shopify_api 3.1.7 → 3.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f107b47a300751663d847a7b27d3e0bc40d6a23f
4
+ data.tar.gz: 73094dbd7e250b929f96995a0337b83cc468d943
5
+ SHA512:
6
+ metadata.gz: 2d5a37087e8921df1a51aeaa7d4de064bacd87d2c4c5319aeb6c207a0832dd754e6565c7caa915532744790844e97b5081145fbff9d87e661b87c5155a2681e2
7
+ data.tar.gz: e8bd2c7c19cc061577b9948b20c4b6e3b8e6cc3abaf9ccec073304210c7a62b46bd0a8ac6b41c2ddaf5295e029a148db11e351f092e1535f6842a2cbb53a2207
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == Version 3.1.8
2
+
3
+ * Expose `index` and `show` actions of `Location`
4
+ * Added create_permission_url and request_token helper methods
5
+ * Edited the readme to better describe the getting started procedure
6
+
1
7
  == Version 3.1.7
2
8
 
3
9
  * Expose `authors` and `tags` action on Article
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shopify_api (3.1.7)
4
+ shopify_api (3.1.8)
5
5
  activeresource (>= 3.0.0)
6
6
  thor (>= 0.14.4)
7
7
 
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Shopify API gem allows Ruby developers to programmatically access the admin section of Shopify stores.
4
4
 
5
- The API is implemented as XML 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.
5
+ 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.
6
6
 
7
7
 
8
8
  == Usage
@@ -11,32 +11,60 @@ The API is implemented as XML over HTTP using all four verbs (GET/POST/PUT/DELET
11
11
 
12
12
  All API usage happens through Shopify applications, created by either shop owners for their own shops, or by Shopify Partners for use by other shop owners:
13
13
 
14
- * Shop owners can create applications for themselves through their own admin (under the Preferences > Applications tab).
14
+ * Shop owners can create applications for themselves through their own admin: http://docs.shopify.com/api/tutorials/creating-a-private-app
15
15
  * Shopify Partners create applications through their admin: http://app.shopify.com/services/partners
16
16
 
17
17
  For more information and detailed documentation about the API visit http://api.shopify.com
18
18
 
19
+
20
+ === Installation
21
+
22
+ To easily install or upgrade to the latest release, use {gem}[http://rubygems.org/]
23
+
24
+ gem install shopify_api
25
+
26
+
19
27
  === Getting Started
20
28
 
21
29
  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:
22
30
 
23
- 1. First create a new application in either the partners admin or your store admin and write down your API_KEY and SHARED_SECRET.
31
+ 1. First create a new application in either the partners admin or your store admin. For a private App you'll need the API_KEY and the PASSWORD otherwise you'll need the API_KEY and SHARED_SECRET.
32
+
33
+ 2. For a private App you just need to set the base site url as follows:
34
+
35
+ shop_url = "https://#{API_KEY}:#{PASSWORD}@SHOP_NAME.myshopify.com/admin"
36
+ ShopifyAPI::Base.site = shop_url
24
37
 
25
- 2. You will need to supply two parameters to the Session class before you instantiate it:
38
+ That's it you're done, skip to step 7 and start using the API!
39
+
40
+ For a partner app you will need to supply two parameters to the Session class before you instantiate it:
26
41
 
27
42
  ShopifyAPI::Session.setup({:api_key => API_KEY, :secret => SHARED_SECRET})
28
43
 
29
- 3. To access a shop's data apps need an access token from that specific shop. This is a two-stage process. Before interacting with a shop for the first time an app should redirect the user to the following URL:
44
+ 3. In order to access a shop's data, apps need an access token from that specific shop. This is a two-stage process. Before interacting with a shop for the first time an app should redirect the user to the following URL:
30
45
 
31
- GET https://SHOP_NAME.myshopify.com/admin/oauth/authorize
46
+ GET https://SHOP_NAME.myshopify.com/admin/oauth/authorize
32
47
 
33
48
  with the following parameters:
34
49
 
35
50
  * client_id – Required – The API key for your app
36
- * scope – Required – The list of required scopes (explained below)
37
- * redirect_uri – Optional – The URL that the merchant will be sent to once authentication is complete. Must be the same host as the Return URL specified in the application settings
51
+ * scope – Required – The list of required scopes (explained here: http://docs.shopify.com/api/tutorials/oauth)
52
+ * redirect_uri – Optional – The URL that the merchant will be sent to once authentication is complete. Defaults to the URL specified in the application settings and must be the same host as that URL.
53
+
54
+ We've added the create_permision_url method to make this easier, first instantiate your session object:
55
+
56
+ session = ShopifyAPI::Session.new("SHOP_NAME.myshopify.com")
38
57
 
39
- 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 the the app can exchange for a permanent access token. Make the following call:
58
+ Then call:
59
+
60
+ scope = ["write_products"]
61
+ permission_url = session.create_permission_url(scope)
62
+
63
+ or if you want a custom redirect_uri:
64
+
65
+ permission_url = session.create_permission_url(scope, "https://my_redirect_uri.com")
66
+
67
+ 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. Make the following call:
40
68
 
41
69
  POST https://SHOP_NAME.myshopify.com/admin/oauth/access_token
42
70
 
@@ -48,34 +76,75 @@ ShopifyAPI uses ActiveResource to communicate with the REST web service. ActiveR
48
76
 
49
77
  and you'll get your permanent access token back in the response.
50
78
 
51
- 5. Use that token to instantiate a session that is ready to make calls to the given shop.
79
+ There is a method to make the request and get the token for you:
80
+
81
+ token = session.request_token(code)
82
+
83
+ Which will request the token, save it to the session object and return it. For future sessions simply pass the token in when creating the session object:
84
+
85
+ session = ShopifyAPI::Session.new("SHOP_NAME.myshopify.com", token)
86
+
87
+ 5. The session must be activated before use:
52
88
 
53
- token = params[:access_token]
54
- session = ShopifyAPI::Session.new("yourshopname.myshopify.com", token)
55
- session.valid? # returns true
89
+ ShopifyAPI::Base.activate_session(session)
56
90
 
57
- 5. Now you can activate the session and you're set:
91
+ 6. Now you're ready to make authorized API requests to your shop! Data is returned as ActiveResource instances:
58
92
 
59
- ShopifyAPI::Base.activate_session(session)
93
+ shop = ShopifyAPI::Shop.current
60
94
 
61
- 6. Get data from that shop (returns ActiveResource instances):
95
+ # Get a specific product
96
+ product = ShopifyAPI::Product.find(179761209)
62
97
 
63
- shop = ShopifyAPI::Shop.current
64
- latest_orders = ShopifyAPI::Order.find(:all)
98
+ # Create a new product
99
+ new_product = ShopifyAPI::Product.new
100
+ new_product.title = "Burton Custom Freestlye 151"
101
+ new_product.product_type = "Snowboard"
102
+ new_product.vendor = "Burton"
103
+ new_product.save
104
+
105
+ # Update a product
106
+ product.handle = "burton-snowboard"
107
+ product.save
65
108
 
66
109
  Alternatively, you can use #temp to initialize a Session and execute a command which also handles temporarily setting ActiveResource::Base.site:
67
110
 
68
- latest_orders = ShopifyAPI::Session.temp("yourshopname.myshopify.com", token) { ShopifyAPI::Order.find(:all) }
111
+ products = ShopifyAPI::Session.temp("SHOP_NAME.myshopify.com", token) { ShopifyAPI::Product.find(:all) }
69
112
 
70
- 7. Finally, you can also clear the session (for example if you want to work with another shop):
113
+ 8. If you want to work with another shop, you'll first need to clear the session::
71
114
 
72
- ShopifyAPI::Base.clear_session
115
+ ShopifyAPI::Base.clear_session
73
116
 
74
- == Questions or Problems?
75
117
 
76
- http://api.shopify.com <= Read the tech docs!
118
+ === Console
119
+
120
+ This package also includes the `shopify` executable to make it easy to open up an interactive console to use the API with a shop.
121
+
122
+ 1. Obtain a private API key and password to use with your shop (step 2 in "Getting Started")
123
+
124
+ 2. Use the `shopify` script to save the credentials for the shop to quickly log in.
125
+
126
+ shopify add yourshopname
127
+
128
+ Follow the prompts for the shop domain, API key and password.
129
+
130
+ 3. Start the console for the connection.
77
131
 
78
- http://wiki.shopify.com/Developer_Home <= Read the wiki!
132
+ shopify console
133
+
134
+ 4. To see the full list of commands, type:
135
+
136
+ shopify help
137
+
138
+
139
+ == Using Development Version
140
+
141
+ Download the source code and run:
142
+
143
+ rake install
144
+
145
+ == Additional Resources
146
+
147
+ http://api.shopify.com <= Read the tech docs!
79
148
 
80
149
  http://ecommerce.shopify.com/c/shopify-apis-and-technology <= Ask questions on the forums!
81
150
 
@@ -0,0 +1,4 @@
1
+ module ShopifyAPI
2
+ class Location < Base
3
+ end
4
+ end
@@ -68,7 +68,25 @@ module ShopifyAPI
68
68
  end
69
69
  end
70
70
  end
71
-
71
+
72
+ def create_permission_url(scope, redirect_uri = nil)
73
+ params = {:client_id => api_key, :scope => scope.join(',')}
74
+ params[:redirect_uri] = redirect_uri if redirect_uri
75
+ "#{protocol}://#{url}/admin/oauth/authorize?#{parameterize(params)}"
76
+ end
77
+
78
+ def request_token(code)
79
+ return token if token
80
+
81
+ response = access_token_request(code)
82
+
83
+ if response.code == "200"
84
+ token = JSON.parse(response.body)['access_token']
85
+ else
86
+ raise RuntimeError, response.msg
87
+ end
88
+ end
89
+
72
90
  def shop
73
91
  Shop.current
74
92
  end
@@ -81,5 +99,18 @@ module ShopifyAPI
81
99
  url.present? && token.present?
82
100
  end
83
101
 
102
+ private
103
+ def parameterize(params)
104
+ URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&'))
105
+ end
106
+
107
+ def access_token_request(code)
108
+ uri = URI.parse("#{protocol}://#{url}/admin/oauth/access_token")
109
+ https = Net::HTTP.new(uri.host, uri.port)
110
+ https.use_ssl = true
111
+ request = Net::HTTP::Post.new(uri.request_uri)
112
+ request.set_form_data({"client_id" => api_key, "client_secret" => secret, "code" => code})
113
+ https.request(request)
114
+ end
84
115
  end
85
116
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "3.1.7"
2
+ VERSION = "3.1.8"
3
3
  end
data/test/session_test.rb CHANGED
@@ -53,6 +53,55 @@ class SessionTest < Test::Unit::TestCase
53
53
  assert_equal 'https://fakeshop.myshopify.com/admin', ShopifyAPI::Base.site.to_s
54
54
  end
55
55
 
56
+ should "create_permission_url returns correct url with single scope no redirect uri" do
57
+ ShopifyAPI::Session.setup(:api_key => "My_test_key", :secret => "My test secret")
58
+ session = ShopifyAPI::Session.new('http://localhost.myshopify.com')
59
+ scope = ["write_products"]
60
+ permission_url = session.create_permission_url(scope)
61
+ assert_equal "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&scope=write_products", permission_url
62
+ end
63
+
64
+ should "create_permission_url returns correct url with single scope and redirect uri" do
65
+ ShopifyAPI::Session.setup(:api_key => "My_test_key", :secret => "My test secret")
66
+ session = ShopifyAPI::Session.new('http://localhost.myshopify.com')
67
+ scope = ["write_products"]
68
+ permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com")
69
+ assert_equal "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&scope=write_products&redirect_uri=http://my_redirect_uri.com", permission_url
70
+ end
71
+
72
+ should "create_permission_url returns correct url with dual scope no redirect uri" do
73
+ ShopifyAPI::Session.setup(:api_key => "My_test_key", :secret => "My test secret")
74
+ session = ShopifyAPI::Session.new('http://localhost.myshopify.com')
75
+ scope = ["write_products","write_customers"]
76
+ permission_url = session.create_permission_url(scope)
77
+ assert_equal "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&scope=write_products,write_customers", permission_url
78
+ end
79
+
80
+ should "create_permission_url returns correct url with no scope no redirect uri" do
81
+ ShopifyAPI::Session.setup(:api_key => "My_test_key", :secret => "My test secret")
82
+ session = ShopifyAPI::Session.new('http://localhost.myshopify.com')
83
+ scope = []
84
+ permission_url = session.create_permission_url(scope)
85
+ assert_equal "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&scope=", permission_url
86
+ end
87
+
88
+ should "request token should get token" do
89
+ ShopifyAPI::Session.setup(:api_key => "My test key", :secret => "My test secret")
90
+ session = ShopifyAPI::Session.new('http://localhost.myshopify.com')
91
+ fake nil, :url => 'https://localhost.myshopify.com/admin/oauth/access_token',:method => :post, :body => '{"access_token" : "token"}'
92
+ assert_equal "token", session.request_token("code")
93
+ end
94
+
95
+ should "raise exception if code invalid in request token" do
96
+ ShopifyAPI::Session.setup(:api_key => "My test key", :secret => "My test secret")
97
+ session = ShopifyAPI::Session.new('http://localhost.myshopify.com')
98
+ fake nil, :url => 'https://localhost.myshopify.com/admin/oauth/access_token',:method => :post, :status => 404, :body => '{"error" : "invalid_request"}'
99
+ assert_raises(RuntimeError) do
100
+ session.request_token("bad_code")
101
+ end
102
+ assert_equal false, session.valid?
103
+ end
104
+
56
105
  should "#temp reset ShopifyAPI::Base.site to original value when using a non-standard port" do
57
106
  ShopifyAPI::Session.setup(:api_key => "key", :secret => "secret")
58
107
  session1 = ShopifyAPI::Session.new('fakeshop.myshopify.com:3000', 'token1')
data/test/test_helper.rb CHANGED
@@ -58,8 +58,13 @@ class Test::Unit::TestCase
58
58
  format = options.delete(:format) || :json
59
59
  method = options.delete(:method) || :get
60
60
  extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
61
-
62
- url = "http://localhost/admin/#{endpoint}#{extension}"
61
+
62
+ url = if options.has_key?(:url)
63
+ options[:url]
64
+ else
65
+ "http://localhost/admin/#{endpoint}#{extension}"
66
+ end
67
+
63
68
  FakeWeb.register_uri(method, url, {:body => body, :status => 200, :content_type => "text/#{format}", :content_length => 1}.merge(options))
64
69
  end
65
70
  end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.7
5
- prerelease:
4
+ version: 3.1.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Shopify
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activeresource
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: thor
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.14.4
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.14.4
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mocha
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.9.8
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.9.8
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: fakeweb
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: The Shopify API gem allows Ruby developers to programmatically access
@@ -148,6 +137,7 @@ files:
148
137
  - lib/shopify_api/resources/fulfillment.rb
149
138
  - lib/shopify_api/resources/image.rb
150
139
  - lib/shopify_api/resources/line_item.rb
140
+ - lib/shopify_api/resources/location.rb
151
141
  - lib/shopify_api/resources/metafield.rb
152
142
  - lib/shopify_api/resources/note_attribute.rb
153
143
  - lib/shopify_api/resources/option.rb
@@ -214,34 +204,27 @@ files:
214
204
  homepage: http://www.shopify.com/partners/apps
215
205
  licenses:
216
206
  - MIT
207
+ metadata: {}
217
208
  post_install_message:
218
209
  rdoc_options:
219
210
  - --charset=UTF-8
220
211
  require_paths:
221
212
  - lib
222
213
  required_ruby_version: !ruby/object:Gem::Requirement
223
- none: false
224
214
  requirements:
225
- - - ! '>='
215
+ - - '>='
226
216
  - !ruby/object:Gem::Version
227
217
  version: '0'
228
- segments:
229
- - 0
230
- hash: 355511341296706903
231
218
  required_rubygems_version: !ruby/object:Gem::Requirement
232
- none: false
233
219
  requirements:
234
- - - ! '>='
220
+ - - '>='
235
221
  - !ruby/object:Gem::Version
236
222
  version: '0'
237
- segments:
238
- - 0
239
- hash: 355511341296706903
240
223
  requirements: []
241
224
  rubyforge_project:
242
- rubygems_version: 1.8.23
225
+ rubygems_version: 2.0.3
243
226
  signing_key:
244
- specification_version: 3
227
+ specification_version: 4
245
228
  summary: ShopifyAPI is a lightweight gem for accessing the Shopify admin REST web
246
229
  services
247
230
  test_files: []