Class: Quonfig::HttpConnection
- Inherits:
-
Object
- Object
- Quonfig::HttpConnection
- Defined in:
- lib/quonfig/http_connection.rb
Constant Summary collapse
- SDK_VERSION =
'ruby-0.1.0'- JSON_HEADERS =
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Quonfig-SDK-Version' => SDK_VERSION }.freeze
Instance Method Summary collapse
- #connection(headers = {}) ⇒ Object
- #get(path, headers = {}) ⇒ Object
-
#initialize(uri, sdk_key) ⇒ HttpConnection
constructor
A new instance of HttpConnection.
- #post(path, body) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(uri, sdk_key) ⇒ HttpConnection
Returns a new instance of HttpConnection.
16 17 18 19 |
# File 'lib/quonfig/http_connection.rb', line 16 def initialize(uri, sdk_key) @uri = uri @sdk_key = sdk_key end |
Instance Method Details
#connection(headers = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/quonfig/http_connection.rb', line 33 def connection(headers = {}) merged = JSON_HEADERS.merge('Authorization' => auth_header).merge(headers) Faraday.new(@uri) do |conn| conn.headers.merge!(merged) end end |
#get(path, headers = {}) ⇒ Object
25 26 27 |
# File 'lib/quonfig/http_connection.rb', line 25 def get(path, headers = {}) connection(headers).get(path) end |
#post(path, body) ⇒ Object
29 30 31 |
# File 'lib/quonfig/http_connection.rb', line 29 def post(path, body) connection.post(path, body.to_json) end |
#uri ⇒ Object
21 22 23 |
# File 'lib/quonfig/http_connection.rb', line 21 def uri @uri end |