escobar 0.3.17 → 0.3.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/escobar/client.rb +17 -4
- data/lib/escobar/github/client.rb +29 -21
- data/lib/escobar/heroku/client.rb +45 -37
- data/lib/escobar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24611335d033aad7733d4318d652f3738bb4dcad
|
4
|
+
data.tar.gz: f7c820a2e3a5941255d6ff0d94c1a9b87a7dc9c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f23958ca6ab4c751494409806e3f315f7e5839d4ad2e0465068f9b675ab1b2f82cc0ad0537bc2384c74c8ac662a39be3609561d2914d09bc0e636198b14d2afb
|
7
|
+
data.tar.gz: 92328c38318c6cf546beda7b3d81c6adf0edd9c0dd5d251c400773145c83b3aca37d8e6d54681ff01330979ff21a809f4ed1395d41cf429a2e83c9747b31eac6
|
data/lib/escobar/client.rb
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
module Escobar
|
2
2
|
# Top-level client for heroku
|
3
3
|
class Client
|
4
|
+
# TimeoutError class when API timeouts
|
5
|
+
class TimeoutError < StandardError
|
6
|
+
def self.wrap(err)
|
7
|
+
new(err)
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :cause
|
11
|
+
def initialize(err)
|
12
|
+
@cause = err
|
13
|
+
self.set_backtrace(err.backtrace)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
# Class for returning API errors to escobar clients
|
5
18
|
class HTTPError < StandardError
|
6
19
|
attr_accessor :body, :headers, :status
|
7
|
-
def self.from_response(err
|
20
|
+
def self.from_response(err)
|
8
21
|
error = new("Error from Heroku API")
|
9
22
|
|
10
|
-
error.body = response
|
11
|
-
error.
|
12
|
-
error.
|
23
|
+
error.body = err.response[:body]
|
24
|
+
error.headers = err.response[:headers]
|
25
|
+
error.status = err.response[:status]
|
13
26
|
|
14
27
|
error.set_backtrace(err.backtrace)
|
15
28
|
error
|
@@ -78,8 +78,6 @@ module Escobar
|
|
78
78
|
def get(path)
|
79
79
|
response = http_method(:get, path)
|
80
80
|
JSON.parse(response.body)
|
81
|
-
rescue StandardError => e
|
82
|
-
raise Escobar::Client::HTTPError.from_response(e, response)
|
83
81
|
end
|
84
82
|
|
85
83
|
def accept_headers
|
@@ -87,36 +85,46 @@ module Escobar
|
|
87
85
|
end
|
88
86
|
|
89
87
|
def http_method(verb, path)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
with_error_handling do
|
89
|
+
client.send(verb) do |request|
|
90
|
+
request.url path
|
91
|
+
request.headers["Accept"] = accept_headers
|
92
|
+
request.headers["Content-Type"] = "application/json"
|
93
|
+
request.headers["Authorization"] = "token #{token}"
|
94
|
+
request.options.timeout = Escobar.http_timeout
|
95
|
+
request.options.open_timeout = Escobar.http_open_timeout
|
96
|
+
end
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
# rubocop:disable Metrics/AbcSize
|
101
101
|
def post(path, body)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
102
|
+
with_error_handling do
|
103
|
+
response = client.post do |request|
|
104
|
+
request.url path
|
105
|
+
request.headers["Accept"] = accept_headers
|
106
|
+
request.headers["Content-Type"] = "application/json"
|
107
|
+
request.headers["Authorization"] = "token #{token}"
|
108
|
+
request.options.timeout = Escobar.http_timeout
|
109
|
+
request.options.open_timeout = Escobar.http_open_timeout
|
110
|
+
request.body = body.to_json
|
111
|
+
end
|
112
|
+
|
113
|
+
JSON.parse(response.body)
|
110
114
|
end
|
111
|
-
|
112
|
-
JSON.parse(response.body)
|
113
|
-
rescue StandardError => e
|
114
|
-
raise Escobar::Client::HTTPError.from_response(e, response)
|
115
115
|
end
|
116
116
|
# rubocop:enable Metrics/AbcSize
|
117
117
|
|
118
118
|
private
|
119
119
|
|
120
|
+
def with_error_handling
|
121
|
+
yield
|
122
|
+
rescue Net::OpenTimeout, Faraday::TimeoutError => e
|
123
|
+
raise Escobar::Client::TimeoutError.wrap(e)
|
124
|
+
rescue Faraday::Error::ClientError => e
|
125
|
+
raise Escobar::Client::HTTPError.from_response(e)
|
126
|
+
end
|
127
|
+
|
120
128
|
def client
|
121
129
|
@client ||= Escobar.zipkin_enabled? ? zipkin_client : default_client
|
122
130
|
end
|
@@ -3,7 +3,7 @@ module Escobar
|
|
3
3
|
module Heroku
|
4
4
|
# Top-level client for interacting with Heroku API
|
5
5
|
class Client
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :token
|
7
7
|
def initialize(token)
|
8
8
|
@token = token
|
9
9
|
end
|
@@ -20,56 +20,68 @@ module Escobar
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def get(path, version = 3)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
with_error_handling do
|
24
|
+
response = client.get do |request|
|
25
|
+
request.url path
|
26
|
+
request_defaults(request, version)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
raise Escobar::Client::HTTPError.from_response(e, response)
|
29
|
+
JSON.parse(response.body)
|
30
|
+
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_range(path, range, version = 3)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
with_error_handling do
|
35
|
+
response = client.get do |request|
|
36
|
+
request.url path
|
37
|
+
request_defaults(request, version)
|
38
|
+
request.headers["Range"] = range
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
raise Escobar::Client::HTTPError.from_response(e, response)
|
41
|
+
JSON.parse(response.body)
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def post(path, body)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
with_error_handling do
|
47
|
+
response = client.post do |request|
|
48
|
+
request.url path
|
49
|
+
request_defaults(request)
|
50
|
+
request.body = body.to_json
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
raise Escobar::Client::HTTPError.from_response(e, response)
|
53
|
+
JSON.parse(response.body)
|
54
|
+
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def put(path, second_factor = nil)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
with_error_handling do
|
59
|
+
response = client.put do |request|
|
60
|
+
request.url path
|
61
|
+
request_defaults(request)
|
62
|
+
if second_factor
|
63
|
+
request.headers["Heroku-Two-Factor-Code"] = second_factor
|
64
|
+
end
|
63
65
|
end
|
64
|
-
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
raise Escobar::Client::HTTPError.from_response(e, response)
|
67
|
+
JSON.parse(response.body)
|
68
|
+
end
|
69
69
|
end
|
70
70
|
|
71
71
|
private
|
72
72
|
|
73
|
+
def with_error_handling
|
74
|
+
yield
|
75
|
+
rescue Net::OpenTimeout, Faraday::TimeoutError => e
|
76
|
+
raise Escobar::Client::TimeoutError.wrap(e)
|
77
|
+
rescue Faraday::Error::ClientError => e
|
78
|
+
raise Escobar::Client::HTTPError.from_response(e)
|
79
|
+
end
|
80
|
+
|
81
|
+
def client
|
82
|
+
@client ||= Escobar.zipkin_enabled? ? zipkin_client : default_client
|
83
|
+
end
|
84
|
+
|
73
85
|
def request_defaults(request, version = 3)
|
74
86
|
request.headers["Accept"] = heroku_accept_header(version)
|
75
87
|
request.headers["Accept-Encoding"] = ""
|
@@ -85,10 +97,6 @@ module Escobar
|
|
85
97
|
"application/vnd.heroku+json; version=#{version}"
|
86
98
|
end
|
87
99
|
|
88
|
-
def client
|
89
|
-
@client ||= Escobar.zipkin_enabled? ? zipkin_client : default_client
|
90
|
-
end
|
91
|
-
|
92
100
|
def zipkin_client
|
93
101
|
Faraday.new(url: "https://api.heroku.com") do |c|
|
94
102
|
c.use :instrumentation
|
data/lib/escobar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escobar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Donohoe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|