class Contentful::Management::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/management/request.rb, line 11 def initialize(client, endpoint, query = {}, id = nil, headers = {}) @headers = headers @initial_id = id @client = client @client.version = headers[:version] @client.organization_id = headers[:organization_id] @client.content_type_id = headers[:content_type_id] @endpoint = endpoint case query when Hash @query = normalize_query(query) if query && !query.empty? else @query = query end if id @type = :single @id = URI.encode_www_form_component(id) else @type = :multi @id = nil end end
Public Instance Methods
Source
# File lib/contentful/management/request.rb, line 63 def absolute? @endpoint.start_with?('http') end
Returns true if endpoint is an absolute url @return [Boolean]
Source
# File lib/contentful/management/request.rb, line 68 def copy self.class.new(@client, @endpoint, @query, @initial_id, @headers) end
Returns a new Request
object with the same data
Source
# File lib/contentful/management/request.rb, line 57 def delete client.delete(self) end
Delegates the actual HTTP DELETE request to the client
Source
# File lib/contentful/management/request.rb, line 42 def get client.get(self) end
Delegates the actual HTTP work to the client
Source
# File lib/contentful/management/request.rb, line 47 def post client.post(self) end
Delegates the actual HTTP POST request to the client
Source
# File lib/contentful/management/request.rb, line 52 def put client.put(self) end
Delegates the actual HTTP PUT request to the client
Source
# File lib/contentful/management/request.rb, line 37 def url "#{@endpoint}#{@type == :single ? "/#{id}" : ''}" end
Returns the final URL, relative to a contentful space
Private Instance Methods
Source
# File lib/contentful/management/request.rb, line 74 def normalize_query(query) query.transform_keys(&:to_sym) end