Class: Remetric::HTTP
- Inherits:
-
Object
- Object
- Remetric::HTTP
- Defined in:
- lib/remetric/http.rb
Instance Method Summary collapse
- #client ⇒ Object
- #delete(path) ⇒ Object
- #get(path, args = {}) ⇒ Object
- #headers ⇒ Object
-
#initialize(client) ⇒ HTTP
constructor
A new instance of HTTP.
- #opts ⇒ Object
- #parse(response) ⇒ Object
- #patch(path, args = {}) ⇒ Object
- #post(path, args = {}) ⇒ Object
- #rc ⇒ Object
- #root_url ⇒ Object
Constructor Details
#initialize(client) ⇒ HTTP
Returns a new instance of HTTP.
7 8 9 |
# File 'lib/remetric/http.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#client ⇒ Object
11 12 13 |
# File 'lib/remetric/http.rb', line 11 def client @client end |
#delete(path) ⇒ Object
56 57 58 59 |
# File 'lib/remetric/http.rb', line 56 def delete(path) response = rc.delete "#{root_url}#{path}", headers parse response end |
#get(path, args = {}) ⇒ Object
41 42 43 44 |
# File 'lib/remetric/http.rb', line 41 def get(path, args = {}) response = rc.get "#{root_url}#{path}", headers.merge(params: args) parse response end |
#headers ⇒ Object
24 25 26 27 28 |
# File 'lib/remetric/http.rb', line 24 def headers { Authorization: "Basic #{Base64.encode64("#{client.api_token}:#{client.secret_key}")}" } end |
#opts ⇒ Object
30 31 32 33 34 35 |
# File 'lib/remetric/http.rb', line 30 def opts { content_type: :json, accept: :json } end |
#parse(response) ⇒ Object
37 38 39 |
# File 'lib/remetric/http.rb', line 37 def parse(response) JSON.parse response.body end |
#patch(path, args = {}) ⇒ Object
51 52 53 54 |
# File 'lib/remetric/http.rb', line 51 def patch(path, args = {}) response = rc.patch "#{root_url}#{path}", args, headers parse response end |
#post(path, args = {}) ⇒ Object
46 47 48 49 |
# File 'lib/remetric/http.rb', line 46 def post(path, args = {}) response = rc.post "#{root_url}#{path}", args, headers parse response end |
#rc ⇒ Object
20 21 22 |
# File 'lib/remetric/http.rb', line 20 def rc @rc ||= RestClient end |
#root_url ⇒ Object
15 16 17 18 |
# File 'lib/remetric/http.rb', line 15 def root_url # return "http://localhost:3000" "https://api.remetric.com" end |