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