-
Notifications
You must be signed in to change notification settings - Fork 8
/
client.rb
50 lines (39 loc) · 1.05 KB
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "net/https"
require "uri"
require "json"
require "openssl"
module Honeybadger
module Api
class Client
attr_reader :access_token
def initialize(access_token)
@access_token = access_token
end
def get(path, options = {})
response = request(path, options)
JSON.parse(response.body, :symbolize_names => true, :symbolize_keys => true)
end
private
def request(path, options = {})
uri = build_uri(path, options)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth(access_token, nil)
response = http.request(request)
end
def build_uri(path, opts)
uri = URI.join(host, path)
uri.query = build_query(opts)
uri
end
def build_query(opts)
URI.encode_www_form(opts)
end
def host
"https://app.honeybadger.io/v2/"
end
end
end
end