Class: Spire::API::Requestable::Request
- Inherits:
-
Object
- Object
- Spire::API::Requestable::Request
- Defined in:
- lib/spire/api/requestable.rb
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#url ⇒ Object
Url of the request.
Instance Method Summary collapse
- #body ⇒ Object
- #body=(val) ⇒ Object
- #exec ⇒ Object
- #headers ⇒ Object
-
#initialize(client, options) ⇒ Request
constructor
A new instance of Request.
- #query ⇒ Object
Constructor Details
#initialize(client, options) ⇒ Request
Returns a new instance of Request.
54 55 56 57 58 59 60 61 62 |
# File 'lib/spire/api/requestable.rb', line 54 def initialize(client, ) @client = client @method = .delete(:method) @url = .delete(:url) @options = @options[:headers] = { "User-Agent" => "Ruby spire.io client" }.merge(@options[:headers] || {}) end |
Instance Attribute Details
#url ⇒ Object
Url of the request
53 54 55 |
# File 'lib/spire/api/requestable.rb', line 53 def url @url end |
Instance Method Details
#body ⇒ Object
68 69 70 |
# File 'lib/spire/api/requestable.rb', line 68 def body @options[:body] end |
#body=(val) ⇒ Object
72 73 74 |
# File 'lib/spire/api/requestable.rb', line 72 def body=(val) @options[:body] = val end |
#exec ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/spire/api/requestable.rb', line 80 def exec response = Response.new(@client.send(@method, @url, @options)) headers = response.headers content_type = headers.values_at("Content-Type", "content-type").compact.first if content_type =~ /json/ && [200, 201].include?(response.status) # FIXME: detect appropriate response headers, rather than rescuing begin response.data = API.deserialize(response.body) rescue end end response end |
#headers ⇒ Object
64 65 66 |
# File 'lib/spire/api/requestable.rb', line 64 def headers @options[:headers] end |
#query ⇒ Object
76 77 78 |
# File 'lib/spire/api/requestable.rb', line 76 def query @options[:query] end |