pactas_itero 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +15 -0
- data/.rubocop.yml +765 -0
- data/CHANGELOG.md +34 -1
- data/Gemfile +3 -1
- data/README.md +3 -1
- data/Rakefile +7 -4
- data/lib/pactas_itero/api/contracts.rb +12 -0
- data/lib/pactas_itero/api/customers.rb +2 -0
- data/lib/pactas_itero/api/invoices.rb +3 -2
- data/lib/pactas_itero/api/oauth.rb +3 -2
- data/lib/pactas_itero/api/orders.rb +2 -0
- data/lib/pactas_itero/api/rated_items.rb +10 -1
- data/lib/pactas_itero/api.rb +9 -7
- data/lib/pactas_itero/client.rb +32 -26
- data/lib/pactas_itero/configurable.rb +9 -8
- data/lib/pactas_itero/default.rb +17 -18
- data/lib/pactas_itero/error.rb +45 -44
- data/lib/pactas_itero/ext/hash/camelize_keys.rb +12 -10
- data/lib/pactas_itero/response/raise_error.rb +5 -5
- data/lib/pactas_itero/version.rb +3 -1
- data/lib/pactas_itero.rb +5 -3
- metadata +16 -83
- data/Gemfile.lock +0 -92
- data/pactas_itero.gemspec +0 -37
- data/spec/fixtures/bearer_token.json +0 -5
- data/spec/fixtures/commit_order_response.json +0 -50
- data/spec/fixtures/contract.json +0 -46
- data/spec/fixtures/contract_cancellation_preview_response.json +0 -73
- data/spec/fixtures/contract_termination_response.json +0 -79
- data/spec/fixtures/contracts.json +0 -48
- data/spec/fixtures/create_order_response.json +0 -17
- data/spec/fixtures/create_rated_item.json +0 -8
- data/spec/fixtures/customer.json +0 -23
- data/spec/fixtures/customers.json +0 -40
- data/spec/fixtures/invoice.json +0 -22
- data/spec/fixtures/invoice_download.pdf +0 -0
- data/spec/fixtures/invoices.json +0 -46
- data/spec/fixtures/order.json +0 -15
- data/spec/fixtures/payment_transaction.json +0 -37
- data/spec/fixtures/rated_items.json +0 -12
- data/spec/fixtures/self_service_token.json +0 -6
- data/spec/pactas_itero/api/contracts_spec.rb +0 -165
- data/spec/pactas_itero/api/customers_spec.rb +0 -229
- data/spec/pactas_itero/api/invoices_spec.rb +0 -103
- data/spec/pactas_itero/api/oauth_spec.rb +0 -44
- data/spec/pactas_itero/api/orders_spec.rb +0 -102
- data/spec/pactas_itero/api/payment_transactions_spec.rb +0 -66
- data/spec/pactas_itero/api/rated_items_spec.rb +0 -113
- data/spec/pactas_itero/client_spec.rb +0 -316
- data/spec/pactas_itero_spec.rb +0 -39
- data/spec/spec_helper.rb +0 -100
@@ -1,316 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
describe PactasItero::Client do
|
5
|
-
|
6
|
-
before do
|
7
|
-
PactasItero.reset!
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "module configuration" do
|
11
|
-
|
12
|
-
before do
|
13
|
-
PactasItero.configure do |config|
|
14
|
-
PactasItero::Configurable.keys.each do |key|
|
15
|
-
config.send("#{key}=", "the #{key} value")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it "inherits the module configuration" do
|
21
|
-
client = PactasItero::Client.new
|
22
|
-
|
23
|
-
PactasItero::Configurable.keys.each do |key|
|
24
|
-
expect(client.instance_variable_get(:"@#{key}")).to eq("the #{key} value")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "with class level configuration" do
|
29
|
-
|
30
|
-
before do
|
31
|
-
@opts = {
|
32
|
-
#connection_options: {ssl: {verify: false}},
|
33
|
-
client_id: "the_client_id",
|
34
|
-
client_secret: "the_client_secret"
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
it "overrides module configuration" do
|
39
|
-
client = PactasItero::Client.new(@opts)
|
40
|
-
|
41
|
-
expect(client.client_id).to eq("the_client_id")
|
42
|
-
expect(client.client_secret).to eq("the_client_secret")
|
43
|
-
expect(client.user_agent).to eq(PactasItero.user_agent)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "can set configuration after initialization" do
|
47
|
-
client = PactasItero::Client.new
|
48
|
-
client.configure do |config|
|
49
|
-
@opts.each do |key, value|
|
50
|
-
config.send("#{key}=", value)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
expect(client.client_id).to eq("the_client_id")
|
55
|
-
expect(client.client_secret).to eq("the_client_secret")
|
56
|
-
expect(client.user_agent).to eq(PactasItero.user_agent)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe ".get" do
|
62
|
-
it "requests the given resource using get" do
|
63
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
64
|
-
request = stub_get("/something?foo=bar")
|
65
|
-
|
66
|
-
client.get "/something", foo: "bar"
|
67
|
-
|
68
|
-
expect(request).to have_been_made
|
69
|
-
end
|
70
|
-
|
71
|
-
it "passes along request headers" do
|
72
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
73
|
-
request = stub_get("/").
|
74
|
-
with(query: { foo: "bar" }, headers: { accept: "text/plain" })
|
75
|
-
client.get "/", foo: "bar", accept: "text/plain"
|
76
|
-
|
77
|
-
expect(request).to have_been_made
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe ".head" do
|
82
|
-
it "requests the given resource using head" do
|
83
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
84
|
-
request = stub_head("/something?foo=bar")
|
85
|
-
|
86
|
-
client.head "/something", foo: "bar"
|
87
|
-
|
88
|
-
expect(request).to have_been_made
|
89
|
-
end
|
90
|
-
|
91
|
-
it "passes along request headers" do
|
92
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
93
|
-
request = stub_head("/").
|
94
|
-
with(query: { foo: "bar" }, headers: { accept: "text/plain" })
|
95
|
-
|
96
|
-
client.head "/", foo: "bar", accept: "text/plain"
|
97
|
-
|
98
|
-
expect(request).to have_been_made
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe ".post" do
|
103
|
-
it "requests the given resource using post" do
|
104
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
105
|
-
request = stub_post("/something").
|
106
|
-
with(body: { foo: "bar" }.to_json)
|
107
|
-
|
108
|
-
client.post "/something", foo: "bar"
|
109
|
-
|
110
|
-
expect(request).to have_been_made
|
111
|
-
end
|
112
|
-
|
113
|
-
it "passes along request headers" do
|
114
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
115
|
-
headers = { "X-Foo" => "bar" }
|
116
|
-
request = stub_post("/").
|
117
|
-
with(body: { foo: "bar" }.to_json, headers: headers)
|
118
|
-
|
119
|
-
client.post "/", foo: "bar", headers: headers
|
120
|
-
|
121
|
-
expect(request).to have_been_made
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe ".put" do
|
126
|
-
it "requests the given resource using put" do
|
127
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
128
|
-
request = stub_put("/something").
|
129
|
-
with(body: { foo: "bar" }.to_json)
|
130
|
-
|
131
|
-
client.put "/something", foo: "bar"
|
132
|
-
|
133
|
-
expect(request).to have_been_made
|
134
|
-
end
|
135
|
-
|
136
|
-
it "passes along request headers" do
|
137
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
138
|
-
headers = { "X-Foo" => "bar" }
|
139
|
-
request = stub_put("/").
|
140
|
-
with(body: { foo: "bar" }.to_json, headers: headers)
|
141
|
-
|
142
|
-
client.put "/", foo: "bar", headers: headers
|
143
|
-
|
144
|
-
expect(request).to have_been_made
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe ".patch" do
|
149
|
-
it "requests the given resource using patch" do
|
150
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
151
|
-
request = stub_patch("/something").
|
152
|
-
with(body: { foo: "bar" }.to_json)
|
153
|
-
|
154
|
-
client.patch "/something", foo: "bar"
|
155
|
-
|
156
|
-
expect(request).to have_been_made
|
157
|
-
end
|
158
|
-
|
159
|
-
it "passes along request headers" do
|
160
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
161
|
-
headers = { "X-Foo" => "bar" }
|
162
|
-
request = stub_patch("/").
|
163
|
-
with(body: { foo: "bar" }.to_json, headers: headers)
|
164
|
-
|
165
|
-
client.patch "/", foo: "bar", headers: headers
|
166
|
-
|
167
|
-
expect(request).to have_been_made
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe ".delete" do
|
172
|
-
it "requests the given resource using delete" do
|
173
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
174
|
-
request = stub_delete("/something")
|
175
|
-
|
176
|
-
client.delete "/something"
|
177
|
-
|
178
|
-
expect(request).to have_been_made
|
179
|
-
end
|
180
|
-
|
181
|
-
it "passes along request headers" do
|
182
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
183
|
-
headers = { "X-Foo" => "bar" }
|
184
|
-
request = stub_delete("/").with(headers: headers)
|
185
|
-
|
186
|
-
client.delete "/", headers: headers
|
187
|
-
|
188
|
-
expect(request).to have_been_made
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe "when making requests" do
|
193
|
-
|
194
|
-
it 'uses the sandbox endpoint by default' do
|
195
|
-
client = PactasItero::Client.new
|
196
|
-
|
197
|
-
expect(client.api_endpoint).to eq "https://sandbox.billwerk.com/"
|
198
|
-
end
|
199
|
-
|
200
|
-
it "uses the production endpoint when production is set to true" do
|
201
|
-
client = PactasItero::Client.new(production: true)
|
202
|
-
|
203
|
-
expect(client.api_endpoint).to eq "https://app.billwerk.com/"
|
204
|
-
end
|
205
|
-
|
206
|
-
it "sets a default user agent" do
|
207
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
208
|
-
request = stub_get("/").
|
209
|
-
with(headers: { user_agent: PactasItero::Default.user_agent })
|
210
|
-
|
211
|
-
client.get "/"
|
212
|
-
|
213
|
-
expect(request).to have_been_made
|
214
|
-
end
|
215
|
-
|
216
|
-
it "accepts a custom user agent" do
|
217
|
-
user_agent = "Mozilla/1.0 (Win3.1)"
|
218
|
-
client = PactasItero::Client.new(user_agent: user_agent, bearer_token: 'bt')
|
219
|
-
request = stub_get("/").with(headers: { user_agent: user_agent })
|
220
|
-
|
221
|
-
client.get "/"
|
222
|
-
|
223
|
-
expect(request).to have_been_made
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'creates the correct auth headers with supplied bearer_token' do
|
227
|
-
token = 'the_bearer_token'
|
228
|
-
request = stub_get("/").with(headers: { authorization: "Bearer #{token}" })
|
229
|
-
client = PactasItero::Client.new(bearer_token: token)
|
230
|
-
|
231
|
-
client.get "/"
|
232
|
-
|
233
|
-
expect(request).to have_been_made
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'creates the correct auth headers with supplied bearer_token' do
|
237
|
-
token = OpenStruct.new(access_token: 'the_bearer_token')
|
238
|
-
client = PactasItero::Client.new(bearer_token: token)
|
239
|
-
|
240
|
-
request = stub_get("/").with(headers: { authorization: "Bearer #{token.access_token}" })
|
241
|
-
|
242
|
-
client.get "/"
|
243
|
-
|
244
|
-
expect(request).to have_been_made
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context "error handling" do
|
249
|
-
it "raises on 404" do
|
250
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
251
|
-
stub_get('/four_oh_four').to_return(status: 404)
|
252
|
-
|
253
|
-
expect { client.get('/four_oh_four') }.to raise_error PactasItero::NotFound
|
254
|
-
end
|
255
|
-
|
256
|
-
it "raises on 500" do
|
257
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
258
|
-
stub_get('/five_oh_oh').to_return(status: 500)
|
259
|
-
|
260
|
-
expect { client.get('/five_oh_oh') }.to raise_error PactasItero::InternalServerError
|
261
|
-
end
|
262
|
-
|
263
|
-
it "includes a message" do
|
264
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
265
|
-
stub_get('/with_message').to_return(
|
266
|
-
status: 422,
|
267
|
-
headers: { content_type: "application/json" },
|
268
|
-
body: { Message: "'Something' is not a valid ObjectId. Expected a 24 digit hex string." }.to_json
|
269
|
-
)
|
270
|
-
|
271
|
-
expect { client.get('/with_message') }.to raise_error(
|
272
|
-
PactasItero::UnprocessableEntity,
|
273
|
-
"GET https://sandbox.billwerk.com/with_message: " \
|
274
|
-
"422 - 'Something' is not a valid ObjectId. Expected a 24 digit hex string.",
|
275
|
-
)
|
276
|
-
end
|
277
|
-
|
278
|
-
it "raises a ClientError on unknown client errors" do
|
279
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
280
|
-
stub_get('/something').to_return(
|
281
|
-
status: 418,
|
282
|
-
headers: { content_type: "application/json" },
|
283
|
-
body: { message: "I'm a teapot" }.to_json
|
284
|
-
)
|
285
|
-
|
286
|
-
expect { client.get('/something') }.to raise_error PactasItero::ClientError
|
287
|
-
end
|
288
|
-
|
289
|
-
it "raises a ServerError on unknown server errors" do
|
290
|
-
client = PactasItero::Client.new(bearer_token: 'bt')
|
291
|
-
stub_get('/something').to_return(
|
292
|
-
status: 509,
|
293
|
-
headers: { content_type: "application/json" },
|
294
|
-
body: { message: "Bandwidth exceeded" }.to_json
|
295
|
-
)
|
296
|
-
|
297
|
-
expect { client.get('/something') }.to raise_error PactasItero::ServerError
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
describe '.sandbox_api_endpoint' do
|
302
|
-
it 'returns url of the sandbox endpoint' do
|
303
|
-
client = PactasItero::Client.new
|
304
|
-
|
305
|
-
expect(client.sandbox_api_endpoint).to eq "https://sandbox.billwerk.com"
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe '.production_api_endpoint' do
|
310
|
-
it 'returns url of the sandbox endpoint' do
|
311
|
-
client = PactasItero::Client.new
|
312
|
-
|
313
|
-
expect(client.production_api_endpoint).to eq "https://app.billwerk.com"
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
data/spec/pactas_itero_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PactasItero do
|
4
|
-
|
5
|
-
it "sets defaults" do
|
6
|
-
PactasItero::Configurable.keys.each do |key|
|
7
|
-
expect(PactasItero.instance_variable_get(:"@#{key}")).to eq(PactasItero::Default.send(key))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe ".client" do
|
12
|
-
it "creates an PactasItero::Client" do
|
13
|
-
expect(PactasItero.client).to be_kind_of PactasItero::Client
|
14
|
-
end
|
15
|
-
|
16
|
-
it "creates new client everytime" do
|
17
|
-
expect(PactasItero.client).to_not eq(PactasItero.client)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "allows stubbing the method" do
|
21
|
-
pactas_client = instance_double(PactasItero::Client)
|
22
|
-
allow(PactasItero).to receive(:client).and_return(pactas_client)
|
23
|
-
|
24
|
-
expect(PactasItero.client).to be_kind_of RSpec::Mocks::InstanceVerifyingDouble
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe ".configure" do
|
29
|
-
PactasItero::Configurable.keys.each do |key|
|
30
|
-
it "sets the #{key.to_s.gsub('_', ' ')}" do
|
31
|
-
PactasItero.configure do |config|
|
32
|
-
config.send("#{key}=", key)
|
33
|
-
end
|
34
|
-
expect(PactasItero.instance_variable_get(:"@#{key}")).to eq(key)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
|
3
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
4
|
-
SimpleCov::Formatter::HTMLFormatter,
|
5
|
-
)
|
6
|
-
|
7
|
-
SimpleCov.start do
|
8
|
-
add_filter '/spec/'
|
9
|
-
add_filter '/vendor/bundle'
|
10
|
-
#minimum_coverage(99.15)
|
11
|
-
refuse_coverage_drop
|
12
|
-
end
|
13
|
-
|
14
|
-
require 'json'
|
15
|
-
require 'pactas_itero'
|
16
|
-
require 'rspec'
|
17
|
-
require 'webmock/rspec'
|
18
|
-
|
19
|
-
WebMock.disable_net_connect!
|
20
|
-
|
21
|
-
RSpec.configure do |config|
|
22
|
-
config.raise_errors_for_deprecations!
|
23
|
-
# Disable should syntax
|
24
|
-
# https://www.relishapp.com/rspec/rspec-expectations/docs/syntax-configuration
|
25
|
-
config.expect_with :rspec do |c|
|
26
|
-
c.syntax = :expect
|
27
|
-
end
|
28
|
-
|
29
|
-
# had to override backtrace_exclusion_patterns because of current
|
30
|
-
# directory structure. once this gem has been extracted into a separate
|
31
|
-
# respository this can be removed
|
32
|
-
config.backtrace_exclusion_patterns = [
|
33
|
-
/\/lib\d*\/ruby\//,
|
34
|
-
/org\/jruby\//,
|
35
|
-
/bin\//,
|
36
|
-
/vendor\/bundle\/(.*)\/gems\//,
|
37
|
-
/spec\/spec_helper.rb/,
|
38
|
-
/lib\/rspec\/(core|expectations|matchers|mocks)/
|
39
|
-
]
|
40
|
-
|
41
|
-
config.after(:each) do
|
42
|
-
PactasItero.reset!
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def fixture_path
|
47
|
-
File.expand_path('../fixtures', __FILE__)
|
48
|
-
end
|
49
|
-
|
50
|
-
def fixture(file)
|
51
|
-
File.new(fixture_path + '/' + file)
|
52
|
-
end
|
53
|
-
|
54
|
-
def pactas_api_endpoint
|
55
|
-
PactasItero::Default::SANDBOX_API_ENDPOINT
|
56
|
-
end
|
57
|
-
|
58
|
-
def pactas_api_url(url)
|
59
|
-
url =~ /^http/ ? url : "#{pactas_api_endpoint}#{url}"
|
60
|
-
end
|
61
|
-
|
62
|
-
def a_delete(path)
|
63
|
-
a_request(:delete, pactas_api_url(path))
|
64
|
-
end
|
65
|
-
|
66
|
-
def a_get(path)
|
67
|
-
a_request(:get, pactas_api_url(path))
|
68
|
-
end
|
69
|
-
|
70
|
-
def a_post(path)
|
71
|
-
a_request(:post, pactas_api_url(path))
|
72
|
-
end
|
73
|
-
|
74
|
-
def a_put(path)
|
75
|
-
a_request(:put, pactas_api_url(path))
|
76
|
-
end
|
77
|
-
|
78
|
-
def stub_delete(path)
|
79
|
-
stub_request(:delete, pactas_api_url(path))
|
80
|
-
end
|
81
|
-
|
82
|
-
def stub_get(path)
|
83
|
-
stub_request(:get, pactas_api_url(path))
|
84
|
-
end
|
85
|
-
|
86
|
-
def stub_head(path)
|
87
|
-
stub_request(:head, pactas_api_url(path))
|
88
|
-
end
|
89
|
-
|
90
|
-
def stub_post(path)
|
91
|
-
stub_request(:post, pactas_api_url(path))
|
92
|
-
end
|
93
|
-
|
94
|
-
def stub_put(path)
|
95
|
-
stub_request(:put, pactas_api_url(path))
|
96
|
-
end
|
97
|
-
|
98
|
-
def stub_patch(path)
|
99
|
-
stub_request(:patch, pactas_api_url(path))
|
100
|
-
end
|