Class: Holistics::Client
- Inherits:
-
Object
- Object
- Holistics::Client
- Defined in:
- lib/holistics/client.rb
Constant Summary collapse
- DEFAULT_ENDPOINT =
'https://api.holistics.io'.freeze
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(endpoint, token) ⇒ Client
constructor
A new instance of Client.
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
Constructor Details
#initialize(endpoint, token) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 |
# File 'lib/holistics/client.rb', line 9 def initialize(endpoint, token) @conn = Faraday.new(:url => (endpoint || DEFAULT_ENDPOINT)) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end @token = token end |
Instance Method Details
#delete(path, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/holistics/client.rb', line 54 def delete(path, = {}) [:params] ||= {} [:headers] ||= {} [:headers].merge!('Content-Type': 'application/json') response = @conn.delete do |req| req.url path req.headers.merge!([:headers]) req.body = [:params].merge({ '_utoken': @token }).to_s end [response.status, response.body] end |
#get(path, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/holistics/client.rb', line 17 def get(path, = {}) [:params] ||= {} [:headers] ||= {} response = @conn.get do |req| req.url path req.headers.merge([:headers]) req.params = [:params].merge({ '_utoken': @token }) end [response.status, response.body] end |
#post(path, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/holistics/client.rb', line 41 def post(path, = {}) [:params] ||= {} [:headers] ||= {} [:headers].merge!('Content-Type': 'application/json') response = @conn.post do |req| req.url path req.headers.merge!([:headers]) req.params['_utoken'] = @token req.body = [:params].to_s end [response.status, response.body] end |
#put(path, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/holistics/client.rb', line 28 def put(path, = {}) [:params] ||= {} [:headers] ||= {} [:headers].merge!('Content-Type': 'application/json') response = @conn.put do |req| req.url path req.headers.merge!([:headers]) req.params['_utoken'] = @token req.body = [:params].to_s end [response.status, response.body] end |