class Contentful::Request
This object represents a request that is to be made. It gets initialized by the client with domain specific logic. The client later uses the Request’s url
and query
methods to execute the HTTP request.
Attributes
Public Class Methods
Source
# File lib/contentful/request.rb, line 8 def initialize(client, endpoint, query = {}, id = nil) @client = client @endpoint = endpoint @query = (normalize_query(query) if query && !query.empty?) if id @type = :single # Given the deprecation of `URI::escape` and `URI::encode` # it is needed to replace it with `URI::encode_www_form_component`. # This method, does replace spaces with `+` instead of `%20`. # Therefore, to keep backwards compatibility, we're replacing the resulting `+` # back with `%20`. @id = URI.encode_www_form_component(id).gsub('+', '%20') else @type = :multi @id = nil end end
Public Instance Methods
Source
# File lib/contentful/request.rb, line 39 def absolute? @endpoint.start_with?('http') end
Returns true if endpoint is an absolute url
Source
# File lib/contentful/request.rb, line 44 def copy Marshal.load(Marshal.dump(self)) end
Returns a new Request
object with the same data
Source
# File lib/contentful/request.rb, line 34 def get client.get(self) end
Delegates the actual HTTP work to the client
Source
# File lib/contentful/request.rb, line 29 def url "#{@endpoint}#{@type == :single ? "/#{id}" : ''}" end
Returns the final URL, relative to a contentful space
Private Instance Methods
Source
# File lib/contentful/request.rb, line 50 def normalize_query(query) Hash[ query.map do |key, value| [ key.to_sym, value.is_a?(::Array) ? value.join(',') : value ] end ] end