Class: ComlinkApiRequest
- Inherits:
-
Object
- Object
- ComlinkApiRequest
- Defined in:
- lib/comlink_api_request.rb
Instance Attribute Summary collapse
-
#comlink_url ⇒ Object
Returns the value of attribute comlink_url.
-
#hmac_enabled ⇒ Object
Returns the value of attribute hmac_enabled.
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(comlink_url, keys) ⇒ ComlinkApiRequest
constructor
A new instance of ComlinkApiRequest.
- #post(path, body) ⇒ Object
Constructor Details
#initialize(comlink_url, keys) ⇒ ComlinkApiRequest
Returns a new instance of ComlinkApiRequest.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/comlink_api_request.rb', line 11 def initialize(comlink_url, keys) @comlink_url = comlink_url.start_with?('http') ? comlink_url : "https://#{comlink_url}" @hmac_enabled = false return if keys.empty? keys = keys.with_indifferent_access @secret_key = keys['secret_key'] @access_key = keys['access_key'] raise ArgumentError, 'Secret key missing' unless @secret_key raise ArgumentError, 'Access key missing' unless @access_key @hmac_enabled = true end |
Instance Attribute Details
#comlink_url ⇒ Object
Returns the value of attribute comlink_url.
9 10 11 |
# File 'lib/comlink_api_request.rb', line 9 def comlink_url @comlink_url end |
#hmac_enabled ⇒ Object
Returns the value of attribute hmac_enabled.
9 10 11 |
# File 'lib/comlink_api_request.rb', line 9 def hmac_enabled @hmac_enabled end |
Instance Method Details
#get(path) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/comlink_api_request.rb', line 26 def get(path) uri = URI.parse("#{@comlink_url}#{path}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) http.request(request).body end |
#post(path, body) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/comlink_api_request.rb', line 35 def post(path, body) uri = URI.parse("#{@comlink_url}#{path}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json') add_hmac_headers(request, 'POST', path, body) request.body = body http.request(request).body end |