Class: APIConnector::Request
- Inherits:
-
Object
- Object
- APIConnector::Request
- Defined in:
- lib/track-r/api_connector/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#connection_length ⇒ Object
readonly
Returns the value of attribute connection_length.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #connect ⇒ Object
- #error? ⇒ Boolean
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 |
# File 'lib/track-r/api_connector/request.rb', line 5 def initialize(={}) @token = [:token] || Token.new @path = [:path] || "/" @connection_length = [:connection_length].to_i || 15 # timeout @headers = default_headers.merge! end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/track-r/api_connector/request.rb', line 3 def body @body end |
#connection_length ⇒ Object (readonly)
Returns the value of attribute connection_length.
3 4 5 |
# File 'lib/track-r/api_connector/request.rb', line 3 def connection_length @connection_length end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
3 4 5 |
# File 'lib/track-r/api_connector/request.rb', line 3 def @error_message end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/track-r/api_connector/request.rb', line 3 def headers @headers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/track-r/api_connector/request.rb', line 3 def path @path end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/track-r/api_connector/request.rb', line 3 def token @token end |
Instance Method Details
#connect ⇒ Object
12 13 14 15 16 |
# File 'lib/track-r/api_connector/request.rb', line 12 def connect Timeout::timeout(@connection_length) { return APIConnector::Response.new(:body => open(api_url, @headers)) } end |
#error? ⇒ Boolean
18 19 20 |
# File 'lib/track-r/api_connector/request.rb', line 18 def error? !@error_message.nil? end |