shopify_api 5.2.4 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -1
- data/CHANGELOG +4 -0
- data/README.md +12 -12
- data/lib/shopify_api/session.rb +15 -16
- data/lib/shopify_api/version.rb +1 -1
- data/test/product_test.rb +10 -0
- data/test/session_test.rb +0 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b0ab297c1e32ac84d673b04ddf366cc5f9d43f2eb6f060d70e5d1fcc7c8736f
|
4
|
+
data.tar.gz: 99a2583bf370e73c85f2b71c4b6e99f1ac2e37db2a628a30dcbed346c29bdf8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94e653b2a765e962ba1f4c360308bab8a66bb32b8fe487def7ef9880c4b972f934f280fce5805a7f5dcdea60b2a591c0ff4ea87dff04ce6334d490506155aa5a
|
7
|
+
data.tar.gz: 13701b452c87df0a9fb4054857f37d5821b63bb0ee8e467556bc8bb1d5beeae0712ec2457462567a45a715bc8b5a60d68aad8811385d9353e61779bec68bf060
|
data/.github/CODEOWNERS
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* @shopify/
|
1
|
+
* @shopify/platform-dev-tools-education
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -88,20 +88,20 @@ ShopifyAPI uses ActiveResource to communicate with the REST web service. ActiveR
|
|
88
88
|
We've added the create_permission_url method to make this easier, first instantiate your session object:
|
89
89
|
|
90
90
|
```ruby
|
91
|
-
|
91
|
+
shopify_session = ShopifyAPI::Session.new("SHOP_NAME.myshopify.com")
|
92
92
|
```
|
93
93
|
|
94
94
|
Then call:
|
95
95
|
|
96
96
|
```ruby
|
97
97
|
scope = ["write_products"]
|
98
|
-
permission_url =
|
98
|
+
permission_url = shopify_session.create_permission_url(scope)
|
99
99
|
```
|
100
100
|
|
101
101
|
or if you want a custom redirect_uri:
|
102
102
|
|
103
103
|
```ruby
|
104
|
-
permission_url =
|
104
|
+
permission_url = shopify_session.create_permission_url(scope, "https://my_redirect_uri.com")
|
105
105
|
```
|
106
106
|
|
107
107
|
4. Once authorized, the shop redirects the owner to the return URL of your application with a parameter named 'code'. This is a temporary token that the app can exchange for a permanent access token.
|
@@ -131,37 +131,37 @@ ShopifyAPI uses ActiveResource to communicate with the REST web service. ActiveR
|
|
131
131
|
the params, extract the temp code and then request your token:
|
132
132
|
|
133
133
|
```ruby
|
134
|
-
token =
|
134
|
+
token = shopify_session.request_token(params)
|
135
135
|
```
|
136
136
|
|
137
137
|
This method will save the token to the session object and return it. All fields returned by Shopify, other than the access token itself, are stored in the session's `extra` attribute. For a list of all fields returned by Shopify, read [our OAuth documentation](https://help.shopify.com/api/guides/authentication/oauth#confirming-installation). If you requested an access token that is associated with a specific user, you can retreive information about this user from the `extra` hash:
|
138
138
|
|
139
139
|
```ruby
|
140
140
|
# a list of all granted scopes
|
141
|
-
granted_scopes =
|
141
|
+
granted_scopes = shopify_session.extra['scope']
|
142
142
|
# a hash containing the user information
|
143
|
-
user =
|
143
|
+
user = shopify_session.extra['associated_user']
|
144
144
|
# the access scopes available to this user, which may be a subset of the access scopes granted to this app.
|
145
|
-
active_scopes =
|
145
|
+
active_scopes = shopify_session.extra['associated_user_scope']
|
146
146
|
# the time at which this token expires; this is automatically converted from 'expires_in' returned by Shopify
|
147
|
-
expires_at =
|
147
|
+
expires_at = shopify_session.extra['expires_at']
|
148
148
|
```
|
149
149
|
|
150
150
|
For the security of your application, after retrieving an access token you must validate the following:
|
151
|
-
1) The list of scopes in `
|
152
|
-
2) If you requested an online-mode access token, `
|
151
|
+
1) The list of scopes in `shopify_session.extra['scope']` is the same as you requested.
|
152
|
+
2) If you requested an online-mode access token, `shopify_session.extra['associated_user']` must be present.
|
153
153
|
Failing either of these tests means the end-user may have tampered with the url parameters during the OAuth authentication phase. You should avoid using this access token and revoke it immediately. If you use the [`omniauth-shopify-oauth2`](https://github.com/Shopify/omniauth-shopify-oauth2) gem these checks are done automatically for you.
|
154
154
|
|
155
155
|
For future sessions simply pass in the `token` and `extra` hash (optional) when creating the session object:
|
156
156
|
|
157
157
|
```ruby
|
158
|
-
|
158
|
+
shopify_session = ShopifyAPI::Session.new("SHOP_NAME.myshopify.com", token, extra)
|
159
159
|
```
|
160
160
|
|
161
161
|
5. The session must be activated before use:
|
162
162
|
|
163
163
|
```ruby
|
164
|
-
ShopifyAPI::Base.activate_session(
|
164
|
+
ShopifyAPI::Base.activate_session(shopify_session)
|
165
165
|
```
|
166
166
|
|
167
167
|
6. Now you're ready to make authorized API requests to your shop! Data is returned as ActiveResource instances:
|
data/lib/shopify_api/session.rb
CHANGED
@@ -7,8 +7,7 @@ module ShopifyAPI
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class Session
|
10
|
-
cattr_accessor :api_key, :secret, :
|
11
|
-
self.protocol = 'https'
|
10
|
+
cattr_accessor :api_key, :secret, :myshopify_domain
|
12
11
|
self.myshopify_domain = 'myshopify.com'
|
13
12
|
|
14
13
|
attr_accessor :url, :token, :name, :extra
|
@@ -44,8 +43,7 @@ module ShopifyAPI
|
|
44
43
|
shop = shop.slice(0, idx)
|
45
44
|
end
|
46
45
|
return nil if shop.empty?
|
47
|
-
|
48
|
-
port ? "#{shop}:#{port}" : shop
|
46
|
+
"#{shop}.#{myshopify_domain}"
|
49
47
|
rescue URI::InvalidURIError
|
50
48
|
nil
|
51
49
|
end
|
@@ -105,7 +103,7 @@ module ShopifyAPI
|
|
105
103
|
end
|
106
104
|
|
107
105
|
def site
|
108
|
-
"
|
106
|
+
"https://#{url}/admin"
|
109
107
|
end
|
110
108
|
|
111
109
|
def valid?
|
@@ -128,17 +126,18 @@ module ShopifyAPI
|
|
128
126
|
end
|
129
127
|
|
130
128
|
private
|
131
|
-
def parameterize(params)
|
132
|
-
URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
133
|
-
end
|
134
129
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
130
|
+
def parameterize(params)
|
131
|
+
URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&'))
|
132
|
+
end
|
133
|
+
|
134
|
+
def access_token_request(code)
|
135
|
+
uri = URI.parse("https://#{url}/admin/oauth/access_token")
|
136
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
137
|
+
https.use_ssl = true
|
138
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
139
|
+
request.set_form_data('client_id' => api_key, 'client_secret' => secret, 'code' => code)
|
140
|
+
https.request(request)
|
141
|
+
end
|
143
142
|
end
|
144
143
|
end
|
data/lib/shopify_api/version.rb
CHANGED
data/test/product_test.rb
CHANGED
@@ -47,4 +47,14 @@ class ProductTest < Test::Unit::TestCase
|
|
47
47
|
variant.price = "0.50"
|
48
48
|
variant.save
|
49
49
|
end
|
50
|
+
|
51
|
+
def test_price_range
|
52
|
+
assert_equal('199.00', @product.price_range)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_price_range_when_has_different_price
|
56
|
+
@product.variants[0].price = '100.00'
|
57
|
+
|
58
|
+
assert_equal('100.00 - 199.00', @product.price_range)
|
59
|
+
end
|
50
60
|
end
|
data/test/session_test.rb
CHANGED
@@ -56,10 +56,6 @@ class SessionTest < Test::Unit::TestCase
|
|
56
56
|
assert_equal "My test secret", ShopifyAPI::Session.secret
|
57
57
|
end
|
58
58
|
|
59
|
-
test "use 'https' protocol by default for all sessions" do
|
60
|
-
assert_equal 'https', ShopifyAPI::Session.protocol
|
61
|
-
end
|
62
|
-
|
63
59
|
test "#temp reset ShopifyAPI::Base.site to original value" do
|
64
60
|
|
65
61
|
ShopifyAPI::Session.setup(:api_key => "key", :secret => "secret")
|
@@ -115,28 +111,6 @@ class SessionTest < Test::Unit::TestCase
|
|
115
111
|
assert_equal false, session.valid?
|
116
112
|
end
|
117
113
|
|
118
|
-
test "#temp reset ShopifyAPI::Base.site to original value when using a non-standard port" do
|
119
|
-
ShopifyAPI::Session.setup(:api_key => "key", :secret => "secret")
|
120
|
-
session1 = ShopifyAPI::Session.new('fakeshop.myshopify.com:3000', 'token1')
|
121
|
-
ShopifyAPI::Base.activate_session(session1)
|
122
|
-
end
|
123
|
-
|
124
|
-
test "myshopify_domain supports non-standard ports" do
|
125
|
-
begin
|
126
|
-
ShopifyAPI::Session.setup(:api_key => "key", :secret => "secret", :myshopify_domain => 'localhost', port: '3000')
|
127
|
-
session = ShopifyAPI::Session.new('fakeshop.localhost:3000', 'token1')
|
128
|
-
ShopifyAPI::Base.activate_session(session)
|
129
|
-
assert_equal 'https://fakeshop.localhost:3000/admin', ShopifyAPI::Base.site.to_s
|
130
|
-
|
131
|
-
session = ShopifyAPI::Session.new('fakeshop', 'token1')
|
132
|
-
ShopifyAPI::Base.activate_session(session)
|
133
|
-
assert_equal 'https://fakeshop.localhost:3000/admin', ShopifyAPI::Base.site.to_s
|
134
|
-
ensure
|
135
|
-
ShopifyAPI::Session.myshopify_domain = "myshopify.com"
|
136
|
-
ShopifyAPI::Session.port = nil
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
114
|
test "return site for session" do
|
141
115
|
session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
|
142
116
|
assert_equal "https://testshop.myshopify.com/admin", session.site
|
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
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|