def create(url, code = nil)
      url = ensure_url(url)

      if resp = check_host(url)
        return resp
      end

      begin
        if code = @db.add(url.to_s, code, @options)
          [201, {"Location" => code}, url]
        else
          [422, {}, "Unable to shorten #{url}"]
        end
      rescue DuplicateCodeError => err
        [422, {}, err.to_s]
      end
    end
def create(url, code = nil)
      url = ensure_url(url)

      if resp = check_host(url)
        return resp
      end

      begin
        if code = @db.add(url.to_s, code, @options)
          [201, {"Location" => code}, url]
        else
          [422, {}, "Unable to shorten #{url}"]
        end
      rescue DuplicateCodeError => err
        [422, {}, err.to_s]
      end
    end
Public: Maps a URL to a shortened code.

 url  - A String or Addressable::URI URL to shorten.
 code - Optional String code to use.  Defaults to a random String.

 Returns 201 with the Location pointing to the code, or 422.