shopify_api 4.0.7 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c171c258fbdbd3d55c3d29332ae04332f4712cf
4
- data.tar.gz: ae0cc40c73d57a7938195fc1d0bb90af8aeff0b1
3
+ metadata.gz: b0d75415d15fd29b2fc2eb1dda08bbea82c45093
4
+ data.tar.gz: 3a93ef51f81e79cb1c88fda8593768510a59090c
5
5
  SHA512:
6
- metadata.gz: 58ec881bfa5d516de2c9a39aefd1d8278b933f7fffe949e191d451b5b03a55e2afccb4c60c9ff9f4e3965fa30c15fa7b7336d18ad0f5d0510c13030338e81fd5
7
- data.tar.gz: 28d02bc796f1ff6dcd56b83a01acfd94ef6aed81bcaef446c2bb4d1d30a0156c5534250f14db4cff2c5d4d7555c8665cbefc68ea4be604acf5a8b9e03e3c0a27
6
+ metadata.gz: e2b080d989b2bc8ed91d267daa040c815f3a675b258691eb75f52f9bef5d958e6b31f875df8f1c28a09fb699329ab70121e5d652aa2047566c414d93e50aaad7
7
+ data.tar.gz: ff815d6221f9073c3250f6970b1ba727fa7b2456798337aa3971650b7e1468a77be7a1add37fe7170b22dfd6b7cf197e5403cf5d78d22af4d970cc69a431d033
@@ -12,6 +12,10 @@ module ShopifyAPI
12
12
  end
13
13
  end
14
14
 
15
+ def usage_charges
16
+ UsageCharge.find(:all, params: { recurring_application_charge_id: id })
17
+ end
18
+
15
19
  def cancel
16
20
  load_attributes_from_response(self.destroy)
17
21
  end
@@ -19,5 +23,9 @@ module ShopifyAPI
19
23
  def activate
20
24
  load_attributes_from_response(post(:activate))
21
25
  end
26
+
27
+ def customize(customize_recurring_app_charge_params = {})
28
+ load_attributes_from_response(put(:customize, recurring_application_charge: customize_recurring_app_charge_params ))
29
+ end
22
30
  end
23
31
  end
@@ -0,0 +1,5 @@
1
+ module ShopifyAPI
2
+ class UsageCharge < Base
3
+ init_prefix :recurring_application_charge
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "4.0.7"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -13,6 +13,8 @@
13
13
  "test": null,
14
14
  "trial_days": 0,
15
15
  "trial_ends_on": null,
16
+ "terms": "$1 per 1000 emails",
17
+ "capped_amount": "100.00",
16
18
  "updated_at": "2014-01-20T13:42:19-05:00",
17
19
  "decorated_return_url": "http://super-duper.shopifyapps.com?charge_id=654381177",
18
20
  "confirmation_url": "http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164"
@@ -0,0 +1,5 @@
1
+ {
2
+ "recurring_application_charge": {
3
+ "update_capped_amount_url": "http://apple.myshopify.com/admin/charges/654381177/confirm_update_capped_amount?signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164"
4
+ }
5
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "usage_charge": {
3
+ "id": 359376002,
4
+ "description": "1000 emails",
5
+ "price": "9.00",
6
+ "recurring_application_charge_id": 654381177,
7
+ "billing_on": "2015-07-08",
8
+ "balance_remaining": "91.00",
9
+ "balance_used": "9.00"
10
+ }
11
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "usage_charges": [
3
+ {
4
+ "id": 359376005,
5
+ "description": "1000 emails",
6
+ "price": "9.00",
7
+ "recurring_application_charge_id": 654381177,
8
+ "billing_on": "2015-07-08",
9
+ "balance_remaining": "82.00",
10
+ "balance_used": "18.00"
11
+
12
+ },
13
+ {
14
+ "id": 359376006,
15
+ "description": "1000 emails",
16
+ "price": "9.00",
17
+ "recurring_application_charge_id": 654381177,
18
+ "billing_on": "2015-07-08",
19
+ "balance_remaining": "82.00",
20
+ "balance_used": "18.00"
21
+ }
22
+ ]
23
+ }
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class RecurringApplicationChargeTest < Test::Unit::TestCase
4
4
 
5
5
  def test_recurring_application_charges_create
6
- fake "recurring_application_charges", :method => :post, :status => 201, :body => load_fixture('recurring_application_charge')
6
+ fake "recurring_application_charges", method: :post, status: 201, body: load_fixture('recurring_application_charge')
7
7
 
8
8
  charge = ShopifyAPI::RecurringApplicationCharge.create(
9
9
  name: "Default Plan",
@@ -15,7 +15,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_get_recurring_application_charges
18
- fake "recurring_application_charges/654381177", :method => :get, :status => 201, :body => load_fixture('recurring_application_charge')
18
+ fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
19
19
 
20
20
  charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
21
21
 
@@ -23,7 +23,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_list_recurring_application_charges
26
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
26
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
27
27
 
28
28
  charge = ShopifyAPI::RecurringApplicationCharge.find(:all)
29
29
 
@@ -31,23 +31,23 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  def test_list_since_recurring_application_charges
34
- fake "recurring_application_charges.json?since_id=64512345",:extension => false, :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
34
+ fake "recurring_application_charges.json?since_id=64512345",extension: false, method: :get, status: 201, body: load_fixture('recurring_application_charges')
35
35
 
36
- charge = ShopifyAPI::RecurringApplicationCharge.find(:all, :params => {:since_id => '64512345'})
36
+ charge = ShopifyAPI::RecurringApplicationCharge.find(:all, params: { since_id: '64512345' })
37
37
 
38
38
  assert_equal "Super Mega Plan", charge.last.name
39
39
  end
40
40
 
41
41
  def test_list_fields_recurring_application_charges
42
- fake "recurring_application_charges.json?fields=name",:extension => false, :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
42
+ fake "recurring_application_charges.json?fields=name",extension: false, method: :get, status: 201, body: load_fixture('recurring_application_charges')
43
43
 
44
- charge = ShopifyAPI::RecurringApplicationCharge.find(:all, :params => {:fields => 'name'})
44
+ charge = ShopifyAPI::RecurringApplicationCharge.find(:all, params: { fields: 'name' })
45
45
 
46
46
  assert_equal "Super Mega Plan", charge.last.name
47
47
  end
48
48
 
49
49
  def test_pending_recurring_application_charge
50
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
50
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
51
51
 
52
52
  charge = ShopifyAPI::RecurringApplicationCharge.pending
53
53
 
@@ -55,7 +55,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
55
55
  end
56
56
 
57
57
  def test_cancelled_recurring_application_charge
58
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
58
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
59
59
 
60
60
  charge = ShopifyAPI::RecurringApplicationCharge.cancelled
61
61
 
@@ -63,7 +63,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
63
63
  end
64
64
 
65
65
  def test_accepted_recurring_application_charge
66
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
66
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
67
67
 
68
68
  charge = ShopifyAPI::RecurringApplicationCharge.accepted
69
69
 
@@ -72,7 +72,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
72
72
  end
73
73
 
74
74
  def test_declined_recurring_application_charge
75
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
75
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
76
76
 
77
77
  charge = ShopifyAPI::RecurringApplicationCharge.declined
78
78
 
@@ -80,22 +80,51 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
80
80
  end
81
81
 
82
82
  def test_activate_recurring_application_charge
83
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
84
- fake "recurring_application_charges/455696199/activate", :method => :post, :status => 200, :body => "{}"
83
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
84
+ fake "recurring_application_charges/455696199/activate", method: :post, status: 200, body: "{}"
85
85
 
86
86
  charge = ShopifyAPI::RecurringApplicationCharge.accepted
87
87
 
88
88
  assert charge.last.activate
89
89
  end
90
90
 
91
+ def test_adjust_recurring_application_charge
92
+ fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
93
+ fake "recurring_application_charges/654381177/customize.json?recurring_application_charge%5Bcapped_amount%5D=200", method: :put, body: load_fixture('recurring_application_charge_adjustment'), extension: false
94
+
95
+ charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
96
+
97
+ assert charge.customize(capped_amount: 200)
98
+ end
99
+
91
100
  def test_cancel_recurring_application_charge
92
- fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
93
- fake "recurring_application_charges/455696194", :method => :delete, :status => 200, :body => "{}"
101
+ fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
102
+ fake "recurring_application_charges/455696194", method: :delete, status: 200, body: "{}"
94
103
 
95
104
  charge = ShopifyAPI::RecurringApplicationCharge.current
96
105
  assert charge.cancel
97
106
  end
98
107
 
108
+ def test_usage_charges_recurring_application_charge_found
109
+ fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
110
+ fake "recurring_application_charges/654381177/usage_charges", method: :get, status: 201, body: load_fixture('usage_charges')
111
+
112
+ charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
113
+ usage_charges = charge.usage_charges
114
+
115
+ assert_equal 2, usage_charges.length
116
+ end
117
+
118
+ def test_usage_charges_recurring_application_charge_not_found
119
+ fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
120
+ fake "recurring_application_charges/654381177/usage_charges", method: :get, status: 201, body: "[]"
121
+
122
+ charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
123
+ usage_charges = charge.usage_charges
124
+
125
+ assert_equal 0, usage_charges.length
126
+ end
127
+
99
128
  def test_no_recurring_application_charge_found
100
129
  fake "recurring_application_charges", body: {recurring_application_charges: []}.to_json
101
130
 
@@ -105,7 +134,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
105
134
  end
106
135
 
107
136
  def test_recurring_application_charge_not_found_error
108
- fake "recurring_application_charges", :body => '{"errors":"Not Found"}', :status => 404
137
+ fake "recurring_application_charges", body: '{"errors":"Not Found"}', status: 404
109
138
 
110
139
  all_application_charges = ShopifyAPI::RecurringApplicationCharge.all
111
140
  if ActiveResource::VERSION::MAJOR >= 4 && ActiveResource::VERSION::MINOR >= 2
@@ -117,5 +146,4 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
117
146
  assert_equal nil, ShopifyAPI::RecurringApplicationCharge.current
118
147
  assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
119
148
  end
120
-
121
149
  end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class UsageChargeTest < Test::Unit::TestCase
4
+
5
+ def test_create_usage_charges
6
+ fake "recurring_application_charges/654381177/usage_charges", method: :post, body: load_fixture('usage_charge')
7
+
8
+ usage_charge = ShopifyAPI::UsageCharge.new(description: '1000 emails', price: 1.0)
9
+ usage_charge.prefix_options = {recurring_application_charge_id: 654381177}
10
+ assert usage_charge.save
11
+ end
12
+
13
+ def test_get_usage_charges
14
+ fake "recurring_application_charges/654381177/usage_charges/359376002", method: :get, status: 201, body: load_fixture('usage_charge')
15
+
16
+ usage_charge = ShopifyAPI::UsageCharge.find(359376002, params: {recurring_application_charge_id: 654381177})
17
+
18
+ assert_equal "1000 emails", usage_charge.description
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.7
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -186,6 +186,7 @@ files:
186
186
  - lib/shopify_api/resources/tax_line.rb
187
187
  - lib/shopify_api/resources/theme.rb
188
188
  - lib/shopify_api/resources/transaction.rb
189
+ - lib/shopify_api/resources/usage_charge.rb
189
190
  - lib/shopify_api/resources/variant.rb
190
191
  - lib/shopify_api/resources/webhook.rb
191
192
  - lib/shopify_api/session.rb
@@ -237,6 +238,7 @@ files:
237
238
  - test/fixtures/policies.json
238
239
  - test/fixtures/product.json
239
240
  - test/fixtures/recurring_application_charge.json
241
+ - test/fixtures/recurring_application_charge_adjustment.json
240
242
  - test/fixtures/recurring_application_charges.json
241
243
  - test/fixtures/script_tag.json
242
244
  - test/fixtures/script_tags.json
@@ -244,6 +246,8 @@ files:
244
246
  - test/fixtures/shop.json
245
247
  - test/fixtures/tags.json
246
248
  - test/fixtures/transaction.json
249
+ - test/fixtures/usage_charge.json
250
+ - test/fixtures/usage_charges.json
247
251
  - test/fixtures/variant.json
248
252
  - test/fixtures/variants.json
249
253
  - test/fixtures/webhook.json
@@ -267,6 +271,7 @@ files:
267
271
  - test/shop_test.rb
268
272
  - test/test_helper.rb
269
273
  - test/transaction_test.rb
274
+ - test/usage_charge_test.rb
270
275
  - test/variant_test.rb
271
276
  - test/webhook_test.rb
272
277
  homepage: http://www.shopify.com/partners/apps