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.
-
#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, header = {}) ⇒ 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, header = {}) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/contentful/management/request.rb', line 9 def initialize(client, endpoint, query = {}, id = nil, header = {}) @header = header @initial_id = id @client = client @client.version = header[:version] @client.organization_id = header[:organization_id] @client.content_type_id = header[:content_type_id] @client.zero_length = query.empty? @endpoint = endpoint @query = normalize_query(query) if query && !query.empty? if id @type = :single @id = URI.escape(id) else @type = :multi @id = nil end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/contentful/management/request.rb', line 7 def client @client end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
7 8 9 |
# File 'lib/contentful/management/request.rb', line 7 def endpoint @endpoint end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/contentful/management/request.rb', line 7 def id @id end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
7 8 9 |
# File 'lib/contentful/management/request.rb', line 7 def query @query end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/contentful/management/request.rb', line 7 def type @type end |
Instance Method Details
#absolute? ⇒ Boolean
Returns true if endpoint is an absolute url
57 58 59 |
# File 'lib/contentful/management/request.rb', line 57 def absolute? @endpoint.start_with?('http') end |
#copy ⇒ Object
Returns a new Request object with the same data
62 63 64 |
# File 'lib/contentful/management/request.rb', line 62 def copy self.class.new(@client, @endpoint, @query, @initial_id, @header) end |
#delete ⇒ Object
Delegates the actual HTTP DELETE request to the client
51 52 53 |
# File 'lib/contentful/management/request.rb', line 51 def delete client.delete(self) end |
#get ⇒ Object
Delegates the actual HTTP work to the client
36 37 38 |
# File 'lib/contentful/management/request.rb', line 36 def get client.get(self) end |
#post ⇒ Object
Delegates the actual HTTP POST request to the client
41 42 43 |
# File 'lib/contentful/management/request.rb', line 41 def post client.post(self) end |
#put ⇒ Object
Delegates the actual HTTP PUT request to the client
46 47 48 |
# File 'lib/contentful/management/request.rb', line 46 def put client.put(self) end |
#url ⇒ Object
Returns the final URL, relative to a contentful space
31 32 33 |
# File 'lib/contentful/management/request.rb', line 31 def url "#{@endpoint}#{@type == :single ? "/#{id}" : ''}" end |