shopify_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +11 -0
- data/lib/shopify_client.rb +10 -0
- data/lib/shopify_client/api/custom_collection.rb +22 -0
- data/lib/shopify_client/api/order.rb +22 -0
- data/lib/shopify_client/api/product.rb +21 -0
- data/lib/shopify_client/api/recurring_application_charge.rb +43 -0
- data/lib/shopify_client/api/script_tag.rb +35 -0
- data/lib/shopify_client/api/shop.rb +16 -0
- data/lib/shopify_client/api/smart_collection.rb +22 -0
- data/lib/shopify_client/api/webhook.rb +34 -0
- data/lib/shopify_client/base.rb +57 -0
- data/lib/shopify_client/client.rb +91 -0
- data/lib/shopify_client/custom_collection.rb +28 -0
- data/lib/shopify_client/error.rb +13 -0
- data/lib/shopify_client/error/client_error.rb +23 -0
- data/lib/shopify_client/error/server_error.rb +15 -0
- data/lib/shopify_client/image.rb +13 -0
- data/lib/shopify_client/order.rb +29 -0
- data/lib/shopify_client/product.rb +22 -0
- data/lib/shopify_client/recurring_application_charge.rb +20 -0
- data/lib/shopify_client/request/content_type.rb +20 -0
- data/lib/shopify_client/response/parse_json.rb +22 -0
- data/lib/shopify_client/response/raise_error.rb +23 -0
- data/lib/shopify_client/script_tag.rb +19 -0
- data/lib/shopify_client/shop.rb +22 -0
- data/lib/shopify_client/smart_collection.rb +28 -0
- data/lib/shopify_client/version.rb +3 -0
- data/lib/shopify_client/webhook.rb +21 -0
- data/shopify_client.gemspec +28 -0
- data/test/fixtures/custom_collection.json +18 -0
- data/test/fixtures/custom_collections.json +19 -0
- data/test/fixtures/order.json +274 -0
- data/test/fixtures/orders.json +276 -0
- data/test/fixtures/product.json +140 -0
- data/test/fixtures/products.json +170 -0
- data/test/fixtures/recurring_application_charge.json +18 -0
- data/test/fixtures/recurring_application_charges.json +34 -0
- data/test/fixtures/script_tag.json +9 -0
- data/test/fixtures/script_tags.json +18 -0
- data/test/fixtures/shop.json +37 -0
- data/test/fixtures/smart_collection.json +25 -0
- data/test/fixtures/smart_collections.json +26 -0
- data/test/fixtures/webhook.json +10 -0
- data/test/fixtures/webhooks.json +20 -0
- data/test/shopify_client/api/custom_collection_spec.rb +54 -0
- data/test/shopify_client/api/order_spec.rb +68 -0
- data/test/shopify_client/api/product_spec.rb +66 -0
- data/test/shopify_client/api/recurring_application_charge_spec.rb +138 -0
- data/test/shopify_client/api/script_tag_spec.rb +109 -0
- data/test/shopify_client/api/shop_spec.rb +30 -0
- data/test/shopify_client/api/smart_collection_spec.rb +54 -0
- data/test/shopify_client/api/webhook_spec.rb +109 -0
- data/test/shopify_client/base_spec.rb +12 -0
- data/test/shopify_client/client_spec.rb +12 -0
- data/test/shopify_client/custom_collection_spec.rb +41 -0
- data/test/shopify_client/error/client_error_spec.rb +19 -0
- data/test/shopify_client/error/server_error_spec.rb +20 -0
- data/test/shopify_client/order_spec.rb +30 -0
- data/test/shopify_client/product_spec.rb +21 -0
- data/test/shopify_client/recurring_application_charge_spec.rb +20 -0
- data/test/shopify_client/script_tag_spec.rb +22 -0
- data/test/shopify_client/shop_spec.rb +14 -0
- data/test/shopify_client/smart_collection_spec.rb +41 -0
- data/test/shopify_client/webhook_spec.rb +22 -0
- data/test/shopify_client_spec.rb +10 -0
- data/test/test_helper.rb +13 -0
- metadata +235 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"recurring_application_charge": {
|
3
|
+
"activated_on": null,
|
4
|
+
"billing_on": "2013-07-17T00:00:00+00:00",
|
5
|
+
"cancelled_on": null,
|
6
|
+
"created_at": "2013-07-18T13:55:43-04:00",
|
7
|
+
"id": 455696195,
|
8
|
+
"name": "Super Mega Plan",
|
9
|
+
"price": "15.00",
|
10
|
+
"return_url": "http://yourapp.com",
|
11
|
+
"status": "pending",
|
12
|
+
"test": null,
|
13
|
+
"trial_days": 0,
|
14
|
+
"trial_ends_on": null,
|
15
|
+
"updated_at": "2013-07-18T13:55:43-04:00",
|
16
|
+
"confirmation_url": "http://apple.myshopify.com/admin/charges/confirm_recurring_application_charge?id=455696195&signature=BAhpBENfKRs%3D--a911ece9470850c96f6c7735c684b8a3f6869594"
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"recurring_application_charges": [
|
3
|
+
{
|
4
|
+
"activated_on": null,
|
5
|
+
"billing_on": "2013-07-17T00:00:00+00:00",
|
6
|
+
"cancelled_on": null,
|
7
|
+
"created_at": "2013-07-18T13:55:43-04:00",
|
8
|
+
"id": 455696195,
|
9
|
+
"name": "Super Mega Plan",
|
10
|
+
"price": "15.00",
|
11
|
+
"return_url": "http://yourapp.com",
|
12
|
+
"status": "accepted",
|
13
|
+
"test": null,
|
14
|
+
"trial_days": 0,
|
15
|
+
"trial_ends_on": null,
|
16
|
+
"updated_at": "2013-07-18T13:56:57-04:00"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"activated_on": "2013-07-17T00:00:00+00:00",
|
20
|
+
"billing_on": "2013-07-17T00:00:00+00:00",
|
21
|
+
"cancelled_on": null,
|
22
|
+
"created_at": "2013-07-18T13:55:43-04:00",
|
23
|
+
"id": 455696196,
|
24
|
+
"name": "Super Mega Plan",
|
25
|
+
"price": "15.00",
|
26
|
+
"return_url": "http://yourapp.com",
|
27
|
+
"status": "active",
|
28
|
+
"test": null,
|
29
|
+
"trial_days": 0,
|
30
|
+
"trial_ends_on": null,
|
31
|
+
"updated_at": "2013-07-18T13:56:57-04:00"
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"script_tags": [
|
3
|
+
{
|
4
|
+
"created_at": "2013-08-01T11:13:08-04:00",
|
5
|
+
"event": "onload",
|
6
|
+
"id": 421379493,
|
7
|
+
"src": "http://js-aplenty.com/bar.js",
|
8
|
+
"updated_at": "2013-08-01T11:13:08-04:00"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"created_at": "2013-08-01T11:13:08-04:00",
|
12
|
+
"event": "onload",
|
13
|
+
"id": 596726825,
|
14
|
+
"src": "http://js-aplenty.com/foo.js",
|
15
|
+
"updated_at": "2013-08-01T11:13:08-04:00"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"shop": {
|
3
|
+
"address1": "1 Infinite Loop",
|
4
|
+
"city": "Cupertino",
|
5
|
+
"country": "US",
|
6
|
+
"created_at": "2007-12-31T19:00:00-05:00",
|
7
|
+
"customer_email": "customers@apple.com",
|
8
|
+
"domain": "shop.apple.com",
|
9
|
+
"email": "steve@apple.com",
|
10
|
+
"id": 690933842,
|
11
|
+
"latitude": "45.45",
|
12
|
+
"longitude": "-75.43",
|
13
|
+
"name": "Apple Computers",
|
14
|
+
"phone": "1231231234",
|
15
|
+
"province": "California",
|
16
|
+
"public": null,
|
17
|
+
"source": null,
|
18
|
+
"zip": "95014",
|
19
|
+
"country_code": "US",
|
20
|
+
"country_name": "United States",
|
21
|
+
"currency": "USD",
|
22
|
+
"timezone": "(GMT-05:00) Eastern Time (US & Canada)",
|
23
|
+
"shop_owner": "Steve Jobs",
|
24
|
+
"money_format": "$ ",
|
25
|
+
"money_with_currency_format": "$ USD",
|
26
|
+
"province_code": "CA",
|
27
|
+
"taxes_included": null,
|
28
|
+
"tax_shipping": null,
|
29
|
+
"plan_display_name": "enterprise",
|
30
|
+
"plan_name": "enterprise",
|
31
|
+
"myshopify_domain": "apple.myshopify.com",
|
32
|
+
"google_apps_domain": null,
|
33
|
+
"google_apps_login_enabled": null,
|
34
|
+
"money_in_emails_format": "$",
|
35
|
+
"money_with_currency_in_emails_format": "$ USD"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"smart_collection": {
|
3
|
+
"body_html": "<p>The best selling ipod ever</p>",
|
4
|
+
"handle": "smart-ipods",
|
5
|
+
"id": 482865238,
|
6
|
+
"products_count": 0,
|
7
|
+
"published_at": "2008-02-01T19:00:00-05:00",
|
8
|
+
"published_scope": "global",
|
9
|
+
"sort_order": "manual",
|
10
|
+
"template_suffix": null,
|
11
|
+
"title": "Smart iPods",
|
12
|
+
"updated_at": "2008-02-01T19:00:00-05:00",
|
13
|
+
"rules": [
|
14
|
+
{
|
15
|
+
"column": "type",
|
16
|
+
"relation": "equals",
|
17
|
+
"condition": "Cult Products"
|
18
|
+
}
|
19
|
+
],
|
20
|
+
"image": {
|
21
|
+
"created_at": "2013-07-18T13:55:42-04:00",
|
22
|
+
"src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/collections/ipod_nano_8gb.jpg?0"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"smart_collections": [
|
3
|
+
{
|
4
|
+
"body_html": "<p>The best selling ipod ever</p>",
|
5
|
+
"handle": "smart-ipods",
|
6
|
+
"id": 482865238,
|
7
|
+
"published_at": "2008-02-01T19:00:00-05:00",
|
8
|
+
"published_scope": "global",
|
9
|
+
"sort_order": "manual",
|
10
|
+
"template_suffix": null,
|
11
|
+
"title": "Smart iPods",
|
12
|
+
"updated_at": "2008-02-01T19:00:00-05:00",
|
13
|
+
"rules": [
|
14
|
+
{
|
15
|
+
"column": "type",
|
16
|
+
"relation": "equals",
|
17
|
+
"condition": "Cult Products"
|
18
|
+
}
|
19
|
+
],
|
20
|
+
"image": {
|
21
|
+
"created_at": "2013-07-18T13:55:42-04:00",
|
22
|
+
"src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/collections/ipod_nano_8gb.jpg?0"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"webhooks": [
|
3
|
+
{
|
4
|
+
"address": "http://apple.com",
|
5
|
+
"created_at": "2013-07-18T13:55:43-04:00",
|
6
|
+
"format": "json",
|
7
|
+
"id": 4759306,
|
8
|
+
"topic": "orders/create",
|
9
|
+
"updated_at": "2013-07-18T13:55:43-04:00"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"address": "http://apple.com/uninstall",
|
13
|
+
"created_at": "2013-07-18T13:55:43-04:00",
|
14
|
+
"format": "json",
|
15
|
+
"id": 901431826,
|
16
|
+
"topic": "app/uninstalled",
|
17
|
+
"updated_at": "2013-07-18T13:55:43-04:00"
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
describe ShopifyClient::API::CustomCollection do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@client = ShopifyClient.new("example.myshopify.com", "token")
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#custom_collections" do
|
8
|
+
it "requests all custom collections" do
|
9
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/custom_collections.json").
|
10
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
11
|
+
to_return(status: 200, body: '')
|
12
|
+
|
13
|
+
@client.custom_collections
|
14
|
+
|
15
|
+
assert_requested stubbed
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an ShopifyClient::CustomCollection array" do
|
19
|
+
stub_request(:get, "https://example.myshopify.com/admin/custom_collections.json").
|
20
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
21
|
+
to_return(status: 200, body: fixture('custom_collections.json'))
|
22
|
+
|
23
|
+
custom_collections = @client.custom_collections
|
24
|
+
|
25
|
+
custom_collections.size.must_equal 1
|
26
|
+
custom_collections.first.must_be_instance_of ShopifyClient::CustomCollection
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#custom_collection" do
|
31
|
+
it "requests an specific custom collection" do
|
32
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/custom_collections/123.json").
|
33
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
34
|
+
to_return(status: 200, body: '')
|
35
|
+
|
36
|
+
@client.custom_collection(123)
|
37
|
+
|
38
|
+
assert_requested stubbed
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns a ShopifyClient::CustomCollection with data" do
|
42
|
+
stub_request(:get, "https://example.myshopify.com/admin/custom_collections/123.json").
|
43
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
44
|
+
to_return(status: 200, body: fixture('custom_collection.json'))
|
45
|
+
|
46
|
+
custom_collection = @client.custom_collection(123)
|
47
|
+
|
48
|
+
custom_collection.must_be_instance_of ShopifyClient::CustomCollection
|
49
|
+
custom_collection.handle.must_equal 'ipods'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
describe ShopifyClient::API::Order do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@client = ShopifyClient.new("example.myshopify.com", "token")
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#orders" do
|
8
|
+
it "requests all orders" do
|
9
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/orders.json").
|
10
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
11
|
+
to_return(status: 200, body: '')
|
12
|
+
|
13
|
+
@client.orders
|
14
|
+
|
15
|
+
assert_requested stubbed
|
16
|
+
end
|
17
|
+
|
18
|
+
it "filters by financial_status" do
|
19
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/orders.json?financial_status=authorized").
|
20
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
21
|
+
to_return(status: 200, body: '')
|
22
|
+
|
23
|
+
@client.orders(:financial_status => :authorized)
|
24
|
+
|
25
|
+
assert_requested stubbed
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
it "returns an ShopifyClient::Order array" do
|
30
|
+
stub_request(:get, "https://example.myshopify.com/admin/orders.json").
|
31
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
32
|
+
to_return(status: 200, body: fixture('orders.json'))
|
33
|
+
|
34
|
+
orders = @client.orders
|
35
|
+
|
36
|
+
orders.size.must_equal 1
|
37
|
+
orders.first.must_be_instance_of ShopifyClient::Order
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#order" do
|
43
|
+
it "requests an specific order" do
|
44
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/orders/123.json").
|
45
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
46
|
+
to_return(status: 200, body: '')
|
47
|
+
|
48
|
+
@client.order(123)
|
49
|
+
|
50
|
+
assert_requested stubbed
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns a ShopifyClient::Order" do
|
54
|
+
stub_request(:get, "https://example.myshopify.com/admin/orders/123.json").
|
55
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
56
|
+
to_return(status: 200, body: fixture('order.json'))
|
57
|
+
|
58
|
+
order = @client.order(123)
|
59
|
+
|
60
|
+
order.must_be_instance_of ShopifyClient::Order
|
61
|
+
order.cart_token.must_equal "68778783ad298f1c80c3bafcddeea02f"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
describe ShopifyClient::API::Product do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@client = ShopifyClient.new("example.myshopify.com", "token")
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#products" do
|
8
|
+
it "requests all products" do
|
9
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/products.json").
|
10
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
11
|
+
to_return(status: 200, body: '')
|
12
|
+
|
13
|
+
@client.products
|
14
|
+
|
15
|
+
assert_requested stubbed
|
16
|
+
end
|
17
|
+
|
18
|
+
it "filters by collection_id" do
|
19
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/products.json?collection_id=456").
|
20
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
21
|
+
to_return(status: 200, body: '')
|
22
|
+
|
23
|
+
@client.products(:collection_id => 456)
|
24
|
+
|
25
|
+
assert_requested stubbed
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
it "returns an ShopifyClient::Product array" do
|
30
|
+
stub_request(:get, "https://example.myshopify.com/admin/products.json").
|
31
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
32
|
+
to_return(status: 200, body: fixture('products.json'))
|
33
|
+
|
34
|
+
products = @client.products
|
35
|
+
|
36
|
+
products.size.must_equal 2
|
37
|
+
products.first.must_be_instance_of ShopifyClient::Product
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#product" do
|
43
|
+
it "requests an specific product" do
|
44
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/products/123.json").
|
45
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
46
|
+
to_return(status: 200, body: '')
|
47
|
+
|
48
|
+
@client.product(123)
|
49
|
+
|
50
|
+
assert_requested stubbed
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns a ShopifyClient::Product" do
|
54
|
+
stub_request(:get, "https://example.myshopify.com/admin/products/123.json").
|
55
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
56
|
+
to_return(status: 200, body: fixture('product.json'))
|
57
|
+
|
58
|
+
product = @client.product(123)
|
59
|
+
|
60
|
+
product.must_be_instance_of ShopifyClient::Product
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
describe ShopifyClient::API::RecurringApplicationCharge do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@client = ShopifyClient.new("example.myshopify.com", "token")
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#recurring_application_charges" do
|
8
|
+
it "requests all recurring application charges" do
|
9
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/recurring_application_charges.json").
|
10
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
11
|
+
to_return(status: 200, body: '')
|
12
|
+
|
13
|
+
@client.recurring_application_charges
|
14
|
+
|
15
|
+
assert_requested stubbed
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an ShopifyClient::RecurringApplicationCharge array" do
|
19
|
+
stub_request(:get, "https://example.myshopify.com/admin/recurring_application_charges.json").
|
20
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
21
|
+
to_return(status: 200, body: fixture('recurring_application_charges.json'))
|
22
|
+
|
23
|
+
recurring_application_charges = @client.recurring_application_charges
|
24
|
+
|
25
|
+
recurring_application_charges.size.must_equal 2
|
26
|
+
recurring_application_charges.first.must_be_instance_of ShopifyClient::RecurringApplicationCharge
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#current_recurring_application_charge" do
|
31
|
+
it "returns an 'active' charge" do
|
32
|
+
stub_request(:get, "https://example.myshopify.com/admin/recurring_application_charges.json").
|
33
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
34
|
+
to_return(status: 200, body: fixture('recurring_application_charges.json'))
|
35
|
+
|
36
|
+
current = @client.current_recurring_application_charge
|
37
|
+
|
38
|
+
current.status.must_equal 'active'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#recurring_application_charge" do
|
43
|
+
it "requests an specific recurring application charge" do
|
44
|
+
stubbed = stub_request(:get, "https://example.myshopify.com/admin/recurring_application_charges/123.json").
|
45
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
46
|
+
to_return(status: 200, body: '')
|
47
|
+
|
48
|
+
@client.recurring_application_charge(123)
|
49
|
+
|
50
|
+
assert_requested stubbed
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns a ShopifyClient::RecurringApplicationCharge" do
|
54
|
+
stub_request(:get, "https://example.myshopify.com/admin/recurring_application_charges/123.json").
|
55
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
56
|
+
to_return(status: 200, body: fixture('recurring_application_charge.json'))
|
57
|
+
|
58
|
+
recurring_application_charge = @client.recurring_application_charge(123)
|
59
|
+
|
60
|
+
recurring_application_charge.must_be_instance_of ShopifyClient::RecurringApplicationCharge
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#create_recurring_application_charge" do
|
65
|
+
before do
|
66
|
+
@attributes = { name: "Super Duper Plan", price: 10.0, return_url: "http://super-duper.shopifyapps.com" }
|
67
|
+
@request = stub_request(:post, "https://example.myshopify.com/admin/recurring_application_charges.json").
|
68
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" },
|
69
|
+
body: { recurring_application_charge: @attributes }).
|
70
|
+
to_return(status: 200, body: fixture('recurring_application_charge.json'))
|
71
|
+
end
|
72
|
+
|
73
|
+
it "posts with recurring_application_charge params" do
|
74
|
+
@client.create_recurring_application_charge(@attributes)
|
75
|
+
|
76
|
+
assert_requested @request
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns an initialized RecurringApplicationCharge" do
|
80
|
+
recurring_application_charge = @client.create_recurring_application_charge(@attributes)
|
81
|
+
|
82
|
+
recurring_application_charge.must_be_instance_of ShopifyClient::RecurringApplicationCharge
|
83
|
+
recurring_application_charge.id.must_equal 455696195
|
84
|
+
end
|
85
|
+
|
86
|
+
it "raises an error if 422 returned" do
|
87
|
+
@request = stub_request(:post, "https://example.myshopify.com/admin/recurring_application_charges.json").
|
88
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
89
|
+
to_return(status: 422 , body: '{"error": "Price must be present"}')
|
90
|
+
|
91
|
+
assert_raises ShopifyClient::Error::ClientError do
|
92
|
+
@client.create_recurring_application_charge({ name: "Super Duper Plan", return_url: "http://super-duper.shopifyapps.com" })
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#activate_recurring_application_charge" do
|
99
|
+
before do
|
100
|
+
@request = stub_request(:post, "https://example.myshopify.com/admin/recurring_application_charges/123/activate.json").
|
101
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
102
|
+
to_return(status: 200)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "posts to activate charge" do
|
106
|
+
@client.activate_recurring_application_charge(123)
|
107
|
+
|
108
|
+
assert_requested @request
|
109
|
+
end
|
110
|
+
|
111
|
+
it "can receive a ShopifyClient::RecurringApplicationCharge object" do
|
112
|
+
@client.activate_recurring_application_charge(ShopifyClient::RecurringApplicationCharge.new(id: 123))
|
113
|
+
|
114
|
+
assert_requested @request
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#cancel_recurring_application_charge" do
|
119
|
+
before do
|
120
|
+
@request = stub_request(:delete, "https://example.myshopify.com/admin/recurring_application_charges/123.json").
|
121
|
+
with(headers: { 'X-Shopify-Access-Token' => "token" }).
|
122
|
+
to_return(status: 200)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "deletes to cancel charge" do
|
126
|
+
@client.cancel_recurring_application_charge(123)
|
127
|
+
|
128
|
+
assert_requested @request
|
129
|
+
end
|
130
|
+
|
131
|
+
it "can receive a ShopifyClient::RecurringApplicationCharge object" do
|
132
|
+
@client.cancel_recurring_application_charge(ShopifyClient::RecurringApplicationCharge.new(id: 123))
|
133
|
+
|
134
|
+
assert_requested @request
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|