class Babili::Client
Public Class Methods
delete(path, query_params = {})
click to toggle source
# File lib/babili/client.rb, line 18 def self.delete(path, query_params = {}) execute(:delete, uri(path), headers, query_params) end
get(path, query_params = {})
click to toggle source
# File lib/babili/client.rb, line 6 def self.get(path, query_params = {}) execute(:get, uri(path), headers, query_params) end
post(path, payload, query_params = {})
click to toggle source
# File lib/babili/client.rb, line 10 def self.post(path, payload, query_params = {}) execute(:post, uri(path), headers, nil, payload) end
put(path, payload, query_params = {})
click to toggle source
# File lib/babili/client.rb, line 14 def self.put(path, payload, query_params = {}) execute(:put, uri(path), headers, nil, payload) end
Private Class Methods
execute(method, url, headers, query_params = {}, payload = nil)
click to toggle source
# File lib/babili/client.rb, line 24 def self.execute(method, url, headers, query_params = {}, payload = nil) query = { method: method, url: url, headers: { params: query_params }.merge(headers), payload: payload ? payload.to_json : nil } raw_response = RestClient::Request.execute(query) JSON.parse(raw_response) end
headers()
click to toggle source
# File lib/babili/client.rb, line 41 def self.headers if !Babili.config.platform_token raise TokenMissingError.new("You must define an platform token before calling the API.") end { authorization: "Bearer #{Babili.config.platform_token}", content_type: :json, accept: :json } end
uri(path)
click to toggle source
# File lib/babili/client.rb, line 36 def self.uri(path) base_url = "#{Babili.config.api_scheme}://#{Babili.config.api_host}:#{Babili.config.api_port}" URI.join(base_url, path).to_s end