Class: AllinSDK::JsonAPI::Facade
- Inherits:
-
Object
- Object
- AllinSDK::JsonAPI::Facade
- Includes:
- HTTParty
- Defined in:
- lib/allin-sdk-ruby/json_api/facade.rb
Class Method Summary collapse
- .api_get(method, params = {}, token_required = true) ⇒ Object
- .api_post(method, body_params = {}, query_params = {}) ⇒ Object
- .generate_token ⇒ Object
- .parse_response(response) ⇒ Object
Class Method Details
.api_get(method, params = {}, token_required = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/allin-sdk-ruby/json_api/facade.rb', line 18 def self.api_get(method, params={}, token_required=true) query_values = params if token_required query_values.merge!({token: self.generate_token}) end uri_params = ::Addressable::URI.new uri_params.query_values = query_values puts "[GET] <- starting request to Allin at \##{method} with params: #{params}".light_blue result = self.send("get", "/allinapi/?method=#{method}&#{uri_params.query}", {}) puts "[GET] -> request response from backend: #{result}".green self.parse_response result.body end |
.api_post(method, body_params = {}, query_params = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/allin-sdk-ruby/json_api/facade.rb', line 33 def self.api_post(method, body_params={}, query_params={}) = { :body => body_params, :query => {token: self.generate_token}.merge(query_params), :headers => { 'Cache-Control' => 'no-cache' } } puts "[POST] <- starting request to Allin at \##{method} with params: #{body_params}".light_blue result = self.send("post", "/allinapi/?method=#{method}", ) puts "[POST] -> request response from backend: #{result}".green self.parse_response result.body end |
.generate_token ⇒ Object
49 50 51 |
# File 'lib/allin-sdk-ruby/json_api/facade.rb', line 49 def self.generate_token AllinSDK::JsonAPI::Token.retrieve end |
.parse_response(response) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/allin-sdk-ruby/json_api/facade.rb', line 10 def self.parse_response(response) begin JSON.parse(response) rescue JSON::ParserError => e response end end |