apruve 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/apruve/resources.rb +1 -0
- data/lib/apruve/resources/shipment.rb +42 -0
- data/lib/apruve/version.rb +1 -1
- data/spec/apruve/resources/shipment_spec.rb +173 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21a3b62543cd831797e61455cf14a4c56dcfa6e
|
4
|
+
data.tar.gz: 2d408819e0d45f1ba3d8dc5a8718a5d4e69043da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f5197f4c7ada27283bfb88983a933f43e6128edc202288276b8938e28f0af9426b8ccb9f2084685ed7a8fd3d2b73f1c643f567f4089e852b79df3f10cdee036
|
7
|
+
data.tar.gz: 1cf2c2a1337c4e578c33b99a6eafa45098045688823ebda8eda8f3d0cc540bf92d45ae14be18e4ccc6bbfa2b9a25a0f4f13709302a5a12eaf8bcfc9550596244
|
data/Gemfile.lock
CHANGED
data/lib/apruve/resources.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative 'resources/order'
|
|
6
6
|
require_relative 'resources/order_item'
|
7
7
|
require_relative 'resources/invoice'
|
8
8
|
require_relative 'resources/invoice_item'
|
9
|
+
require_relative 'resources/shipment'
|
9
10
|
require_relative 'resources/merchant'
|
10
11
|
require_relative 'resources/subscription'
|
11
12
|
require_relative 'resources/subscription_adjustment'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Apruve
|
2
|
+
class Shipment < Apruve::ApruveObject
|
3
|
+
attr_accessor :id, :invoice_id, :amount_cents, :currency, :shipper, :shipped_at, :tracking_number, :delivered_at, :merchant_notes, :invoice_items
|
4
|
+
|
5
|
+
def self.find(invoice_id, id)
|
6
|
+
response = Apruve.get("invoices/#{invoice_id}/shipments/#{id}")
|
7
|
+
Shipment.new(response.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(params)
|
11
|
+
super
|
12
|
+
# hydrate payment items if appropriate
|
13
|
+
if @invoice_items.nil?
|
14
|
+
@invoice_items = []
|
15
|
+
elsif @invoice_items.is_a?(Array) && @invoice_items.first.is_a?(Hash)
|
16
|
+
hydrated_items = []
|
17
|
+
@invoice_items.each do |item|
|
18
|
+
hydrated_items << Apruve::OrderItem.new(item)
|
19
|
+
end
|
20
|
+
@invoice_items = hydrated_items
|
21
|
+
end
|
22
|
+
@currency = Apruve.default_currency if currency.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate
|
26
|
+
errors = []
|
27
|
+
errors << 'invoice_id must be set' if invoice_id.nil?
|
28
|
+
raise Apruve::ValidationError.new(errors) if errors.length > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def save!
|
32
|
+
validate
|
33
|
+
response = Apruve.post("invoices/#{self.invoice_id}/shipments", self.to_json)
|
34
|
+
self.id = response.body['id']
|
35
|
+
end
|
36
|
+
|
37
|
+
def update!
|
38
|
+
validate
|
39
|
+
response = Apruve.patch("invoices/#{self.invoice_id}/shipments/#{id}", self.to_json)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/apruve/version.rb
CHANGED
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apruve::Shipment do
|
4
|
+
before :each do
|
5
|
+
Apruve.configure('f5fbe71d68772d1f562ed6f598b995b3', 'local')
|
6
|
+
end
|
7
|
+
|
8
|
+
let (:amount_cents) { 1234578 }
|
9
|
+
let (:id) { '91ac96c0ffc9577ecb634ad726b1874e' }
|
10
|
+
let (:invoice_id) { '2d1bd4f93a1b9ed034e36783adb29bed' }
|
11
|
+
let (:merchant_notes) { 'foo' }
|
12
|
+
let (:shipper) { 'shipper name' }
|
13
|
+
let (:shipped_at) { '2016-11-11T00:00:00-06:00' }
|
14
|
+
let (:delivered_at) { '2016-11-11T00:00:00-06:00' }
|
15
|
+
let (:tracking_number) { '1234abcd' }
|
16
|
+
let (:shipment) do
|
17
|
+
Apruve::Shipment.new(
|
18
|
+
amount_cents: amount_cents,
|
19
|
+
merchant_notes: merchant_notes,
|
20
|
+
id: id,
|
21
|
+
invoice_id: invoice_id,
|
22
|
+
shipper: shipper,
|
23
|
+
shipped_at: shipped_at,
|
24
|
+
delivered_at: delivered_at,
|
25
|
+
tracking_number: tracking_number,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
subject { shipment }
|
29
|
+
|
30
|
+
it { should respond_to(:id) }
|
31
|
+
it { should respond_to(:invoice_id) }
|
32
|
+
it { should respond_to(:amount_cents) }
|
33
|
+
it { should respond_to(:currency) }
|
34
|
+
it { should respond_to(:shipper) }
|
35
|
+
it { should respond_to(:tracking_number) }
|
36
|
+
it { should respond_to(:shipped_at) }
|
37
|
+
it { should respond_to(:delivered_at) }
|
38
|
+
it { should respond_to(:merchant_notes) }
|
39
|
+
it { should respond_to(:invoice_items) }
|
40
|
+
|
41
|
+
describe '#to_json' do
|
42
|
+
let(:expected) do
|
43
|
+
'{"amount_cents":1234578,"merchant_notes":"foo","id":"91ac96c0ffc9577ecb634ad726b1874e","invoice_id":"2d1bd4f93a1b9ed034e36783adb29bed","shipper":"shipper name","shipped_at":"2016-11-11T00:00:00-06:00","delivered_at":"2016-11-11T00:00:00-06:00","tracking_number":"1234abcd","invoice_items":[],"currency":"USD"}'
|
44
|
+
end
|
45
|
+
its(:to_json) { should eq expected }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#validate' do
|
49
|
+
describe 'no errors' do
|
50
|
+
it 'should not raise' do
|
51
|
+
expect { shipment.validate }.not_to raise_error
|
52
|
+
end
|
53
|
+
end
|
54
|
+
describe 'errors' do
|
55
|
+
before :each do
|
56
|
+
shipment.invoice_id = nil
|
57
|
+
end
|
58
|
+
it 'should raise on no invoice_id' do
|
59
|
+
expect { shipment.validate }.to raise_error(Apruve::ValidationError, '["invoice_id must be set"]')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#find' do
|
65
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
66
|
+
let (:invoice_id) { '91ac96c0ffc9577ecb634ad726b1874e' }
|
67
|
+
describe 'success' do
|
68
|
+
let! (:stubs) do
|
69
|
+
faraday_stubs do |stub|
|
70
|
+
stub.get("/api/v4/invoices/#{invoice_id}/shipments/#{id}") { [200, {}, '{}'] }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
it 'should do a get' do
|
74
|
+
Apruve::Shipment.find(invoice_id, id)
|
75
|
+
stubs.verify_stubbed_calls
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'not found' do
|
80
|
+
let! (:stubs) do
|
81
|
+
faraday_stubs do |stub|
|
82
|
+
stub.get("/api/v4/invoices/#{invoice_id}/shipments/#{id}"){ [404, {}, 'Not Found'] }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it 'should raise' do
|
86
|
+
expect { Apruve::Shipment.find(invoice_id, id) }.to raise_error(Apruve::NotFound)
|
87
|
+
stubs.verify_stubbed_calls
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#save' do
|
93
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
94
|
+
let (:invoice_id) { '91ac96c0ffc9577ecb634ad726b1874e' }
|
95
|
+
let (:api_url) { Faker::Internet.url }
|
96
|
+
let (:view_url) { Faker::Internet.url }
|
97
|
+
let (:response) do
|
98
|
+
{
|
99
|
+
id: id,
|
100
|
+
invoice_id: invoice_id,
|
101
|
+
api_url: api_url,
|
102
|
+
view_url: view_url
|
103
|
+
}
|
104
|
+
end
|
105
|
+
describe 'success' do
|
106
|
+
let! (:stubs) do
|
107
|
+
faraday_stubs do |stub|
|
108
|
+
stub.post(
|
109
|
+
"/api/v4/invoices/#{invoice_id}/shipments",
|
110
|
+
shipment.to_json,
|
111
|
+
) { [200, {}, response.to_json] }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
it 'should do a post' do
|
115
|
+
shipment.save!
|
116
|
+
expect(shipment.id).to eq id
|
117
|
+
stubs.verify_stubbed_calls
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'invoice request not found' do
|
122
|
+
let! (:stubs) do
|
123
|
+
faraday_stubs do |stub|
|
124
|
+
stub.post(
|
125
|
+
"/api/v4/invoices/#{invoice_id}/shipments",
|
126
|
+
shipment.to_json,
|
127
|
+
) { [404, {}, 'Not Found'] }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
it 'should raise' do
|
131
|
+
expect { shipment.save! }.to raise_error(Apruve::NotFound)
|
132
|
+
stubs.verify_stubbed_calls
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#update' do
|
138
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
139
|
+
let (:api_url) { Faker::Internet.url }
|
140
|
+
let (:view_url) { Faker::Internet.url }
|
141
|
+
let (:response) do
|
142
|
+
{
|
143
|
+
id: id,
|
144
|
+
api_url: api_url,
|
145
|
+
view_url: view_url
|
146
|
+
}
|
147
|
+
end
|
148
|
+
let (:invoice) { Apruve::Shipment.new({id: id, invoice_id: invoice_id, amount_cents: amount_cents})}
|
149
|
+
describe 'success' do
|
150
|
+
let! (:stubs) do
|
151
|
+
faraday_stubs do |stub|
|
152
|
+
stub.patch("/api/v4/invoices/#{invoice_id}/shipments/#{id}", shipment.to_json) { [200, {}, response.to_json] }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
it 'should do a patch' do
|
156
|
+
shipment.update!
|
157
|
+
stubs.verify_stubbed_calls
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe 'shipment request not found' do
|
162
|
+
let! (:stubs) do
|
163
|
+
faraday_stubs do |stub|
|
164
|
+
stub.patch("/api/v4/invoices/#{invoice_id}/shipments/#{id}", shipment.to_json) { [404, {}, 'Not Found'] }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
it 'should raise' do
|
168
|
+
expect { shipment.update! }.to raise_error(Apruve::NotFound)
|
169
|
+
stubs.verify_stubbed_calls
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apruve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Apruve, Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/apruve/resources/merchant.rb
|
115
115
|
- lib/apruve/resources/order.rb
|
116
116
|
- lib/apruve/resources/order_item.rb
|
117
|
+
- lib/apruve/resources/shipment.rb
|
117
118
|
- lib/apruve/resources/subscription.rb
|
118
119
|
- lib/apruve/resources/subscription_adjustment.rb
|
119
120
|
- lib/apruve/resources/validation_error.rb
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- spec/apruve/resources/merchant_spec.rb
|
131
132
|
- spec/apruve/resources/order_item_spec.rb
|
132
133
|
- spec/apruve/resources/order_spec.rb
|
134
|
+
- spec/apruve/resources/shipment_spec.rb
|
133
135
|
- spec/apruve/resources/subscription_adjustment_spec.rb
|
134
136
|
- spec/apruve/resources/subscription_spec.rb
|
135
137
|
- spec/apruve/resources/webhook_endpoint_spec.rb
|
@@ -168,9 +170,9 @@ test_files:
|
|
168
170
|
- spec/apruve/resources/merchant_spec.rb
|
169
171
|
- spec/apruve/resources/order_item_spec.rb
|
170
172
|
- spec/apruve/resources/order_spec.rb
|
173
|
+
- spec/apruve/resources/shipment_spec.rb
|
171
174
|
- spec/apruve/resources/subscription_adjustment_spec.rb
|
172
175
|
- spec/apruve/resources/subscription_spec.rb
|
173
176
|
- spec/apruve/resources/webhook_endpoint_spec.rb
|
174
177
|
- spec/apruve/response/apruve_exception_middleware_spec.rb
|
175
178
|
- spec/spec_helper.rb
|
176
|
-
has_rdoc:
|