Method: Bitly::HTTP::Request#uri

Defined in:
lib/bitly/http/request.rb

#uriURI

Returns the uri for the request. If the request is an HTTP method that uses a body to send data, then the uri is the one that the request was initialised with. If the request uses query parameters, then the parameters are serialised and added to the uri’s query.

Examples:

uri = URI.parse("https://api-ssl.bitly.com/v3/shorten")
request = Bitly::HTTP::Request.new(uri: uri, params: { foo: "bar" })
request.uri.to_s
# => "https://api-ssl.bitly.com/v3/shorten?foo=bar"

Returns:

  • (URI)

    The full URI for the request



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bitly/http/request.rb', line 58

def uri
  uri = @uri.dup
  return uri if HTTP_METHODS_WITH_BODY.include?(@method)
  if uri.query
    existing_query = URI.decode_www_form(uri.query)
    new_query = hash_to_arrays(@params)
    uri.query = URI.encode_www_form((existing_query + new_query).uniq)
  else
    uri.query = URI.encode_www_form(@params) if @params.any?
  end
  uri
end