shopify_api 4.9.0 → 5.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/probots.yml +2 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +0 -4
- data/CHANGELOG +63 -0
- data/README.md +36 -14
- data/lib/active_resource/detailed_log_subscriber.rb +25 -2
- data/lib/shopify_api/connection.rb +5 -3
- data/lib/shopify_api/limits.rb +1 -2
- data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
- data/lib/shopify_api/resources/access_scope.rb +5 -0
- data/lib/shopify_api/resources/api_permission.rb +9 -0
- data/lib/shopify_api/resources/asset.rb +8 -8
- data/lib/shopify_api/resources/billing_address.rb +1 -1
- data/lib/shopify_api/resources/checkout.rb +27 -1
- data/lib/shopify_api/resources/collection_publication.rb +10 -0
- data/lib/shopify_api/resources/currency.rb +6 -0
- data/lib/shopify_api/resources/custom_collection.rb +3 -3
- data/lib/shopify_api/resources/{customer_invite_message.rb → customer_invite.rb} +0 -0
- data/lib/shopify_api/resources/graphql.rb +22 -0
- data/lib/shopify_api/resources/image.rb +2 -2
- data/lib/shopify_api/resources/inventory_item.rb +6 -0
- data/lib/shopify_api/resources/inventory_level.rb +55 -0
- data/lib/shopify_api/resources/line_item.rb +9 -1
- data/lib/shopify_api/resources/location.rb +4 -0
- data/lib/shopify_api/resources/o_auth.rb +8 -0
- data/lib/shopify_api/resources/order.rb +16 -4
- data/lib/shopify_api/resources/payment.rb +7 -0
- data/lib/shopify_api/resources/ping.rb +3 -0
- data/lib/shopify_api/resources/ping/conversation.rb +42 -0
- data/lib/shopify_api/resources/ping/delivery_confirmation_details.rb +10 -0
- data/lib/shopify_api/resources/ping/message.rb +8 -0
- data/lib/shopify_api/resources/product.rb +4 -4
- data/lib/shopify_api/resources/product_publication.rb +10 -0
- data/lib/shopify_api/resources/publication.rb +5 -0
- data/lib/shopify_api/resources/shipping_line.rb +1 -1
- data/lib/shopify_api/resources/shipping_rate.rb +7 -0
- data/lib/shopify_api/resources/shop.rb +4 -4
- data/lib/shopify_api/resources/smart_collection.rb +6 -2
- data/lib/shopify_api/resources/tender_transaction.rb +6 -0
- data/lib/shopify_api/session.rb +1 -1
- data/lib/shopify_api/version.rb +1 -1
- data/service.yml +8 -0
- data/shopify_api.gemspec +4 -1
- data/test/abandoned_checkouts_test.rb +29 -0
- data/test/api_permission_test.rb +9 -0
- data/test/checkouts_test.rb +72 -4
- data/test/collection_publication_test.rb +40 -0
- data/test/currency_test.rb +21 -0
- data/test/detailed_log_subscriber_test.rb +19 -1
- data/test/fixtures/abandoned_checkout.json +184 -0
- data/test/fixtures/abandoned_checkouts.json +186 -0
- data/test/fixtures/checkout.json +160 -0
- data/test/fixtures/checkouts.json +25 -49
- data/test/fixtures/collection_publication.json +11 -0
- data/test/fixtures/collection_publications.json +13 -0
- data/test/fixtures/currencies.json +25 -0
- data/test/fixtures/inventory_level.json +7 -0
- data/test/fixtures/inventory_levels.json +24 -0
- data/test/fixtures/order_with_properties.json +373 -0
- data/test/fixtures/payment.json +7 -0
- data/test/fixtures/payments.json +9 -0
- data/test/fixtures/ping/conversation.json +1 -0
- data/test/fixtures/ping/failed_delivery_confirmation.json +1 -0
- data/test/fixtures/ping/message.json +1 -0
- data/test/fixtures/ping/successful_delivery_confirmation.json +1 -0
- data/test/fixtures/product_publication.json +11 -0
- data/test/fixtures/product_publications.json +13 -0
- data/test/fixtures/publications.json +9 -0
- data/test/fixtures/shipping_rates.json +12 -0
- data/test/fixtures/smart_collection_products.json +155 -0
- data/test/fixtures/tender_transactions.json +52 -0
- data/test/inventory_level_test.rb +59 -0
- data/test/location_test.rb +14 -0
- data/test/order_test.rb +29 -1
- data/test/payment_test.rb +19 -0
- data/test/ping/conversation_test.rb +71 -0
- data/test/ping/message_test.rb +23 -0
- data/test/product_publication_test.rb +40 -0
- data/test/publication_test.rb +12 -0
- data/test/session_test.rb +11 -11
- data/test/shipping_rate_test.rb +17 -0
- data/test/smart_collection_test.rb +25 -0
- data/test/tender_transaction_test.rb +18 -0
- data/test/test_helper.rb +8 -5
- data/test/variant_test.rb +4 -1
- metadata +102 -10
- data/lib/shopify_api/resources/discount.rb +0 -11
- data/test/discount_test.rb +0 -52
- data/test/fixtures/discount.json +0 -17
- data/test/fixtures/discount_disabled.json +0 -17
- data/test/fixtures/discounts.json +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63ec95eea11639a4bb5808aca547e3bf8cb26fb1d3cb1c7576949d99670932fe
|
4
|
+
data.tar.gz: f0d6932da38d82ae6685006ff7683f4a6767f343ca344fbced06fdbfdb9cb51a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a5f47b30dc2761fcd4fe64592f0bd8c75e97e894be120b995cd2046e7e6f912e417a48d32f6c76630ead5b9e7ebf8b8e8f8fba293dbe71d74c7c884d028b103
|
7
|
+
data.tar.gz: 32c775a711e06c294ac92012bc8b15f481598f369615130629ef51343ba81fd6529f33b99fdf8c0180e7ccd14e9f0394aab0b4309a40a2e06c35140a348c2567
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @shopify/app-partner-dev-tools-education
|
data/.github/probots.yml
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -2,7 +2,6 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
- '2.0'
|
6
5
|
- 2.3.1
|
7
6
|
- 2.4.0-preview1
|
8
7
|
|
@@ -15,9 +14,6 @@ gemfile:
|
|
15
14
|
- Gemfile_ar_master
|
16
15
|
|
17
16
|
matrix:
|
18
|
-
exclude:
|
19
|
-
- rvm: '2.0'
|
20
|
-
gemfile: Gemfile_ar_master
|
21
17
|
fast_finish: true
|
22
18
|
allow_failures:
|
23
19
|
- rvm: 2.4.0-preview1
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,66 @@
|
|
1
|
+
== Version 5.2.4
|
2
|
+
|
3
|
+
* Added `currency` parameter to `ShopifyAPI::Order#capture`. This parameter is required for apps that belong to the
|
4
|
+
multi-currency beta program.
|
5
|
+
|
6
|
+
== Version 5.2.3
|
7
|
+
|
8
|
+
* Update delivery confirmation resource to delivery confirmation details resource.
|
9
|
+
|
10
|
+
== Version 5.2.2
|
11
|
+
|
12
|
+
* Add delivery confirmation endpoint to Ping resources.
|
13
|
+
|
14
|
+
== Version 5.2.1
|
15
|
+
|
16
|
+
* Log warning when Shopify indicates deprecated API call was performed
|
17
|
+
|
18
|
+
== Version 5.2.0
|
19
|
+
|
20
|
+
* Added `ShopifyAPI::Currency` to fetch list of supported currencies on a shop
|
21
|
+
* Added `ShopifyAPI::TenderTransaction` to fetch list of transactions on a shop
|
22
|
+
* Fixed bug with X-Shopify-Checkout-Version on ShopifyAPI::Checkout header being applied to all requests
|
23
|
+
|
24
|
+
== Version 5.1.0
|
25
|
+
|
26
|
+
* Added `ShopifyAPI::Publications`
|
27
|
+
* Added `ShopifyAPI::ProductPublications`
|
28
|
+
* Added `ShopifyAPI::CollectionPublications`
|
29
|
+
* Added support for new collection products endpoint from `ShopifyAPI::Collection#products`
|
30
|
+
|
31
|
+
== Version 5.0.0
|
32
|
+
|
33
|
+
* Breaking change: `ShopifyAPI::Checkout` now maps to the Checkout API, rather than the Abandoned Checkouts API
|
34
|
+
* See the README for more details
|
35
|
+
* Added `ShopifyAPI::AbandonedCheckout`
|
36
|
+
* Added support for X-Shopify-Checkout-Version header on `ShopifyAPI::Checkout`
|
37
|
+
* Added `ShopifyAPI::ShippingRate`
|
38
|
+
* Added `ShopifyAPI::Payment`
|
39
|
+
* Added support for `Checkout::complete` endpoint
|
40
|
+
* Fixed session handling support for Rails 5.2.1
|
41
|
+
|
42
|
+
== Version 4.13.0
|
43
|
+
* Added `ShopifyAPI::ApiPermission` resource for uninstalling an application
|
44
|
+
* Added a deprecation warning to `ShopifyAPI::OAuth`
|
45
|
+
|
46
|
+
== Version 4.12.0
|
47
|
+
|
48
|
+
* Added support for the GraphQL API
|
49
|
+
|
50
|
+
== Version 4.11.0
|
51
|
+
|
52
|
+
* Added `ShopifyAPI::InventoryItem`
|
53
|
+
* Added `ShopifyAPI::InventoryLevel`
|
54
|
+
* Added `#inventory_levels` method to `ShopifyAPI::Location`
|
55
|
+
|
56
|
+
== Version 4.10.0
|
57
|
+
|
58
|
+
* Added `ShopifyAPI::AccessScope`
|
59
|
+
|
60
|
+
== Version 4.9.1
|
61
|
+
|
62
|
+
* Fix a bug with custom properties for orders
|
63
|
+
|
1
64
|
== Version 4.9.0
|
2
65
|
|
3
66
|
* Added `ShopifyAPI::PriceRule`
|
data/README.md
CHANGED
@@ -10,6 +10,13 @@ The Shopify API gem allows Ruby developers to programmatically access the admin
|
|
10
10
|
|
11
11
|
The API is implemented as JSON over HTTP using all four verbs (GET/POST/PUT/DELETE). Each resource, like Order, Product, or Collection, has its own URL and is manipulated in isolation. In other words, we’ve tried to make the API follow the REST principles as much as possible.
|
12
12
|
|
13
|
+
## ⚠️ Breaking change notice for version 5.0.0 ⚠️
|
14
|
+
The [Abandoned Checkout API](https://help.shopify.com/en/api/reference/orders/abandoned_checkouts) is now accessed through the `ShopifyAPI::AbandonedCheckout` resource. If you were previously accessing the Abandoned Checkout API through the `ShopifyAPI::Checkout` resource, you will need to update your code after upgrading from version 4.x.x or earlier.
|
15
|
+
|
16
|
+
Going forward, the `ShopifyAPI::Checkout` resource is used to access the [Checkout API](https://help.shopify.com/en/api/reference/sales_channels/checkout), which can be used to create new checkouts.
|
17
|
+
|
18
|
+
For more details, [please see this issue](https://github.com/Shopify/shopify_api/issues/471).
|
19
|
+
|
13
20
|
## Usage
|
14
21
|
|
15
22
|
### Requirements
|
@@ -19,7 +26,7 @@ All API usage happens through Shopify applications, created by either shop owner
|
|
19
26
|
* Shop owners can create applications for themselves through their own admin: https://docs.shopify.com/api/authentication/creating-a-private-app
|
20
27
|
* Shopify Partners create applications through their admin: http://app.shopify.com/services/partners
|
21
28
|
|
22
|
-
For more information and detailed documentation about the API visit
|
29
|
+
For more information and detailed documentation about the API visit https://developers.shopify.com/
|
23
30
|
|
24
31
|
#### Ruby version
|
25
32
|
|
@@ -39,15 +46,6 @@ Or install via [gem](http://rubygems.org/)
|
|
39
46
|
gem install shopify_api
|
40
47
|
```
|
41
48
|
|
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
|
-
|
51
49
|
### Getting Started
|
52
50
|
|
53
51
|
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:
|
@@ -230,6 +228,30 @@ gem install shopify_cli
|
|
230
228
|
shopify-cli help
|
231
229
|
```
|
232
230
|
|
231
|
+
## GraphQL
|
232
|
+
|
233
|
+
This library also supports Shopify's new [GraphQL API](https://help.shopify.com/api/graphql-admin-api)
|
234
|
+
via a dependency on the [graphql-client](https://github.com/github/graphql-client) gem.
|
235
|
+
The authentication process (steps 1-5 under [Getting Started](#getting-started))
|
236
|
+
is identical. Once your session is activated, simply construct a new graphql
|
237
|
+
client and use `parse` and `query` as defined by
|
238
|
+
[graphql-client](https://github.com/github/graphql-client#defining-queries).
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
client = ShopifyAPI::GraphQL.new
|
242
|
+
|
243
|
+
SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
|
244
|
+
{
|
245
|
+
shop {
|
246
|
+
name
|
247
|
+
}
|
248
|
+
}
|
249
|
+
GRAPHQL
|
250
|
+
|
251
|
+
result = client.query(SHOP_NAME_QUERY)
|
252
|
+
result.data.shop.name
|
253
|
+
```
|
254
|
+
|
233
255
|
## Threadsafety
|
234
256
|
|
235
257
|
ActiveResource is threadsafe as of version 4.1 (which works with Rails 4.x and above).
|
@@ -241,14 +263,14 @@ If you were previously using Shopify's [activeresource fork](https://github.com/
|
|
241
263
|
Download the source code and run:
|
242
264
|
|
243
265
|
```bash
|
244
|
-
|
266
|
+
bundle install
|
267
|
+
bundle exec rake test
|
245
268
|
```
|
246
269
|
|
247
270
|
## Additional Resources
|
248
271
|
|
249
|
-
API
|
250
|
-
|
251
|
-
Ask questions on the forums: http://ecommerce.shopify.com/c/shopify-apis-and-technology
|
272
|
+
* [API Reference](https://help.shopify.com/api/reference)
|
273
|
+
* [Ask questions on the forums](http://ecommerce.shopify.com/c/shopify-apis-and-technology)
|
252
274
|
|
253
275
|
## Copyright
|
254
276
|
|
@@ -1,6 +1,17 @@
|
|
1
1
|
module ActiveResource
|
2
2
|
class DetailedLogSubscriber < ActiveSupport::LogSubscriber
|
3
3
|
def request(event)
|
4
|
+
log_request_response_details(event)
|
5
|
+
warn_on_deprecated_header(event)
|
6
|
+
end
|
7
|
+
|
8
|
+
def logger
|
9
|
+
ActiveResource::Base.logger
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def log_request_response_details(event)
|
4
15
|
data = event.payload[:data]
|
5
16
|
headers = data.extract_options!
|
6
17
|
request_body = data.first
|
@@ -10,8 +21,20 @@ module ActiveResource
|
|
10
21
|
info "Response:\n#{event.payload[:response].body}"
|
11
22
|
end
|
12
23
|
|
13
|
-
def
|
14
|
-
|
24
|
+
def warn_on_deprecated_header(event)
|
25
|
+
payload = event.payload
|
26
|
+
|
27
|
+
payload[:response].each do |header_name, header_value|
|
28
|
+
case header_name.downcase
|
29
|
+
when 'x-shopify-api-deprecated-reason'
|
30
|
+
warning_message = <<~MSG
|
31
|
+
[DEPRECATED] ShopifyAPI made a call to #{payload[:method].upcase} #{payload[:path]}, and this call made
|
32
|
+
use of a deprecated endpoint, behaviour, or parameter. See #{header_value} for more details.
|
33
|
+
MSG
|
34
|
+
|
35
|
+
warn warning_message
|
36
|
+
end
|
37
|
+
end
|
15
38
|
end
|
16
39
|
end
|
17
40
|
end
|
@@ -13,15 +13,17 @@ module ShopifyAPI
|
|
13
13
|
module RequestNotification
|
14
14
|
def request(method, path, *arguments)
|
15
15
|
super.tap do |response|
|
16
|
-
notify_about_request(response, arguments)
|
16
|
+
notify_about_request(method, path, response, arguments)
|
17
17
|
end
|
18
18
|
rescue => e
|
19
|
-
notify_about_request(e.response, arguments) if e.respond_to?(:response)
|
19
|
+
notify_about_request(method, path, e.response, arguments) if e.respond_to?(:response)
|
20
20
|
raise
|
21
21
|
end
|
22
22
|
|
23
|
-
def notify_about_request(response, arguments)
|
23
|
+
def notify_about_request(method, path, response, arguments)
|
24
24
|
ActiveSupport::Notifications.instrument("request.active_resource_detailed") do |payload|
|
25
|
+
payload[:method] = method
|
26
|
+
payload[:path] = path
|
25
27
|
payload[:response] = response
|
26
28
|
payload[:data] = arguments
|
27
29
|
end
|
data/lib/shopify_api/limits.rb
CHANGED
@@ -39,8 +39,7 @@ module ShopifyAPI
|
|
39
39
|
# @return {Integer}
|
40
40
|
#
|
41
41
|
def credit_limit(scope=:shop)
|
42
|
-
|
43
|
-
@api_credit_limit[scope] ||= api_credit_limit_param(scope).pop.to_i - 1
|
42
|
+
api_credit_limit_param(scope).pop.to_i - 1
|
44
43
|
end
|
45
44
|
alias_method :call_limit, :credit_limit
|
46
45
|
|
@@ -42,7 +42,7 @@ module ShopifyAPI
|
|
42
42
|
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
43
43
|
"#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
# find an asset by key:
|
47
47
|
# ShopifyAPI::Asset.find('layout/theme.liquid', :params => {:theme_id => 99})
|
48
48
|
def self.find(*args)
|
@@ -57,7 +57,7 @@ module ShopifyAPI
|
|
57
57
|
resource
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# For text assets, Shopify returns the data in the 'value' attribute.
|
62
62
|
# For binary assets, the data is base-64-encoded and returned in the
|
63
63
|
# 'attachment' attribute. This accessor returns the data in both cases.
|
@@ -65,28 +65,28 @@ module ShopifyAPI
|
|
65
65
|
attributes['value'] ||
|
66
66
|
(attributes['attachment'] ? Base64.decode64(attributes['attachment']) : nil)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def attach(data)
|
70
70
|
self.attachment = Base64.encode64(data)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def destroy
|
74
74
|
connection.delete(element_path(prefix_options.merge(:asset => {:key => key})), self.class.headers)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def new?
|
78
78
|
false
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
def method_missing(method_symbol, *arguments) #:nodoc:
|
82
82
|
if %w{value= attachment= src= source_key=}.include?(method_symbol)
|
83
83
|
wipe_value_attributes
|
84
84
|
end
|
85
85
|
super
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
private
|
89
|
-
|
89
|
+
|
90
90
|
def wipe_value_attributes
|
91
91
|
%w{value attachment src source_key}.each do |attr|
|
92
92
|
attributes.delete(attr)
|
@@ -1,4 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ShopifyAPI
|
2
4
|
class Checkout < Base
|
5
|
+
self.primary_key = :token
|
6
|
+
|
7
|
+
def self.headers
|
8
|
+
super.merge('X-Shopify-Checkout-Version' => '2016-09-06')
|
9
|
+
end
|
10
|
+
|
11
|
+
def complete
|
12
|
+
post(:complete)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ready?
|
16
|
+
return false unless persisted?
|
17
|
+
|
18
|
+
reload
|
19
|
+
[200, 201].include?(ShopifyAPI::Base.connection.response.code.to_i)
|
20
|
+
end
|
21
|
+
|
22
|
+
def payments
|
23
|
+
Payment.find(:all, params: { checkout_id: id })
|
24
|
+
end
|
25
|
+
|
26
|
+
def shipping_rates
|
27
|
+
ShippingRate.find(:all, params: { checkout_id: id })
|
28
|
+
end
|
3
29
|
end
|
4
|
-
end
|
30
|
+
end
|
@@ -6,14 +6,14 @@ module ShopifyAPI
|
|
6
6
|
def products
|
7
7
|
Product.find(:all, :params => {:collection_id => self.id})
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def add_product(product)
|
11
11
|
Collect.create(:collection_id => self.id, :product_id => product.id)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def remove_product(product)
|
15
15
|
collect = Collect.find(:first, :params => {:collection_id => self.id, :product_id => product.id})
|
16
16
|
collect.destroy if collect
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
19
19
|
end
|