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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5d48fc637ec7a266839494a814abf7161a180d0
4
- data.tar.gz: 0d239d9b8d6df630ed305f3313f820c443d48bdb
3
+ metadata.gz: dcbd78797c225cef3292433dc0e2bb4d945d15a8
4
+ data.tar.gz: ffd3b68cc14dc3fabbc3e565c40221b25054d646
5
5
  SHA512:
6
- metadata.gz: 324ae2a30a0fb96918903d6803c08fc657811c15b46d6cad37bce584d372f05d7221d5a2efa6e119074744e506f091f419f765b0ac52f1136c14180ef568f939
7
- data.tar.gz: 5f8ec8d8473f06a5b0318eba1e72753c8608af661f14dec2155fb8c17b24fdc0d5ace87d4b15cef9032a0947da23af1b7bba5efa366a42a2fc4a40118ec6c1c9
6
+ metadata.gz: 839fd752a315359cda9cfdb113db5bc2f38c2000523d997cc138c87778d4db199c9ad68655d1a7cd768f2d2177766991f05bb4555140f3370b3baa832e6fb2b1
7
+ data.tar.gz: 824899b30d8ba53ad8d5aa20d87c6a9dd106d3fe4786fbde563d627d6324281633a9571df19c62b376f11de25bf379a75b507b06ad6a4598bfe279d92a0cca4c
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem update --system
4
+ - gem update bundler
2
5
  rvm:
3
6
  - 2.1.3
4
7
  - 2.0.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chargify_api_ares (1.4.1)
4
+ chargify_api_ares (1.4.2)
5
5
  activeresource (>= 3.2.16)
6
6
 
7
7
  GEM
@@ -67,4 +67,4 @@ DEPENDENCIES
67
67
  vcr
68
68
 
69
69
  BUNDLED WITH
70
- 1.10.5
70
+ 1.11.2
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)
@@ -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.1'
8
- s.date = '2015-11-12'
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"]
@@ -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,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- chargify_api_ares (1.4.1)
4
+ chargify_api_ares (1.4.2)
5
5
  activeresource (>= 3.2.16)
6
6
 
7
7
  GEM
@@ -128,4 +128,4 @@ DEPENDENCIES
128
128
  vcr
129
129
 
130
130
  BUNDLED WITH
131
- 1.10.5
131
+ 1.11.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- chargify_api_ares (1.4.1)
4
+ chargify_api_ares (1.4.2)
5
5
  activeresource (>= 3.2.16)
6
6
 
7
7
  GEM
@@ -128,4 +128,4 @@ DEPENDENCIES
128
128
  vcr
129
129
 
130
130
  BUNDLED WITH
131
- 1.10.5
131
+ 1.11.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- chargify_api_ares (1.4.1)
4
+ chargify_api_ares (1.4.2)
5
5
  activeresource (>= 3.2.16)
6
6
 
7
7
  GEM
@@ -122,4 +122,4 @@ DEPENDENCIES
122
122
  vcr
123
123
 
124
124
  BUNDLED WITH
125
- 1.10.5
125
+ 1.11.2
@@ -1,9 +1,26 @@
1
1
  module Chargify
2
-
3
2
  class Allocation < Base
4
-
5
- self.prefix = "/subscriptions/:subscription_id/components/:component_id/"
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
@@ -36,6 +36,10 @@ RSpec.configure do |config|
36
36
  config.after(:each, :fake_resource) do
37
37
  ActiveResource::FakeResource.disable
38
38
  end
39
+
40
+ config.before(:each) do
41
+ Chargify.configure {}
42
+ end
39
43
  end
40
44
 
41
45
  def test_domain
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.1
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: 2015-11-12 00:00:00.000000000 Z
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