etsy 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +8 -0
- data/Gemfile +10 -0
- data/README.md +300 -0
- data/Rakefile +2 -30
- data/etsy.gemspec +36 -0
- data/lib/etsy.rb +46 -17
- data/lib/etsy/address.rb +47 -0
- data/lib/etsy/basic_client.rb +1 -1
- data/lib/etsy/category.rb +84 -0
- data/lib/etsy/country.rb +27 -0
- data/lib/etsy/image.rb +7 -3
- data/lib/etsy/listing.rb +107 -8
- data/lib/etsy/model.rb +99 -3
- data/lib/etsy/payment_template.rb +33 -0
- data/lib/etsy/profile.rb +49 -0
- data/lib/etsy/request.rb +85 -17
- data/lib/etsy/response.rb +80 -4
- data/lib/etsy/section.rb +16 -0
- data/lib/etsy/secure_client.rb +49 -4
- data/lib/etsy/shipping_template.rb +32 -0
- data/lib/etsy/shop.rb +21 -12
- data/lib/etsy/transaction.rb +18 -0
- data/lib/etsy/user.rb +45 -13
- data/lib/etsy/verification_request.rb +2 -2
- data/test/fixtures/address/getUserAddresses.json +12 -0
- data/test/fixtures/category/findAllSubCategoryChildren.json +78 -0
- data/test/fixtures/category/findAllTopCategory.json +347 -0
- data/test/fixtures/category/findAllTopCategory.single.json +18 -0
- data/test/fixtures/category/findAllTopCategoryChildren.json +308 -0
- data/test/fixtures/category/getCategory.multiple.json +28 -0
- data/test/fixtures/category/getCategory.single.json +18 -0
- data/test/fixtures/country/getCountry.json +1 -0
- data/test/fixtures/listing/findAllListingActive.category.json +827 -0
- data/test/fixtures/listing/{findAllShopListingsActive.json → findAllShopListings.json} +0 -0
- data/test/fixtures/listing/getListing.multiple.json +1 -0
- data/test/fixtures/listing/getListing.single.json +1 -0
- data/test/fixtures/payment_template/getPaymentTemplate.json +1 -0
- data/test/fixtures/profile/new.json +28 -0
- data/test/fixtures/section/getShopSection.json +18 -0
- data/test/fixtures/shipping_template/getShippingTemplate.json +1 -0
- data/test/fixtures/shop/getShop.single.json +4 -3
- data/test/fixtures/transaction/findAllShopTransactions.json +1 -0
- data/test/fixtures/user/getUser.single.withProfile.json +38 -0
- data/test/fixtures/user/getUser.single.withShops.json +41 -0
- data/test/test_helper.rb +9 -4
- data/test/unit/etsy/address_test.rb +61 -0
- data/test/unit/etsy/category_test.rb +106 -0
- data/test/unit/etsy/country_test.rb +64 -0
- data/test/unit/etsy/listing_test.rb +112 -5
- data/test/unit/etsy/model_test.rb +64 -0
- data/test/unit/etsy/payment_template_test.rb +68 -0
- data/test/unit/etsy/profile_test.rb +111 -0
- data/test/unit/etsy/request_test.rb +89 -53
- data/test/unit/etsy/response_test.rb +118 -4
- data/test/unit/etsy/section_test.rb +28 -0
- data/test/unit/etsy/secure_client_test.rb +27 -5
- data/test/unit/etsy/shipping_template_test.rb +24 -0
- data/test/unit/etsy/shop_test.rb +12 -5
- data/test/unit/etsy/transaction_test.rb +52 -0
- data/test/unit/etsy/user_test.rb +147 -8
- data/test/unit/etsy/verification_request_test.rb +3 -3
- data/test/unit/etsy_test.rb +19 -7
- metadata +133 -77
- data/README.rdoc +0 -208
- data/lib/etsy/version.rb +0 -13
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,300 @@
|
|
1
|
+
# Etsy
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/kytrinyx/etsy.png)](http://travis-ci.org/kytrinyx/etsy)
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
The Etsy gem provides a friendly Ruby interface to the Etsy API
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Installing the latest stable version is simple:
|
12
|
+
|
13
|
+
$ gem install etsy
|
14
|
+
|
15
|
+
If you want to be on the bleeding edge, install from GitHub:
|
16
|
+
|
17
|
+
$ git clone git://github.com/reagent/etsy.git
|
18
|
+
$ cd etsy
|
19
|
+
$ rake gem && gem install pkg/etsy-<version>.gem
|
20
|
+
|
21
|
+
### Dependencies
|
22
|
+
|
23
|
+
The gem has been verified to work with version 1.5.0 of json.
|
24
|
+
It will likely work with higher versions, but this is unproven.
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Public Mode
|
29
|
+
|
30
|
+
The Etsy API has two modes: public, and authenticated. Public mode only requires an
|
31
|
+
API key (available from http://developer.etsy.com):
|
32
|
+
|
33
|
+
require 'rubygems'
|
34
|
+
require 'etsy'
|
35
|
+
|
36
|
+
Etsy.api_key = 'foobar'
|
37
|
+
|
38
|
+
From there, you can make any non-authenticated calls to the API that you need.
|
39
|
+
|
40
|
+
## Authenticated Calls
|
41
|
+
|
42
|
+
The Etsy API has support for both retrieval of extended information and write support for authenticated users. Authentication can either be performed from the console or from within a Ruby web application.
|
43
|
+
|
44
|
+
### Console
|
45
|
+
|
46
|
+
For simple authentication from the console, configure the necessary parameters:
|
47
|
+
|
48
|
+
require 'rubygems'
|
49
|
+
require 'etsy'
|
50
|
+
|
51
|
+
Etsy.api_key = 'key'
|
52
|
+
Etsy.api_secret = 'secret'
|
53
|
+
|
54
|
+
First, generate a request token:
|
55
|
+
|
56
|
+
request = Etsy.request_token
|
57
|
+
|
58
|
+
From there, you will need to paste a verification URL into a browser:
|
59
|
+
|
60
|
+
Etsy.verification_url
|
61
|
+
|
62
|
+
Once you have allowed access, you can generate an access token by supplying
|
63
|
+
the verifier displayed on the Etsy site:
|
64
|
+
|
65
|
+
access = Etsy.access_token(request.token, request.secret, 'abc123')
|
66
|
+
|
67
|
+
Authenticated calls can now be made by passing an access token and secret:
|
68
|
+
|
69
|
+
Etsy.myself(access.token, access.secret)
|
70
|
+
|
71
|
+
### Web Application
|
72
|
+
|
73
|
+
The process for authenticating via a web application is similar, but requires the configuration of a callback URL:
|
74
|
+
|
75
|
+
require 'rubygems'
|
76
|
+
require 'etsy'
|
77
|
+
|
78
|
+
Etsy.api_key = 'key'
|
79
|
+
Etsy.api_secret = 'secret'
|
80
|
+
Etsy.callback_url = 'http://localhost:4567/authorize'
|
81
|
+
|
82
|
+
In this mode, you'll need to store the request token and secret before redirecting
|
83
|
+
to the verification URL. A simple example using Sinatra:
|
84
|
+
|
85
|
+
enable :sessions
|
86
|
+
|
87
|
+
get '/' do
|
88
|
+
request_token = Etsy.request_token
|
89
|
+
session[:request_token] = request_token.token
|
90
|
+
session[:request_secret] = request_token.secret
|
91
|
+
redirect Etsy.verification_url
|
92
|
+
end
|
93
|
+
|
94
|
+
get '/authorize' do
|
95
|
+
access_token = Etsy.access_token(
|
96
|
+
session[:request_token],
|
97
|
+
session[:request_secret],
|
98
|
+
params[:oauth_verifier]
|
99
|
+
)
|
100
|
+
# access_token.token and access_token.secret can now be saved for future API calls
|
101
|
+
end
|
102
|
+
|
103
|
+
### Environment
|
104
|
+
|
105
|
+
The Etsy API has both a sandbox environment and a production environment.
|
106
|
+
|
107
|
+
If nothing is set, the default is :sandbox.
|
108
|
+
|
109
|
+
You can set this using:
|
110
|
+
|
111
|
+
Etsy.environment = :production
|
112
|
+
|
113
|
+
## DSL
|
114
|
+
|
115
|
+
Use the Etsy::Request class to make flexible calls to the API.
|
116
|
+
|
117
|
+
To do so, find out which endpoint you wish to connect to and the parameters you wish to pass in.
|
118
|
+
|
119
|
+
>> access = {:access_token => 'token', :access_secret => 'secret'}
|
120
|
+
>> Etsy::Request.get('/taxonomy/tags', access.merge(:limit => 5))
|
121
|
+
|
122
|
+
or to fetch an associated resource
|
123
|
+
|
124
|
+
>> access = {:access_token => 'token', :access_secret => 'secret'}
|
125
|
+
>> Etsy::Request.get('/users/__SELF__', access.merge(:includes => 'Profile'))
|
126
|
+
|
127
|
+
or to limit the fields returned
|
128
|
+
|
129
|
+
>> shop_id = 'littletjane'
|
130
|
+
>> access = {:access_token => 'token', :access_secret => 'secret'}
|
131
|
+
>> Etsy::Request.get('/shops/#{shop_id}', access.merge(:fields => 'is_vacation,is_refusing_alchemy'))
|
132
|
+
|
133
|
+
## Convenience Methods
|
134
|
+
|
135
|
+
There are some wrappers for resources that typically are needed in a small application.
|
136
|
+
|
137
|
+
### Users
|
138
|
+
|
139
|
+
If you're starting with a user, the easiest way is to use the Etsy.user method:
|
140
|
+
|
141
|
+
>> user = Etsy.user('littletjane')
|
142
|
+
=> #<Etsy::User:0x107f82c @result=[{"city"=>"Washington, DC", ... >
|
143
|
+
>> user.username
|
144
|
+
=> "littletjane"
|
145
|
+
>> user.id
|
146
|
+
=> 5327518
|
147
|
+
|
148
|
+
For more information about what is available for a user, check out the documentation
|
149
|
+
for Etsy::User.
|
150
|
+
|
151
|
+
### Shops
|
152
|
+
|
153
|
+
Each user may optionally have a shop. If a user is a seller, he / she also has an
|
154
|
+
associated shop object:
|
155
|
+
|
156
|
+
>> shop = user.shop
|
157
|
+
=> #<Etsy::Shop:0x102578c @result={"is_vacation"=>"", "announcement"=> ... >
|
158
|
+
>> shop.name
|
159
|
+
=> "littletjane"
|
160
|
+
>> shop.title
|
161
|
+
=> "a cute and crafty mix of handmade goods."
|
162
|
+
|
163
|
+
More information about shops can be found in the documentation for Etsy::Shop.
|
164
|
+
|
165
|
+
### Listings
|
166
|
+
|
167
|
+
Shops contain multiple listings:
|
168
|
+
|
169
|
+
>> shop.listings
|
170
|
+
=> [#<Etsy::Listing:0x119acac @result={} ...>, ... ]
|
171
|
+
>> listing = shop.listings.first
|
172
|
+
=> #<Etsy::Listing:0x19a981c @result={} ... >
|
173
|
+
>> listing.title
|
174
|
+
=> "hanging with the bad boys matchbox"
|
175
|
+
>> listing.description
|
176
|
+
=> "standard size matchbox, approx. 1.5 x 2 inches ..."
|
177
|
+
>> listing.url
|
178
|
+
=> "http://www.etsy.com/view_listing.php?listing_id=24165902"
|
179
|
+
>> listing.view_count
|
180
|
+
=> 19
|
181
|
+
>> listing.created_at
|
182
|
+
=> Sat Apr 25 11:31:34 -0400 2009
|
183
|
+
|
184
|
+
See the documentation for Etsy::Listing for more information.
|
185
|
+
|
186
|
+
### Images
|
187
|
+
|
188
|
+
Each listing has one or more images available:
|
189
|
+
|
190
|
+
>> listing.images
|
191
|
+
=> [#<Etsy::Image:0x18f85e4 @result={} ... >,
|
192
|
+
#<Etsy::Image:0x18f85d0 @result={} ... >]
|
193
|
+
>> listing.images.first.square
|
194
|
+
=> "http://ny-image0.etsy.com/il_75x75.189111072.jpg"
|
195
|
+
>> listing.images.first.full
|
196
|
+
=> "http://ny-image0.etsy.com/il_fullxfull.189111072.jpg"
|
197
|
+
|
198
|
+
Listings also have a primary image:
|
199
|
+
|
200
|
+
>> listing.image
|
201
|
+
=> #<Etsy::Image:0x18c3060 @result={} ... >
|
202
|
+
>> listing.image.full
|
203
|
+
=> "http://ny-image0.etsy.com/il_fullxfull.189111072.jpg"
|
204
|
+
|
205
|
+
More information is available in the documentation for Etsy::Image.
|
206
|
+
|
207
|
+
### Associations
|
208
|
+
|
209
|
+
Associations on resources can be specified with the 'includes' key.
|
210
|
+
|
211
|
+
A single resource can be specified with the name of the resource as a string:
|
212
|
+
|
213
|
+
>> Listing.find(1, {:includes => 'Images'})
|
214
|
+
|
215
|
+
Multiple resources can be specified with the name of the resources as a comma-delimited string:
|
216
|
+
|
217
|
+
>> User.find(1, {:includes => ['FeedbackAsBuyer', 'FeedbackAsSeller']})
|
218
|
+
|
219
|
+
If you want a more fine-grained response, you can specify the associations as an array of hashes, each of which must contain the name of the resource, and can also include the fields you wish returned, as well as the limit and offset.
|
220
|
+
|
221
|
+
>> association = {:resource => 'Images', :fields => ['red','green','blue'], :limit => 1, :offset => 0}
|
222
|
+
>> Listing.find(1, {:includes => [association]})
|
223
|
+
|
224
|
+
## Contributing
|
225
|
+
|
226
|
+
I have a "commit bit" policy for contributions to this repository. Once I accept
|
227
|
+
your patch, I will give you full commit access. To submit patches:
|
228
|
+
|
229
|
+
1. Fork this repository
|
230
|
+
2. Implement the desired feature with tests (and documentation if necessary)
|
231
|
+
3. Send me a pull request
|
232
|
+
|
233
|
+
I ask that you not submit patches that include changes to the version or gemspec.
|
234
|
+
|
235
|
+
### Basics steps for contributing using (https://github.com/defunkt/hub)
|
236
|
+
|
237
|
+
# Setup the project
|
238
|
+
git clone kytrinyx/etsy
|
239
|
+
git fork
|
240
|
+
bundle
|
241
|
+
rake
|
242
|
+
|
243
|
+
# Normal flow
|
244
|
+
git checkout -b your-feature-or-bug
|
245
|
+
# Write your tests
|
246
|
+
# Make the tests pass
|
247
|
+
git add <CHANGES>
|
248
|
+
git commit -m "Some useful message"
|
249
|
+
git push -u YOUR-GITHUB-USERNAME your-feature-or-bug
|
250
|
+
git pull-request
|
251
|
+
|
252
|
+
## Contributors
|
253
|
+
|
254
|
+
These people have helped make the Etsy gem what it is today:
|
255
|
+
|
256
|
+
* [Patrick Reagan](https://github.com/reagent)
|
257
|
+
* [Katrina Owen](http://github.com/kytrinyx)
|
258
|
+
* [Mak Nazečić-Andrlon](https://github.com/Muon)
|
259
|
+
* [Patrick Schless](https://github.com/plainlystated)
|
260
|
+
* [Matt Fields](https://github.com/mfields106)
|
261
|
+
* [Jake Boxer](https://github.com/jakeboxer)
|
262
|
+
* [Trae Robrock](https://github.com/trobrock)
|
263
|
+
* [Jimmy Tang](https://github.com/jimmytang)
|
264
|
+
* [Julio Santos](https://github.com/julio)
|
265
|
+
|
266
|
+
### Github Flow
|
267
|
+
|
268
|
+
For those of you with commit access, please check out Scott Chacon's blog post about [github flow](http://scottchacon.com/2011/08/31/github-flow.html)
|
269
|
+
|
270
|
+
> * Anything in the master branch is deployable
|
271
|
+
> * To work on something new, create a descriptively named branch off of master (ie: new-oauth2-scopes)
|
272
|
+
> * Commit to that branch locally and regularly push your work to the same named branch on the server
|
273
|
+
> * When you need feedback or help, or you think the branch is ready for merging, open a pull request
|
274
|
+
> * After someone else has reviewed and signed off on the feature, you can merge it into master
|
275
|
+
> * Once it is merged and pushed to ‘master’, you can and should deploy immediately
|
276
|
+
|
277
|
+
## License
|
278
|
+
|
279
|
+
Copyright (c) 2009 - 2012 Patrick Reagan (reaganpr@gmail.com)
|
280
|
+
|
281
|
+
Permission is hereby granted, free of charge, to any person
|
282
|
+
obtaining a copy of this software and associated documentation
|
283
|
+
files (the "Software"), to deal in the Software without
|
284
|
+
restriction, including without limitation the rights to use,
|
285
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
286
|
+
copies of the Software, and to permit persons to whom the
|
287
|
+
Software is furnished to do so, subject to the following
|
288
|
+
conditions:
|
289
|
+
|
290
|
+
The above copyright notice and this permission notice shall be
|
291
|
+
included in all copies or substantial portions of the Software.
|
292
|
+
|
293
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
294
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
295
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
296
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
297
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
298
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
299
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
300
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,40 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
1
2
|
require 'rubygems'
|
2
|
-
require 'rake/gempackagetask'
|
3
3
|
require 'rake/testtask'
|
4
|
-
|
5
|
-
require 'lib/etsy/version'
|
4
|
+
require "bundler/gem_tasks"
|
6
5
|
|
7
6
|
task :default => :test
|
8
7
|
|
9
|
-
spec = Gem::Specification.new do |s|
|
10
|
-
s.name = 'etsy'
|
11
|
-
s.version = Etsy::Version.to_s
|
12
|
-
s.has_rdoc = true
|
13
|
-
s.extra_rdoc_files = %w(README.rdoc)
|
14
|
-
s.rdoc_options = %w(--main README.rdoc)
|
15
|
-
s.summary = "Provides a friendly ruby-like interface to the Etsy API"
|
16
|
-
s.author = 'Patrick Reagan'
|
17
|
-
s.email = 'reaganpr@gmail.com'
|
18
|
-
s.homepage = 'http://sneaq.net'
|
19
|
-
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
20
|
-
|
21
|
-
s.add_dependency('json', '~> 1.4.0')
|
22
|
-
s.add_dependency('oauth', '~> 0.4.0')
|
23
|
-
end
|
24
|
-
|
25
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
26
|
-
pkg.gem_spec = spec
|
27
|
-
end
|
28
|
-
|
29
8
|
Rake::TestTask.new do |t|
|
30
9
|
t.libs << 'test'
|
31
10
|
t.test_files = FileList["test/**/*_test.rb"]
|
32
11
|
t.verbose = true
|
33
12
|
end
|
34
|
-
|
35
|
-
desc 'Generate the gemspec for this Gem'
|
36
|
-
task :gemspec do
|
37
|
-
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
38
|
-
File.open(file, 'w') {|f| f << spec.to_ruby }
|
39
|
-
puts "Created gemspec: #{file}"
|
40
|
-
end
|
data/etsy.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.required_rubygems_version = Gem::Requirement.new(">= 0") if gem.respond_to? :required_rubygems_version=
|
5
|
+
gem.rubygems_version = "1.8.10"
|
6
|
+
|
7
|
+
gem.authors = ["Katrina Owen"]
|
8
|
+
gem.authors = ["Patrick Reagan", "Katrina Owen"]
|
9
|
+
gem.email = ["reaganpr@gmail.com", "katrina.owen@gmail.com"]
|
10
|
+
gem.description = %q{A friendly Ruby interface to the Etsy API}
|
11
|
+
gem.summary = %q{Provides a friendly ruby-like wrapper for the Etsy API}
|
12
|
+
gem.homepage = "http://github.com/kytrinyx/etsy"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.name = "etsy"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = "0.2.1"
|
20
|
+
|
21
|
+
if gem.respond_to? :specification_version then
|
22
|
+
gem.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
gem.add_runtime_dependency("json", [">= 1.5.0"])
|
26
|
+
gem.add_runtime_dependency("oauth", ["~> 0.4.0"])
|
27
|
+
else
|
28
|
+
gem.add_dependency("json", [">= 1.5.0"])
|
29
|
+
gem.add_dependency("oauth", ["~> 0.4.0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
gem.add_dependency("json", [">= 1.5.0"])
|
33
|
+
gem.add_dependency("oauth", ["~> 0.4.0"])
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/etsy.rb
CHANGED
@@ -3,6 +3,7 @@ $:.unshift File.dirname(__FILE__)
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
5
|
require 'oauth'
|
6
|
+
require 'uri'
|
6
7
|
|
7
8
|
require 'etsy/request'
|
8
9
|
require 'etsy/response'
|
@@ -13,9 +14,17 @@ require 'etsy/verification_request'
|
|
13
14
|
|
14
15
|
require 'etsy/model'
|
15
16
|
require 'etsy/user'
|
17
|
+
require 'etsy/profile'
|
16
18
|
require 'etsy/shop'
|
17
19
|
require 'etsy/listing'
|
18
20
|
require 'etsy/image'
|
21
|
+
require 'etsy/transaction'
|
22
|
+
require 'etsy/address'
|
23
|
+
require 'etsy/category'
|
24
|
+
require 'etsy/payment_template'
|
25
|
+
require 'etsy/country'
|
26
|
+
require 'etsy/shipping_template'
|
27
|
+
require 'etsy/section'
|
19
28
|
|
20
29
|
# = Etsy: A friendly Ruby interface to the Etsy API
|
21
30
|
#
|
@@ -55,8 +64,12 @@ module Etsy
|
|
55
64
|
class << self
|
56
65
|
attr_accessor :api_key, :api_secret
|
57
66
|
attr_writer :callback_url
|
67
|
+
attr_writer :permission_scopes
|
58
68
|
end
|
59
69
|
|
70
|
+
SANDBOX_HOST = 'sandbox.openapi.etsy.com'
|
71
|
+
PRODUCTION_HOST = 'openapi.etsy.com'
|
72
|
+
|
60
73
|
# Set the environment, accepts either :sandbox or :production. Defaults to :sandbox
|
61
74
|
# and will raise an exception when set to an unrecognized environment.
|
62
75
|
#
|
@@ -65,6 +78,7 @@ module Etsy
|
|
65
78
|
raise(ArgumentError, "environment must be set to either :sandbox or :production")
|
66
79
|
end
|
67
80
|
@environment = environment
|
81
|
+
@host = (environment == :sandbox) ? SANDBOX_HOST : PRODUCTION_HOST
|
68
82
|
end
|
69
83
|
|
70
84
|
# The currently configured environment.
|
@@ -73,20 +87,8 @@ module Etsy
|
|
73
87
|
@environment || :sandbox
|
74
88
|
end
|
75
89
|
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
def self.access_mode=(mode)
|
80
|
-
unless [:read_only, :read_write].include?(mode)
|
81
|
-
raise(ArgumentError, "access mode must be set to either :read_only or :read_write")
|
82
|
-
end
|
83
|
-
@access_mode = mode
|
84
|
-
end
|
85
|
-
|
86
|
-
# The currently configured access mode
|
87
|
-
#
|
88
|
-
def self.access_mode
|
89
|
-
@access_mode || :read_only
|
90
|
+
def self.host # :nodoc:
|
91
|
+
@host || SANDBOX_HOST
|
90
92
|
end
|
91
93
|
|
92
94
|
# The configured callback URL or 'oob' if no callback URL is configured. This controls
|
@@ -96,6 +98,12 @@ module Etsy
|
|
96
98
|
@callback_url || 'oob'
|
97
99
|
end
|
98
100
|
|
101
|
+
# OAuth permission scopes. Defines which private fields we can have access to.
|
102
|
+
#
|
103
|
+
def self.permission_scopes
|
104
|
+
@permission_scopes || []
|
105
|
+
end
|
106
|
+
|
99
107
|
# Find a user by username. See Etsy::User for more information.
|
100
108
|
#
|
101
109
|
def self.user(username)
|
@@ -105,13 +113,14 @@ module Etsy
|
|
105
113
|
# Convenience method for accessing the authenticated user's own user information. Requires
|
106
114
|
# authentication.
|
107
115
|
#
|
108
|
-
def self.myself(token, secret)
|
109
|
-
User.myself(token, secret)
|
116
|
+
def self.myself(token, secret, options = {})
|
117
|
+
User.myself(token, secret, options)
|
110
118
|
end
|
111
119
|
|
112
120
|
# Generate a request token for authorization.
|
113
121
|
#
|
114
122
|
def self.request_token
|
123
|
+
clear_for_new_authorization
|
115
124
|
verification_request.request_token
|
116
125
|
end
|
117
126
|
|
@@ -119,7 +128,7 @@ module Etsy
|
|
119
128
|
# either be passed manually or from the params in the callback URL.
|
120
129
|
#
|
121
130
|
def self.access_token(request_token, request_secret, verifier)
|
122
|
-
@access_token
|
131
|
+
@access_token = begin
|
123
132
|
client = Etsy::SecureClient.new({
|
124
133
|
:request_token => request_token,
|
125
134
|
:request_secret => request_secret,
|
@@ -135,9 +144,29 @@ module Etsy
|
|
135
144
|
verification_request.url
|
136
145
|
end
|
137
146
|
|
147
|
+
def self.single_user(access_token, access_secret)
|
148
|
+
@credentials = {
|
149
|
+
:access_token => access_token,
|
150
|
+
:access_secret => access_secret
|
151
|
+
}
|
152
|
+
nil
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.credentials
|
156
|
+
@credentials || {}
|
157
|
+
end
|
158
|
+
|
138
159
|
private
|
139
160
|
|
140
161
|
def self.verification_request
|
141
162
|
@verification_request ||= VerificationRequest.new
|
142
163
|
end
|
164
|
+
|
165
|
+
def self.clear_for_new_authorization
|
166
|
+
@verification_request = nil
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.deprecate(message)
|
170
|
+
puts "DEPRECATED: #{message}."
|
171
|
+
end
|
143
172
|
end
|