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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/comlink_api_request.rb', line 10 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.transform_keys(&:to_sym) @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.
8 9 10 |
# File 'lib/comlink_api_request.rb', line 8 def comlink_url @comlink_url end |
#hmac_enabled ⇒ Object
Returns the value of attribute hmac_enabled.
8 9 10 |
# File 'lib/comlink_api_request.rb', line 8 def hmac_enabled @hmac_enabled end |
Instance Method Details
#get(path) ⇒ Object
25 26 27 |
# File 'lib/comlink_api_request.rb', line 25 def get(path) Net::HTTP.get_response(URI("#{@comlink_url}#{path}")).body end |
#post(path, body) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/comlink_api_request.rb', line 29 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 |