chargify_api_ares 1.4.1 → 1.4.2
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/.travis.yml +3 -0
- data/Gemfile.lock +2 -2
- data/HISTORY.md +8 -0
- data/chargify_api_ares.gemspec +2 -2
- data/examples/coupons.rb +3 -0
- data/gemfiles/rails_3.gemfile.lock +2 -2
- data/gemfiles/rails_4.1.gemfile.lock +2 -2
- data/gemfiles/rails_4.gemfile.lock +2 -2
- data/lib/chargify_api_ares/resources/allocation.rb +22 -5
- data/spec/resources/allocation_spec.rb +91 -0
- data/spec/spec_helper.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcbd78797c225cef3292433dc0e2bb4d945d15a8
|
4
|
+
data.tar.gz: ffd3b68cc14dc3fabbc3e565c40221b25054d646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839fd752a315359cda9cfdb113db5bc2f38c2000523d997cc138c87778d4db199c9ad68655d1a7cd768f2d2177766991f05bb4555140f3370b3baa832e6fb2b1
|
7
|
+
data.tar.gz: 824899b30d8ba53ad8d5aa20d87c6a9dd106d3fe4786fbde563d627d6324281633a9571df19c62b376f11de25bf379a75b507b06ad6a4598bfe279d92a0cca4c
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.4.2 / Jan 4 2016
|
2
|
+
|
3
|
+
* Adds `Chargify::Allocations.bulk_create` to work with https://docs.chargify.com/api-allocations#create-multiple-allocations. [PR 125](https://github.com/chargify/chargify_api_ares/pull/125) by @ryansch
|
4
|
+
|
5
|
+
## 1.4.1 / Nov 12 2015
|
6
|
+
|
7
|
+
* Adds `paypal_account` nested attribute to subscription [PR 119](https://github.com/chargify/chargify_api_ares/pull/119) by @richmisen
|
8
|
+
|
1
9
|
## 1.4.0 / Oct 6 2015
|
2
10
|
|
3
11
|
* Reverts custom `load_remote_errors` for Migration API (https://github.com/chargify/chargify_api_ares/pull/118)
|
data/chargify_api_ares.gemspec
CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.rubygems_version = '1.3.7'
|
5
5
|
|
6
6
|
s.name = 'chargify_api_ares'
|
7
|
-
s.version = '1.4.
|
8
|
-
s.date = '
|
7
|
+
s.version = '1.4.2'
|
8
|
+
s.date = '2016-01-04'
|
9
9
|
s.summary = 'A Chargify API wrapper for Ruby using ActiveResource'
|
10
10
|
s.description = ''
|
11
11
|
s.authors = ["Chargify Development Team"]
|
data/examples/coupons.rb
CHANGED
@@ -48,3 +48,6 @@ subscription.add_coupon('5OFF')
|
|
48
48
|
# Remove coupon from subscription
|
49
49
|
subscription = Subscription.find_by_customer_reference('moklett')
|
50
50
|
subscription.remove_coupon
|
51
|
+
|
52
|
+
# Validate a coupon code (or subcode)
|
53
|
+
coupon = Chargify::Coupon.validate(coupon_code: "ABC123", product_family_id: 12345)
|
@@ -1,9 +1,26 @@
|
|
1
1
|
module Chargify
|
2
|
-
|
3
2
|
class Allocation < Base
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
self.prefix = "/subscriptions/:subscription_id/components/:component_id/"
|
4
|
+
|
5
|
+
def self.bulk_create_prefix(opts = {})
|
6
|
+
subscription_id = opts[:subscription_id]
|
7
|
+
raise ArgumentError, 'subscription_id required' if subscription_id.nil?
|
8
|
+
|
9
|
+
"/subscriptions/#{subscription_id}/allocations.#{format.extension}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.bulk_create(opts = {})
|
13
|
+
return [] if opts[:allocations].blank?
|
14
|
+
|
15
|
+
subscription_id = opts.delete(:subscription_id)
|
16
|
+
raise ArgumentError, 'subscription_id required' if subscription_id.nil?
|
17
|
+
|
18
|
+
response = connection.post(
|
19
|
+
bulk_create_prefix(subscription_id: subscription_id),
|
20
|
+
format.encode(opts),
|
21
|
+
headers
|
22
|
+
)
|
23
|
+
instantiate_collection(format.decode(response.body))
|
24
|
+
end
|
7
25
|
end
|
8
|
-
|
9
26
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chargify::Allocation do
|
4
|
+
let(:subscription_id) { 123 }
|
5
|
+
let(:component_id) { 456 }
|
6
|
+
let(:allocations) do
|
7
|
+
[
|
8
|
+
{
|
9
|
+
component_id: component_id,
|
10
|
+
quantity: 1,
|
11
|
+
memo: 'test'
|
12
|
+
}
|
13
|
+
]
|
14
|
+
end
|
15
|
+
describe '.bulk_create' do
|
16
|
+
context 'when no allocations are specified' do
|
17
|
+
it 'returns an empty array' do
|
18
|
+
result = Chargify::Allocation.bulk_create(allocations: [])
|
19
|
+
expect(result).to be_empty
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when the subscription_id is missing' do
|
24
|
+
it 'raises' do
|
25
|
+
expect {
|
26
|
+
Chargify::Allocation.bulk_create(allocations: allocations)
|
27
|
+
}.to raise_error(/subscription_id required/)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with correct parameters' do
|
32
|
+
let(:json_body) do
|
33
|
+
[{
|
34
|
+
allocation: {
|
35
|
+
component_id: component_id,
|
36
|
+
subscription_id: subscription_id,
|
37
|
+
quantity: 1,
|
38
|
+
previous_quantity: 0,
|
39
|
+
memo: 'test',
|
40
|
+
timestamp: Time.now.to_s(:iso8601),
|
41
|
+
proration_upgrade_scheme: 'prorate-attempt-capture',
|
42
|
+
proration_downgrade_scheme: 'no-prorate',
|
43
|
+
payment: {
|
44
|
+
amount_in_cents: 2000,
|
45
|
+
success: true,
|
46
|
+
memo: 'Payment for: Prorated component allocation',
|
47
|
+
id: 123
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}].to_json
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:headers) do
|
54
|
+
{
|
55
|
+
'Content-Type' => 'application/json',
|
56
|
+
'Authorization' => 'Basic foobar=='
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
before do
|
61
|
+
FakeWeb.clean_registry
|
62
|
+
Chargify::Allocation.format = :json
|
63
|
+
FakeWeb.register_uri(
|
64
|
+
:post,
|
65
|
+
URI.join(
|
66
|
+
test_domain,
|
67
|
+
Chargify::Allocation.bulk_create_prefix(
|
68
|
+
subscription_id: subscription_id
|
69
|
+
)
|
70
|
+
),
|
71
|
+
body: json_body,
|
72
|
+
content_type: 'application/json'
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
after do
|
77
|
+
FakeWeb.clean_registry
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns a collection of allocations' do
|
81
|
+
result = Chargify::Allocation.bulk_create(
|
82
|
+
subscription_id: subscription_id,
|
83
|
+
allocations: allocations
|
84
|
+
)
|
85
|
+
expect(result.size).to eq 1
|
86
|
+
expect(result.first).to be_a Chargify::Allocation
|
87
|
+
expect(result.first.payment).to be_a Chargify::Allocation::Payment
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chargify_api_ares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chargify Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- spec/remote/remote.example.yml
|
225
225
|
- spec/remote/remote_helper.rb
|
226
226
|
- spec/remote/remote_spec.rb
|
227
|
+
- spec/resources/allocation_spec.rb
|
227
228
|
- spec/resources/base_spec.rb
|
228
229
|
- spec/resources/charge_spec.rb
|
229
230
|
- spec/resources/coupon_spec.rb
|
@@ -276,6 +277,7 @@ test_files:
|
|
276
277
|
- spec/remote/remote.example.yml
|
277
278
|
- spec/remote/remote_helper.rb
|
278
279
|
- spec/remote/remote_spec.rb
|
280
|
+
- spec/resources/allocation_spec.rb
|
279
281
|
- spec/resources/base_spec.rb
|
280
282
|
- spec/resources/charge_spec.rb
|
281
283
|
- spec/resources/coupon_spec.rb
|