Class: Alloy::Api
- Inherits:
-
Object
- Object
- Alloy::Api
- Defined in:
- lib/alloy-api.rb
Constant Summary collapse
- @@api_endpoints =
{ main: { uri: 'https://api.alloy.co/' } }
Class Method Summary collapse
- .api_secret=(value) ⇒ Object
- .api_token=(value) ⇒ Object
- .api_uri=(value) ⇒ Object
- .entity_details(entity_id, options = {}) ⇒ Object
- .evaluation_details(entity_id, evaluation_id, options = {}) ⇒ Object
- .method_missing(m, *args, &block) ⇒ Object
- .parameters(options = {}) ⇒ Object
- .perform(path, options = {}) ⇒ Object
- .set_endpoint(name, token, secret, uri = 'https://api.alloy.co/') ⇒ Object
Class Method Details
.api_secret=(value) ⇒ Object
17 18 19 |
# File 'lib/alloy-api.rb', line 17 def self.api_secret=(value) @@api_endpoints[:main][:secret] = value end |
.api_token=(value) ⇒ Object
13 14 15 |
# File 'lib/alloy-api.rb', line 13 def self.api_token=(value) @@api_endpoints[:main][:token] = value end |
.api_uri=(value) ⇒ Object
9 10 11 |
# File 'lib/alloy-api.rb', line 9 def self.api_uri=(value) @@api_endpoints[:main][:uri] = value end |
.entity_details(entity_id, options = {}) ⇒ Object
33 34 35 |
# File 'lib/alloy-api.rb', line 33 def self.entity_details(entity_id, = {}) perform "entities/#{entity_id}", .merge(method: :get) end |
.evaluation_details(entity_id, evaluation_id, options = {}) ⇒ Object
37 38 39 |
# File 'lib/alloy-api.rb', line 37 def self.evaluation_details(entity_id, evaluation_id, = {}) perform "entities/#{entity_id}/evaluations/#{evaluation_id}", .merge(method: :get) end |
.method_missing(m, *args, &block) ⇒ Object
41 42 43 |
# File 'lib/alloy-api.rb', line 41 def self.method_missing(m, *args, &block) perform(m, args[0] || {}) end |
.parameters(options = {}) ⇒ Object
29 30 31 |
# File 'lib/alloy-api.rb', line 29 def self.parameters(={}) perform "parameters", .merge(method: :get) end |
.perform(path, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/alloy-api.rb', line 45 def self.perform(path, ={}) method = [:method] || "post" endpoint = [:endpoint] || :main uri = "#{@@api_endpoints[endpoint][:uri]}#{path}" body_encoding = [:body_encoding] || :to_json headers = { "Content-Type" => "application/json", "Authorization" => auth_param(endpoint) }.merge([:headers].to_h) if [:body_stream].present? response = HTTParty.send(method, uri, { headers: headers, body_stream: [:body_stream] }) else response = HTTParty.send(method, uri, { headers: headers, body: ([:body] || {}).send(body_encoding) }) end return response if [:raw] JSON.parse(response.body) # TODO: Error handling end |
.set_endpoint(name, token, secret, uri = 'https://api.alloy.co/') ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/alloy-api.rb', line 21 def self.set_endpoint(name, token, secret, uri = 'https://api.alloy.co/') @@api_endpoints[name] = { uri: uri, token: token, secret: secret } end |