Class: Stretch::Connection
- Inherits:
-
Object
- Object
- Stretch::Connection
- Defined in:
- lib/stretch/connection.rb
Constant Summary collapse
- REQUEST_METHODS =
[ :get, :post, :put, :delete ].freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #request(method, path, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
10 11 12 |
# File 'lib/stretch/connection.rb', line 10 def initialize = {} @connection = Faraday.new() end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/stretch/connection.rb', line 6 def connection @connection end |
Instance Method Details
#request(method, path, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stretch/connection.rb', line 14 def request method, path, = {} validate_request_method method response = connection.send(method) do |request| request.headers["Accept"] = "application/json" request.path = path case method when :get .each { |k,v| request.params[k] = v } when :post, :put request.body = MultiJson.dump() end end handle_response response end |