Class: Contentful::Management::Request
- Inherits:
-
Object
- Object
- Contentful::Management::Request
- Defined in:
- lib/contentful/management/request.rb
Overview
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.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#absolute? ⇒ Boolean
Returns true if endpoint is an absolute url.
-
#copy ⇒ Object
Returns a new Request object with the same data.
-
#delete ⇒ Object
Delegates the actual HTTP DELETE request to the client.
-
#get ⇒ Object
Delegates the actual HTTP work to the client.
-
#initialize(client, endpoint, query = {}, id = nil, headers = {}) ⇒ Request
constructor
A new instance of Request.
-
#post ⇒ Object
Delegates the actual HTTP POST request to the client.
-
#put ⇒ Object
Delegates the actual HTTP PUT request to the client.
-
#url ⇒ Object
Returns the final URL, relative to a contentful space.
Constructor Details
#initialize(client, endpoint, query = {}, id = nil, headers = {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/contentful/management/request.rb', line 9 def client @client end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/contentful/management/request.rb', line 9 def endpoint @endpoint end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/contentful/management/request.rb', line 9 def headers @headers end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/contentful/management/request.rb', line 9 def id @id end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
9 10 11 |
# File 'lib/contentful/management/request.rb', line 9 def query @query end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/contentful/management/request.rb', line 9 def type @type end |
Instance Method Details
#absolute? ⇒ Boolean
Returns true if endpoint is an absolute url
63 64 65 |
# File 'lib/contentful/management/request.rb', line 63 def absolute? @endpoint.start_with?('http') end |
#copy ⇒ Object
Returns a new Request object with the same data
68 69 70 |
# File 'lib/contentful/management/request.rb', line 68 def copy self.class.new(@client, @endpoint, @query, @initial_id, @headers) end |
#delete ⇒ Object
Delegates the actual HTTP DELETE request to the client
57 58 59 |
# File 'lib/contentful/management/request.rb', line 57 def delete client.delete(self) end |
#get ⇒ Object
Delegates the actual HTTP work to the client
42 43 44 |
# File 'lib/contentful/management/request.rb', line 42 def get client.get(self) end |
#post ⇒ Object
Delegates the actual HTTP POST request to the client
47 48 49 |
# File 'lib/contentful/management/request.rb', line 47 def post client.post(self) end |
#put ⇒ Object
Delegates the actual HTTP PUT request to the client
52 53 54 |
# File 'lib/contentful/management/request.rb', line 52 def put client.put(self) end |
#url ⇒ Object
Returns the final URL, relative to a contentful space
37 38 39 |
# File 'lib/contentful/management/request.rb', line 37 def url "#{@endpoint}#{@type == :single ? "/#{id}" : ''}" end |