shopify_api 4.3.0 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +23 -3
- data/lib/active_resource/connection_ext.rb +4 -26
- data/lib/active_resource/disable_prefix_check.rb +1 -1
- data/lib/shopify_api.rb +7 -1
- data/lib/shopify_api/connection.rb +33 -0
- data/lib/shopify_api/countable.rb +8 -1
- data/lib/shopify_api/resources/application_credit.rb +4 -0
- data/lib/shopify_api/resources/fulfillment_request.rb +15 -0
- data/lib/shopify_api/version.rb +1 -1
- data/test/application_credit_test.rb +35 -0
- data/test/countable_test.rb +12 -0
- data/test/fixtures/application_credit.json +12 -0
- data/test/fixtures/application_credits.json +24 -0
- data/test/fixtures/fulfillment_request.json +28 -0
- data/test/fulfillment_request_test.rb +29 -0
- data/test/refund_test.rb +1 -1
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b71e5318b9970359ed688393a774c332efcfb83b
|
4
|
+
data.tar.gz: fc99b55edc6c8dd8753edfee81d297becac59815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe95b2e5f5747e3f04648b46f626439512cb94722cfeb9d03256a6e5479665d25f64eeb2b31e25202e80dc0f7458b338ebc3599722e9d34def4f4cb32424360d
|
7
|
+
data.tar.gz: 2f5339e68a4670396810a72c20d49c1e4bea4a5a531e3b48950d8386c167a109792c3be9258f4366f5ee187a0cc8765837b673844c23fff7f83232af67c420d7
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Shopify API
|
2
|
+
===========
|
3
|
+
[![Version][gem]][gem_url] [![Build Status](https://travis-ci.org/Shopify/shopify_api.svg?branch=master)](https://travis-ci.org/Shopify/shopify_api)
|
4
|
+
|
5
|
+
[gem]: https://img.shields.io/gem/v/shopify_api.svg
|
6
|
+
[gem_url]: https://rubygems.org/gems/shopify_api
|
7
|
+
|
3
8
|
|
4
9
|
The Shopify API gem allows Ruby developers to programmatically access the admin section of Shopify stores.
|
5
10
|
|
@@ -22,12 +27,27 @@ This gem requires Ruby 2.3.1 as of version 4.3. If you need to use an older Ruby
|
|
22
27
|
|
23
28
|
### Installation
|
24
29
|
|
25
|
-
|
30
|
+
Add `shopify_api` to your `Gemfile`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'shopify_api'
|
34
|
+
```
|
35
|
+
|
36
|
+
Or install via [gem](http://rubygems.org/)
|
26
37
|
|
27
38
|
```bash
|
28
39
|
gem install shopify_api
|
29
40
|
```
|
30
41
|
|
42
|
+
#### Rails 5
|
43
|
+
|
44
|
+
shopify_api is compatible with Rails 5 but since the latest ActiveResource release (4.1) is locked on Rails 4.x, you'll need to use the unreleased master version:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
gem 'shopify_api'
|
48
|
+
gem 'activeresource', github: 'rails/activeresource'
|
49
|
+
```
|
50
|
+
|
31
51
|
### Getting Started
|
32
52
|
|
33
53
|
ShopifyAPI uses ActiveResource to communicate with the REST web service. ActiveResource has to be configured with a fully authorized URL of a particular store first. To obtain that URL you can follow these steps:
|
@@ -1,32 +1,10 @@
|
|
1
|
+
require 'shopify_api/connection'
|
2
|
+
|
1
3
|
module ActiveResource
|
2
4
|
class Connection
|
3
5
|
attr_reader :response
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
@response = super
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module RequestNotification
|
12
|
-
def request(method, path, *arguments)
|
13
|
-
super.tap do |response|
|
14
|
-
notify_about_request(response, arguments)
|
15
|
-
end
|
16
|
-
rescue => e
|
17
|
-
notify_about_request(e.response, arguments) if e.respond_to?(:response)
|
18
|
-
raise
|
19
|
-
end
|
20
|
-
|
21
|
-
def notify_about_request(response, arguments)
|
22
|
-
ActiveSupport::Notifications.instrument("request.active_resource_detailed") do |payload|
|
23
|
-
payload[:response] = response
|
24
|
-
payload[:data] = arguments
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
prepend ResponseCapture
|
30
|
-
prepend RequestNotification
|
7
|
+
prepend ShopifyAPI::Connection::ResponseCapture
|
8
|
+
prepend ShopifyAPI::Connection::RequestNotification
|
31
9
|
end
|
32
10
|
end
|
@@ -12,7 +12,7 @@ module DisablePrefixCheck
|
|
12
12
|
|
13
13
|
init_prefix_explicit resource_type, resource_id
|
14
14
|
|
15
|
-
define_singleton_method :prefix do |options|
|
15
|
+
define_singleton_method :prefix do |options = {}|
|
16
16
|
resource_type = options[resource] if flexible
|
17
17
|
|
18
18
|
options[resource_id].nil? ? "/admin/" : "/admin/#{resource_type}/#{options[resource_id]}/"
|
data/lib/shopify_api.rb
CHANGED
@@ -4,7 +4,6 @@ require 'active_resource'
|
|
4
4
|
require 'active_support/core_ext/class/attribute_accessors'
|
5
5
|
require 'digest/md5'
|
6
6
|
require 'base64'
|
7
|
-
require 'active_resource/connection_ext'
|
8
7
|
require 'active_resource/detailed_log_subscriber'
|
9
8
|
require 'shopify_api/limits'
|
10
9
|
require 'shopify_api/json_format'
|
@@ -22,3 +21,10 @@ require 'shopify_api/metafields'
|
|
22
21
|
require 'shopify_api/countable'
|
23
22
|
require 'shopify_api/resources'
|
24
23
|
require 'shopify_api/session'
|
24
|
+
require 'shopify_api/connection'
|
25
|
+
|
26
|
+
if ShopifyAPI::Base.respond_to?(:connection_class)
|
27
|
+
ShopifyAPI::Base.connection_class = ShopifyAPI::Connection
|
28
|
+
else
|
29
|
+
require 'active_resource/connection_ext'
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ShopifyAPI
|
2
|
+
class Connection < ActiveResource::Connection
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
module ResponseCapture
|
6
|
+
def handle_response(response)
|
7
|
+
@response = super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
include ResponseCapture
|
12
|
+
|
13
|
+
module RequestNotification
|
14
|
+
def request(method, path, *arguments)
|
15
|
+
super.tap do |response|
|
16
|
+
notify_about_request(response, arguments)
|
17
|
+
end
|
18
|
+
rescue => e
|
19
|
+
notify_about_request(e.response, arguments) if e.respond_to?(:response)
|
20
|
+
raise
|
21
|
+
end
|
22
|
+
|
23
|
+
def notify_about_request(response, arguments)
|
24
|
+
ActiveSupport::Notifications.instrument("request.active_resource_detailed") do |payload|
|
25
|
+
payload[:response] = response
|
26
|
+
payload[:data] = arguments
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
include RequestNotification
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ShopifyAPI
|
2
|
+
class FulfillmentRequest < Base
|
3
|
+
init_prefix :order
|
4
|
+
|
5
|
+
def order_id
|
6
|
+
@prefix_options[:order_id]
|
7
|
+
end
|
8
|
+
|
9
|
+
def mark_as_failed
|
10
|
+
load_attributes_from_response(
|
11
|
+
put(:mark_as_failed, message: failure_message)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/shopify_api/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ApplicationCreditTest < Test::Unit::TestCase
|
4
|
+
def test_application_credit_create
|
5
|
+
fake "application_credits", method: :post, status: 201, body: load_fixture('application_credit')
|
6
|
+
|
7
|
+
credit = ShopifyAPI::ApplicationCredit.create(
|
8
|
+
description: "refund for application charge",
|
9
|
+
amount: 5.00,
|
10
|
+
api_client_id: 861378,
|
11
|
+
shop_id: 487168
|
12
|
+
)
|
13
|
+
|
14
|
+
assert_equal 'refund for application charge', credit.description
|
15
|
+
assert_equal '5.00', credit.amount
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_application_credit
|
19
|
+
fake "application_credits/803742", method: :get, status: 201, body: load_fixture('application_credit')
|
20
|
+
|
21
|
+
credit = ShopifyAPI::ApplicationCredit.find(803742)
|
22
|
+
|
23
|
+
assert_equal 'refund for application charge', credit.description
|
24
|
+
assert_equal '5.00', credit.amount
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_list_application_credits
|
28
|
+
fake "application_credits", method: :get, status: 201, body: load_fixture('application_credits')
|
29
|
+
|
30
|
+
credit = ShopifyAPI::ApplicationCredit.find(:all)
|
31
|
+
|
32
|
+
assert_equal 2, credit.size
|
33
|
+
assert_equal '10.00', credit.last.amount
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"application_credit": {
|
3
|
+
"id": 803742,
|
4
|
+
"api_client_id": 861378,
|
5
|
+
"partner_id": 549861,
|
6
|
+
"shop_id": 487168,
|
7
|
+
"amount": "5.00",
|
8
|
+
"description": "refund for application charge",
|
9
|
+
"created_at": "2015-07-10T15:03:51+10:00",
|
10
|
+
"updated_at": "2015-07-10T15:03:51+10:00"
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"application_charges": [
|
3
|
+
{
|
4
|
+
"id": 803742,
|
5
|
+
"api_client_id": 861378,
|
6
|
+
"shop_id": 487168,
|
7
|
+
"amount": "5.00",
|
8
|
+
"billing_status": "pending",
|
9
|
+
"description": "refund for application charge",
|
10
|
+
"created_at": "2015-07-10T15:03:51+10:00",
|
11
|
+
"updated_at": "2015-07-10T15:03:51+10:00"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"id": 803743,
|
15
|
+
"api_client_id": 861378,
|
16
|
+
"shop_id": 487168,
|
17
|
+
"amount": "10.00",
|
18
|
+
"billing_status": "pending",
|
19
|
+
"description": "refund for application charge",
|
20
|
+
"created_at": "2015-07-10T15:03:51+10:00",
|
21
|
+
"updated_at": "2015-07-10T15:03:51+10:00"
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"fulfillment_request":{
|
3
|
+
"id":695890229,
|
4
|
+
"shop_id":690933842,
|
5
|
+
"order_id":450789469,
|
6
|
+
"fulfillment_service_id":755357713,
|
7
|
+
"service_handle":"shipwire-app",
|
8
|
+
"delivered_at":null,
|
9
|
+
"failed_at":null,
|
10
|
+
"failure_message":null,
|
11
|
+
"receipt":null,
|
12
|
+
"is_not_deleted":true,
|
13
|
+
"deleted_at":null,
|
14
|
+
"created_at":"2016-07-12T11:23:42-04:00",
|
15
|
+
"updated_at":"2016-07-12T11:23:42-04:00",
|
16
|
+
"fulfillment_request_line_items":[
|
17
|
+
{
|
18
|
+
"id":6,
|
19
|
+
"shop_id":690933842,
|
20
|
+
"fulfillment_request_id":695890229,
|
21
|
+
"line_item_id":466157049,
|
22
|
+
"quantity":1,
|
23
|
+
"created_at":"2016-07-12T11:23:54-04:00",
|
24
|
+
"updated_at":"2016-07-12T11:23:54-04:00"
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FulFillmentRequestTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
fake "orders/450789469/fulfillment_requests/695890229", method: :get, body: load_fixture('fulfillment_request')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "#mark_as_failed" do
|
9
|
+
should "be able to mark_as_failed a fulfillment request" do
|
10
|
+
fulfillment_request = ShopifyAPI::FulfillmentRequest.find(255858046, params: { order_id: 450789469 })
|
11
|
+
|
12
|
+
cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment_request'))
|
13
|
+
cancelled['failure_message'] = 'failure reason'
|
14
|
+
fake "orders/450789469/fulfillment_requests/695890229/mark_as_failed", method: :put, body: ActiveSupport::JSON.encode(cancelled)
|
15
|
+
|
16
|
+
assert fulfillment_request.failure_message.blank?
|
17
|
+
assert fulfillment_request.mark_as_failed
|
18
|
+
assert_equal 'failure reason', fulfillment_request.failure_message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "#find" do
|
23
|
+
should "be able to find fulfillment request" do
|
24
|
+
fulfillment_request = ShopifyAPI::FulfillmentRequest.find(255858046, params: { order_id: 450789469 })
|
25
|
+
assert_equal 695890229, fulfillment_request.id
|
26
|
+
assert_equal 450789469, fulfillment_request.order_id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/refund_test.rb
CHANGED
@@ -9,7 +9,7 @@ class RefundTest < Test::Unit::TestCase
|
|
9
9
|
:restock => true,
|
10
10
|
:note => "wrong size",
|
11
11
|
:shipping => { :full_refund => true },
|
12
|
-
:refund_line_items => [{ :
|
12
|
+
:refund_line_items => [{ :line_item_id => 518995019, :quantity => 1 }]
|
13
13
|
)
|
14
14
|
assert_equal 703073504, refund.refund_line_items.first.line_item_id
|
15
15
|
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.3.
|
4
|
+
version: 4.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/active_resource/json_errors.rb
|
131
131
|
- lib/active_resource/to_query.rb
|
132
132
|
- lib/shopify_api.rb
|
133
|
+
- lib/shopify_api/connection.rb
|
133
134
|
- lib/shopify_api/countable.rb
|
134
135
|
- lib/shopify_api/events.rb
|
135
136
|
- lib/shopify_api/json_format.rb
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- lib/shopify_api/resources/address.rb
|
141
142
|
- lib/shopify_api/resources/announcement.rb
|
142
143
|
- lib/shopify_api/resources/application_charge.rb
|
144
|
+
- lib/shopify_api/resources/application_credit.rb
|
143
145
|
- lib/shopify_api/resources/article.rb
|
144
146
|
- lib/shopify_api/resources/asset.rb
|
145
147
|
- lib/shopify_api/resources/base.rb
|
@@ -159,6 +161,7 @@ files:
|
|
159
161
|
- lib/shopify_api/resources/event.rb
|
160
162
|
- lib/shopify_api/resources/fulfillment.rb
|
161
163
|
- lib/shopify_api/resources/fulfillment_event.rb
|
164
|
+
- lib/shopify_api/resources/fulfillment_request.rb
|
162
165
|
- lib/shopify_api/resources/fulfillment_service.rb
|
163
166
|
- lib/shopify_api/resources/gift_card.rb
|
164
167
|
- lib/shopify_api/resources/image.rb
|
@@ -201,6 +204,7 @@ files:
|
|
201
204
|
- test/access_token_test.rb
|
202
205
|
- test/active_resource/json_errors_test.rb
|
203
206
|
- test/application_charge_test.rb
|
207
|
+
- test/application_credit_test.rb
|
204
208
|
- test/article_test.rb
|
205
209
|
- test/asset_test.rb
|
206
210
|
- test/base_test.rb
|
@@ -209,6 +213,7 @@ files:
|
|
209
213
|
- test/cart_test.rb
|
210
214
|
- test/checkouts_test.rb
|
211
215
|
- test/collect_test.rb
|
216
|
+
- test/countable_test.rb
|
212
217
|
- test/custom_collection_test.rb
|
213
218
|
- test/customer_saved_search_test.rb
|
214
219
|
- test/customer_test.rb
|
@@ -217,6 +222,8 @@ files:
|
|
217
222
|
- test/fixtures/access_token_delegate.json
|
218
223
|
- test/fixtures/application_charge.json
|
219
224
|
- test/fixtures/application_charges.json
|
225
|
+
- test/fixtures/application_credit.json
|
226
|
+
- test/fixtures/application_credits.json
|
220
227
|
- test/fixtures/article.json
|
221
228
|
- test/fixtures/articles.json
|
222
229
|
- test/fixtures/asset.json
|
@@ -240,6 +247,7 @@ files:
|
|
240
247
|
- test/fixtures/events.json
|
241
248
|
- test/fixtures/fulfillment.json
|
242
249
|
- test/fixtures/fulfillment_event.json
|
250
|
+
- test/fixtures/fulfillment_request.json
|
243
251
|
- test/fixtures/fulfillment_service.json
|
244
252
|
- test/fixtures/gift_card.json
|
245
253
|
- test/fixtures/gift_card_disabled.json
|
@@ -276,6 +284,7 @@ files:
|
|
276
284
|
- test/fixtures/webhook.json
|
277
285
|
- test/fixtures/webhooks.json
|
278
286
|
- test/fulfillment_event_test.rb
|
287
|
+
- test/fulfillment_request_test.rb
|
279
288
|
- test/fulfillment_service_test.rb
|
280
289
|
- test/fulfillment_test.rb
|
281
290
|
- test/gift_card_test.rb
|
@@ -323,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
323
332
|
version: '0'
|
324
333
|
requirements: []
|
325
334
|
rubyforge_project:
|
326
|
-
rubygems_version: 2.
|
335
|
+
rubygems_version: 2.5.1
|
327
336
|
signing_key:
|
328
337
|
specification_version: 4
|
329
338
|
summary: ShopifyAPI is a lightweight gem for accessing the Shopify admin REST web
|