pactas_itero 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +15 -0
  3. data/.rubocop.yml +765 -0
  4. data/CHANGELOG.md +34 -1
  5. data/Gemfile +3 -1
  6. data/README.md +3 -1
  7. data/Rakefile +7 -4
  8. data/lib/pactas_itero/api/contracts.rb +12 -0
  9. data/lib/pactas_itero/api/customers.rb +2 -0
  10. data/lib/pactas_itero/api/invoices.rb +3 -2
  11. data/lib/pactas_itero/api/oauth.rb +3 -2
  12. data/lib/pactas_itero/api/orders.rb +2 -0
  13. data/lib/pactas_itero/api/rated_items.rb +10 -1
  14. data/lib/pactas_itero/api.rb +9 -7
  15. data/lib/pactas_itero/client.rb +32 -26
  16. data/lib/pactas_itero/configurable.rb +9 -8
  17. data/lib/pactas_itero/default.rb +17 -18
  18. data/lib/pactas_itero/error.rb +45 -44
  19. data/lib/pactas_itero/ext/hash/camelize_keys.rb +12 -10
  20. data/lib/pactas_itero/response/raise_error.rb +5 -5
  21. data/lib/pactas_itero/version.rb +3 -1
  22. data/lib/pactas_itero.rb +5 -3
  23. metadata +16 -83
  24. data/Gemfile.lock +0 -92
  25. data/pactas_itero.gemspec +0 -37
  26. data/spec/fixtures/bearer_token.json +0 -5
  27. data/spec/fixtures/commit_order_response.json +0 -50
  28. data/spec/fixtures/contract.json +0 -46
  29. data/spec/fixtures/contract_cancellation_preview_response.json +0 -73
  30. data/spec/fixtures/contract_termination_response.json +0 -79
  31. data/spec/fixtures/contracts.json +0 -48
  32. data/spec/fixtures/create_order_response.json +0 -17
  33. data/spec/fixtures/create_rated_item.json +0 -8
  34. data/spec/fixtures/customer.json +0 -23
  35. data/spec/fixtures/customers.json +0 -40
  36. data/spec/fixtures/invoice.json +0 -22
  37. data/spec/fixtures/invoice_download.pdf +0 -0
  38. data/spec/fixtures/invoices.json +0 -46
  39. data/spec/fixtures/order.json +0 -15
  40. data/spec/fixtures/payment_transaction.json +0 -37
  41. data/spec/fixtures/rated_items.json +0 -12
  42. data/spec/fixtures/self_service_token.json +0 -6
  43. data/spec/pactas_itero/api/contracts_spec.rb +0 -165
  44. data/spec/pactas_itero/api/customers_spec.rb +0 -229
  45. data/spec/pactas_itero/api/invoices_spec.rb +0 -103
  46. data/spec/pactas_itero/api/oauth_spec.rb +0 -44
  47. data/spec/pactas_itero/api/orders_spec.rb +0 -102
  48. data/spec/pactas_itero/api/payment_transactions_spec.rb +0 -66
  49. data/spec/pactas_itero/api/rated_items_spec.rb +0 -113
  50. data/spec/pactas_itero/client_spec.rb +0 -316
  51. data/spec/pactas_itero_spec.rb +0 -39
  52. data/spec/spec_helper.rb +0 -100
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PactasItero::Api::Invoices do
4
- describe '.invoices' do
5
- it 'requests the correct resource' do
6
- client = PactasItero::Client.new(bearer_token: 'bt')
7
- request = stub_get('/api/v1/invoices').
8
- to_return(
9
- body: fixture('invoices.json'),
10
- headers: { content_type: 'application/json; charset=utf-8'}
11
- )
12
-
13
- client.invoices
14
-
15
- expect(request).to have_been_made
16
- end
17
-
18
- it 'returns an array of contracts' do
19
- client = PactasItero::Client.new(bearer_token: 'bt')
20
- request = stub_get('/api/v1/invoices').
21
- to_return(
22
- body: fixture('invoices.json'),
23
- headers: { content_type: 'application/json; charset=utf-8'}
24
- )
25
-
26
- invoices = client.invoices
27
-
28
- expect(invoices).to be_a Array
29
- end
30
- end
31
-
32
- describe '.invoices_from' do
33
- it 'requests the correct resource' do
34
- client = PactasItero::Client.new(bearer_token: 'bt')
35
- request = stub_get('/api/v1/invoices?from=54b67d9e995ec90bc8f37718').
36
- to_return(
37
- body: fixture('invoices.json'),
38
- headers: { content_type: 'application/json; charset=utf-8'}
39
- )
40
-
41
- client.invoices_from('54b67d9e995ec90bc8f37718')
42
-
43
- expect(request).to have_been_made
44
- end
45
-
46
- it 'requests the correct resource, if from parameter is nil' do
47
- client = PactasItero::Client.new(bearer_token: 'bt')
48
- request = stub_get('/api/v1/invoices').
49
- to_return(
50
- body: fixture('invoices.json'),
51
- headers: { content_type: 'application/json; charset=utf-8'}
52
- )
53
-
54
- client.invoices_from(nil)
55
-
56
- expect(request).to have_been_made
57
- end
58
-
59
- it 'returns an array of contracts' do
60
- client = PactasItero::Client.new(bearer_token: 'bt')
61
- request = stub_get('/api/v1/invoices?from=54b67d9e995ec90bc8f37718').
62
- to_return(
63
- body: fixture('invoices.json'),
64
- headers: { content_type: 'application/json; charset=utf-8'}
65
- )
66
-
67
- invoices = client.invoices_from('54b67d9e995ec90bc8f37718')
68
-
69
- expect(invoices).to be_a Array
70
- end
71
- end
72
-
73
- describe '.invoice' do
74
- it 'requests the correct resource' do
75
- client = PactasItero::Client.new(bearer_token: 'bt')
76
- request = stub_get('/api/v1/invoices/54b67d9e995ec90bc8f37718').
77
- to_return(
78
- body: fixture('invoice.json'),
79
- headers: { content_type: 'application/json; charset=utf-8'}
80
- )
81
-
82
- client.invoice('54b67d9e995ec90bc8f37718')
83
-
84
- expect(request).to have_been_made
85
- end
86
- end
87
-
88
- describe '.invoice_download' do
89
- it "returns the pdf as a string after requesting the correct resource" do
90
- client = PactasItero::Client.new(bearer_token: 'bt')
91
- request = stub_get('/api/v1/invoices/54b67d9e995ec90bc8f37718/download').
92
- to_return(
93
- body: fixture('invoice_download.pdf'),
94
- headers: { content_type: 'application/pdf'}
95
- )
96
-
97
- response = client.invoice_download('54b67d9e995ec90bc8f37718')
98
-
99
- expect(request).to have_been_made
100
- expect(response.class).to be String
101
- end
102
- end
103
- end
@@ -1,44 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe PactasItero::Api::OAuth do
4
- describe "#token" do
5
- it "requests the correct resource" do
6
- client_credentials_request = stub_post("https://sandbox.billwerk.com/oauth/token").with(
7
- basic_auth: %w(a_client_id a_client_secret),
8
- body: "grant_type=client_credentials",
9
- headers: {
10
- "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8",
11
- },
12
- )
13
-
14
- client = PactasItero::Client.new(client_id: "a_client_id", client_secret: "a_client_secret")
15
-
16
- client.token
17
-
18
- expect(client_credentials_request).to have_been_made
19
- end
20
-
21
- it "returns the bearer token" do
22
- stub_post("https://sandbox.billwerk.com/oauth/token").with(
23
- basic_auth: %w(a_client_id a_client_secret),
24
- body: "grant_type=client_credentials",
25
- headers: {
26
- "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8",
27
- },
28
- ).to_return(
29
- status: 200,
30
- body: fixture("bearer_token.json"),
31
- headers: {
32
- content_type: "application/json; charset=utf-8",
33
- },
34
- )
35
-
36
- client = PactasItero::Client.new(client_id: "a_client_id", client_secret: "a_client_secret")
37
- bearer_token = client.token
38
-
39
- expect(bearer_token.access_token).to eq("top_secret_access_token")
40
- expect(bearer_token.token_type).to eq("bearer")
41
- expect(bearer_token.expires).to eq(0)
42
- end
43
- end
44
- end
@@ -1,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PactasItero::Api::Orders do
4
- describe ".create_order" do
5
- it "requests the correct resource" do
6
- client = PactasItero::Client.new(bearer_token: 'bt')
7
- post_data = {
8
- ContractId: "5370e5ab9e40071fd01e01e0",
9
- Cart: {
10
- PlanVariantId: "525bf9089e40073a58590fd5"
11
- }
12
- }.to_json
13
- request = stub_post('/api/v1/orders').
14
- with(body: post_data).
15
- to_return(
16
- body: fixture('create_order_response.json'),
17
- headers: { content_type: 'application/json; charset=utf-8'}
18
- )
19
-
20
- client.create_order(
21
- contract_id: "5370e5ab9e40071fd01e01e0",
22
- cart: {
23
- plan_variant_id: "525bf9089e40073a58590fd5"
24
- }
25
- )
26
-
27
- expect(request).to have_been_made
28
- end
29
-
30
- it 'returns the created order' do
31
- client = PactasItero::Client.new(bearer_token: 'bt')
32
- post_data = {
33
- ContractId: "5370e5ab9e40071fd01e01e0",
34
- Cart: {
35
- PlanVariantId: "525bf9089e40073a58590fd5"
36
- }
37
- }.to_json
38
- request = stub_post('/api/v1/orders').
39
- with(body: post_data).
40
- to_return(
41
- body: fixture('create_order_response.json'),
42
- headers: { content_type: 'application/json; charset=utf-8'}
43
- )
44
-
45
- order = client.create_order(
46
- contract_id: "5370e5ab9e40071fd01e01e0",
47
- cart: {
48
- plan_variant_id: "525bf9089e40073a58590fd5"
49
- }
50
- )
51
-
52
- expect(order.id).to eq '537dfcab9e400760b4cd6347'
53
- expect(order.contract_id).to eq '5370e5ab9e40071fd01e01e0'
54
- end
55
- end
56
-
57
- describe '.order' do
58
- it 'requests the correct resource' do
59
- client = PactasItero::Client.new(bearer_token: 'bt')
60
- request = stub_get('/api/v1/orders/5357bc4f1d8dd00fa0db6c31').
61
- to_return(
62
- body: fixture('order.json'),
63
- headers: { content_type: 'application/json; charset=utf-8'}
64
- )
65
-
66
- client.order('5357bc4f1d8dd00fa0db6c31')
67
-
68
- expect(request).to have_been_made
69
- end
70
- end
71
-
72
- describe ".commit_order" do
73
- it "requests the correct resource" do
74
- client = PactasItero::Client.new(bearer_token: 'bt')
75
- request = stub_post('/api/v1/orders/537dfcab9e400760b4cd6347/commit').
76
- with(body: {}.to_json).
77
- to_return(
78
- body: fixture('commit_order_response.json'),
79
- headers: { content_type: 'application/json; charset=utf-8'}
80
- )
81
-
82
- client.commit_order('537dfcab9e400760b4cd6347')
83
-
84
- expect(request).to have_been_made
85
- end
86
-
87
- it 'returns the updated contract' do
88
- client = PactasItero::Client.new(bearer_token: 'bt')
89
- request = stub_post('/api/v1/orders/537dfcab9e400760b4cd6347/commit').
90
- with(body: {}.to_json).
91
- to_return(
92
- body: fixture('commit_order_response.json'),
93
- headers: { content_type: 'application/json; charset=utf-8'}
94
- )
95
-
96
- contract = client.commit_order('537dfcab9e400760b4cd6347')
97
-
98
- expect(contract.id).to eq '5370e5ab9e40071fd01e01e0'
99
- expect(contract.current_phase.plan_variant_id).to eq '525bf9089e40073a58590fd5'
100
- end
101
- end
102
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe PactasItero::Api::PaymentTransactions do
5
- describe ".payment_transaction" do
6
- it "requests the correct resource" do
7
- client = PactasItero::Client.new(bearer_token: "bearer_token")
8
- request = stub_get("/api/v1/PaymentTransactions/payment_transaction_id").to_return(
9
- body: fixture("payment_transaction.json"),
10
- headers: { content_type: "application/json; charset=utf-8" },
11
- )
12
-
13
- client.payment_transaction("payment_transaction_id")
14
-
15
- expect(request).to have_been_made
16
- end
17
-
18
- it "returns the payment transaction details" do
19
- client = PactasItero::Client.new(bearer_token: "bearer_token")
20
- stub_get("/api/v1/PaymentTransactions/payment_transaction_id").to_return(
21
- body: fixture("payment_transaction.json"),
22
- headers: { content_type: "application/json; charset=utf-8" },
23
- )
24
-
25
- transaction = client.payment_transaction("payment_transaction_id")
26
-
27
- expect(transaction.amount).to eq 11.89
28
- expect(transaction.contract_id).to eq "592d74a981b1f010f04293a4"
29
- expect(transaction.currency).to eq "EUR"
30
- expect(transaction.customer_id).to eq "592d74a881b1f010f04293a2"
31
- expect(transaction.customer_name).to eq "Example Company"
32
- expect(transaction.id).to eq "597de03d81b1ef0d18a46f4e"
33
- expect(transaction.payment_provider).to eq "Example Provider"
34
- expect(transaction.payment_provider_role).to eq "CreditCard"
35
- expect(transaction.preauth).to eq false
36
- expect(transaction.provider_transaction_id).to eq "ccec718e-271e-4d0e-b0e1-94894e40c0c7"
37
- expect(transaction.status).to eq(
38
- "amount" => 11.89,
39
- "http_code" => 0,
40
- "preauth" => false,
41
- "status" => "Succeeded",
42
- "timestamp" => "2017-07-30T13:33:49.9900000Z",
43
- )
44
- expect(transaction.status_history).to eq(
45
- [
46
- {
47
- "amount" => 11.89,
48
- "http_code" => 0,
49
- "preauth" => false,
50
- "status" => "InProgress",
51
- "timestamp" => "2017-07-30T13:33:49.9760000Z",
52
- },
53
- {
54
- "amount" => 11.89,
55
- "http_code" => 0,
56
- "preauth" => false,
57
- "status" => "Succeeded",
58
- "timestamp" => "2017-07-30T13:33:49.9900000Z",
59
- },
60
- ],
61
- )
62
- expect(transaction.status_timestamp).to eq "2017-07-30T13:33:49.9900000Z"
63
- expect(transaction.trigger).to eq "Recurring"
64
- end
65
- end
66
- end
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PactasItero::Api::RatedItems do
4
- describe ".create_rated_item" do
5
- it "requests the correct resource" do
6
- client = PactasItero::Client.new(bearer_token: 'bt')
7
- post_data = {
8
- PeriodStart: '2014-09-19T08:18:51.907Z',
9
- PeriodEnd: '2014-09-19T08:19:51.907Z',
10
- Quantity: 2,
11
- Description: 'the description',
12
- PricePerUnit: 123.45,
13
- TaxPolicyId: 'tax-policy-id',
14
- }.to_json
15
- request = stub_post('/api/v1/contracts/contract-id/ratedItems').
16
- with(body: post_data).
17
- to_return(
18
- body: fixture('create_rated_item.json'),
19
- headers: { content_type: 'application/json; charset=utf-8'}
20
- )
21
-
22
- client.create_rated_item(
23
- 'contract-id',
24
- 2,
25
- 'the description',
26
- 123.45,
27
- 'tax-policy-id',
28
- {
29
- period_start: "2014-09-19T08:18:51.907Z",
30
- period_end: "2014-09-19T08:19:51.907Z"
31
- }
32
- )
33
-
34
- expect(request).to have_been_made
35
- end
36
-
37
- it 'returns the created rated item' do
38
- client = PactasItero::Client.new(bearer_token: 'bt')
39
- post_data = {
40
- PeriodStart: '2014-09-19T08:18:51.907Z',
41
- PeriodEnd: '2014-09-19T08:19:51.907Z',
42
- Quantity: 2,
43
- Description: 'the description',
44
- PricePerUnit: 123.45,
45
- TaxPolicyId: 'tax-policy-id',
46
- }.to_json
47
- request = stub_post('/api/v1/contracts/contract-id/ratedItems').
48
- with(body: post_data).
49
- to_return(
50
- body: fixture('create_rated_item.json'),
51
- headers: { content_type: 'application/json; charset=utf-8'}
52
- )
53
-
54
- rated_item = client.create_rated_item(
55
- 'contract-id',
56
- 2,
57
- 'the description',
58
- 123.45,
59
- 'tax-policy-id',
60
- {
61
- period_start: "2014-09-19T08:18:51.907Z",
62
- period_end: "2014-09-19T08:19:51.907Z"
63
- }
64
- )
65
-
66
- expect(rated_item.description).to eq 'the description'
67
- expect(rated_item.period_end).to eq '2014-09-19T08:18:51.907Z'
68
- expect(rated_item.period_start).to eq '2014-09-19T08:18:51.907Z'
69
- expect(rated_item.price_per_unit).to eq 123.45
70
- expect(rated_item.quantity).to eq 2
71
- expect(rated_item.tax_policy_id).to eq 'tax-policy-id'
72
- end
73
- end
74
-
75
- describe ".rated_items" do
76
- it "returns rated items" do
77
- client = PactasItero::Client.new(bearer_token: 'bt')
78
- stub_get("/api/v1/contracts/contract-id/ratedItems").
79
- to_return(
80
- body: fixture("rated_items.json"),
81
- headers: { content_type: "application/json; charset=utf-8"}
82
- )
83
-
84
- rated_items = client.rated_items("contract-id")
85
-
86
- expect(rated_items).to be_a Array
87
- rated_item = rated_items.first
88
- expect(rated_item.id).to eq "591b847314aa03167c5a3b08"
89
- expect(rated_item.line_item_id).to eq "59308e9781b1ef1190f21478"
90
- expect(rated_item.quantity).to eq 1
91
- expect(rated_item.price_per_unit).to eq 3.9
92
- expect(rated_item.tax_policy_id).to eq "tax-policy-id"
93
- expect(rated_item.description).to eq "1x DHL Versandmarken"
94
- expect(rated_item.period_end).to eq "2017-05-15T22:00:00.0000000Z"
95
- expect(rated_item.period_start).to eq "2017-05-15T22:00:00.0000000Z"
96
- end
97
- end
98
-
99
- describe ".delete_rated_item" do
100
- it "deletes a rated item" do
101
- client = PactasItero::Client.new(bearer_token: 'bt')
102
- stub_delete("/api/v1/ratedItems/rated-item-id").
103
- to_return(
104
- body: "",
105
- headers: { content_type: "application/json; charset=utf-8"}
106
- )
107
-
108
- response = client.delete_rated_item("rated-item-id")
109
-
110
- expect(response).to be_nil
111
- end
112
- end
113
- end