Class: Remetric::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/remetric/http.rb

Instance Method Summary collapse

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

#clientObject



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

#headersObject



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

#optsObject



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

#rcObject



20
21
22
# File 'lib/remetric/http.rb', line 20

def rc
  @rc ||= RestClient
end

#root_urlObject



15
16
17
18
# File 'lib/remetric/http.rb', line 15

def root_url
  # return "http://localhost:3000"
  "https://api.remetric.com"
end