Class: APIConnector::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/track-r/api_connector/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @token = options[:token] || Token.new
  @path = options[:path] || "/"
  @connection_length = options[:connection_length].to_i || 15 # timeout
  @headers = default_headers.merge! options
end

Instance Attribute Details

#bodyObject (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_lengthObject (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_messageObject (readonly)

Returns the value of attribute error_message.



3
4
5
# File 'lib/track-r/api_connector/request.rb', line 3

def error_message
  @error_message
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/track-r/api_connector/request.rb', line 3

def headers
  @headers
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/track-r/api_connector/request.rb', line 3

def path
  @path
end

#tokenObject (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

#connectObject



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

Returns:

  • (Boolean)


18
19
20
# File 'lib/track-r/api_connector/request.rb', line 18

def error?
  !@error_message.nil?
end