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