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
-
#get ⇒ Object
Delegates the actual HTTP work to the client.
-
#initialize(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(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 29 30 31 |
# File 'lib/contentful/management/request.rb', line 9 def initialize(endpoint, query = {}, id = nil, header = {}) @header = header @initial_id = id @client = Contentful::Management::Client.shared_instance @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 @absolute = true if @endpoint.start_with?('http') @query = if query && !query.empty? normalize_query(query) end 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
58 59 60 |
# File 'lib/contentful/management/request.rb', line 58 def absolute? !!@absolute end |
#copy ⇒ Object
Returns a new Request object with the same data
63 64 65 |
# File 'lib/contentful/management/request.rb', line 63 def copy self.class.new(@endpoint, @query, @initial_id, @header) end |
#delete ⇒ Object
53 54 55 |
# File 'lib/contentful/management/request.rb', line 53 def delete client.delete(self) end |
#get ⇒ Object
Delegates the actual HTTP work to the client
39 40 41 |
# File 'lib/contentful/management/request.rb', line 39 def get client.get(self) end |
#post ⇒ Object
Delegates the actual HTTP POST request to the client
44 45 46 |
# File 'lib/contentful/management/request.rb', line 44 def post client.post(self) end |
#put ⇒ Object
Delegates the actual HTTP PUT request to the client
49 50 51 |
# File 'lib/contentful/management/request.rb', line 49 def put client.put(self) end |
#url ⇒ Object
Returns the final URL, relative to a contentful space
34 35 36 |
# File 'lib/contentful/management/request.rb', line 34 def url "#{@endpoint }#{ @type == :single ? "/#{ id }" : '' }" end |