Class: Quonfig::HttpConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/quonfig/http_connection.rb

Constant Summary collapse

SDK_VERSION =
"ruby-#{Quonfig::VERSION}".freeze
JSON_HEADERS =
{
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'X-Quonfig-SDK-Version' => SDK_VERSION
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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 Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



21
22
23
# File 'lib/quonfig/http_connection.rb', line 21

def uri
  @uri
end

Instance Method Details

#connection(headers = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/quonfig/http_connection.rb', line 31

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



23
24
25
# File 'lib/quonfig/http_connection.rb', line 23

def get(path, headers = {})
  connection(headers).get(path)
end

#post(path, body) ⇒ Object



27
28
29
# File 'lib/quonfig/http_connection.rb', line 27

def post(path, body)
  connection.post(path, body.to_json)
end