Module: Etsy
- Defined in:
- lib/etsy.rb,
lib/etsy/shop.rb,
lib/etsy/user.rb,
lib/etsy/image.rb,
lib/etsy/model.rb,
lib/etsy/address.rb,
lib/etsy/country.rb,
lib/etsy/listing.rb,
lib/etsy/profile.rb,
lib/etsy/request.rb,
lib/etsy/section.rb,
lib/etsy/version.rb,
lib/etsy/category.rb,
lib/etsy/response.rb,
lib/etsy/transaction.rb,
lib/etsy/basic_client.rb,
lib/etsy/secure_client.rb,
lib/etsy/favorite_listing.rb,
lib/etsy/payment_template.rb,
lib/etsy/shipping_template.rb,
lib/etsy/verification_request.rb
Overview
Etsy: A friendly Ruby interface to the Etsy API
Quick Start
Getting started is easy. First, you will need a valid API key from the Etsy developer site (developer.etsy.com/).
To start using the API, require the etsy gem and set it up to use your API key:
require 'rubygems'
require 'etsy'
Etsy.api_key = 'itsasecret'
Now you can make API calls that originate from an Etsy user:
# Find a user by username
user = Etsy.user('littletjane')
# Grab that user's shop information
user.shop
user.shop.title
# ... and the listings in the shop
listing = user.shop.listings.first
listing.title
listing.description
To see what else is available for a user, check out the full documentation for the Etsy::User class. Information about making authenticated calls is available in the README.
Defined Under Namespace
Modules: Model Classes: Address, BasicClient, Category, Country, Error, EtsyJSONInvalid, ExceededRateLimit, FavoriteListing, Image, InvalidUserID, Listing, MissingShopID, OAuthTokenRevoked, PaymentTemplate, Profile, Request, ResourceUnavailable, Response, Section, SecureClient, ShippingTemplate, Shop, TemporaryIssue, Transaction, User, VerificationRequest
Constant Summary collapse
- SANDBOX_HOST =
'sandbox.openapi.etsy.com'
- PRODUCTION_HOST =
'openapi.etsy.com'
- VERSION =
"0.2.6"
Class Attribute Summary collapse
-
.callback_url ⇒ Object
The configured callback URL or ‘oob’ if no callback URL is configured.
-
.permission_scopes ⇒ Object
OAuth permission scopes.
Class Method Summary collapse
-
.access_token(request_token, request_secret, verifier) ⇒ Object
Generate an access token from the request token, secret, and verifier.
-
.api_key ⇒ Object
Make Etsy.api_key and Etsy.api_secret thread safe.
- .api_key=(val) ⇒ Object
- .api_secret ⇒ Object
- .api_secret=(val) ⇒ Object
- .credentials ⇒ Object
-
.environment ⇒ Object
The currently configured environment.
-
.environment=(environment) ⇒ Object
Set the environment, accepts either :sandbox or :production.
-
.host ⇒ Object
:nodoc:.
-
.myself(token, secret, options = {}) ⇒ Object
Convenience method for accessing the authenticated user’s own user information.
- .protocol ⇒ Object
- .protocol=(protocol) ⇒ Object
-
.request_token ⇒ Object
Generate a request token for authorization.
- .single_user(access_token, access_secret) ⇒ Object
-
.user(username) ⇒ Object
Find a user by username.
-
.verification_url ⇒ Object
Generate the URL to begin the verification process for a user.
Class Attribute Details
.callback_url ⇒ Object
The configured callback URL or ‘oob’ if no callback URL is configured. This controls whether or not we need to pass the OAuth verifier by hand.
124 125 126 |
# File 'lib/etsy.rb', line 124 def self.callback_url @callback_url || 'oob' end |
.permission_scopes ⇒ Object
OAuth permission scopes. Defines which private fields we can have access to.
130 131 132 |
# File 'lib/etsy.rb', line 130 def self. @permission_scopes || [] end |
Class Method Details
.access_token(request_token, request_secret, verifier) ⇒ Object
Generate an access token from the request token, secret, and verifier. The verifier can either be passed manually or from the params in the callback URL.
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/etsy.rb', line 157 def self.access_token(request_token, request_secret, verifier) @access_token = begin client = Etsy::SecureClient.new({ :request_token => request_token, :request_secret => request_secret, :verifier => verifier }) client.client end end |
.api_key ⇒ Object
Make Etsy.api_key and Etsy.api_secret thread safe
72 73 74 |
# File 'lib/etsy.rb', line 72 def self.api_key Thread.current[:etsy_api_key] end |
.api_key=(val) ⇒ Object
76 77 78 |
# File 'lib/etsy.rb', line 76 def self.api_key=(val) Thread.current[:etsy_api_key] = val end |
.api_secret ⇒ Object
79 80 81 |
# File 'lib/etsy.rb', line 79 def self.api_secret Thread.current[:etsy_api_secret] end |
.api_secret=(val) ⇒ Object
82 83 84 |
# File 'lib/etsy.rb', line 82 def self.api_secret=(val) Thread.current[:etsy_api_secret] = val end |
.credentials ⇒ Object
182 183 184 |
# File 'lib/etsy.rb', line 182 def self.credentials @credentials || {} end |
.environment ⇒ Object
The currently configured environment.
113 114 115 |
# File 'lib/etsy.rb', line 113 def self.environment @environment || :sandbox end |
.environment=(environment) ⇒ Object
Set the environment, accepts either :sandbox or :production. Defaults to :sandbox and will raise an exception when set to an unrecognized environment.
92 93 94 95 96 97 98 |
# File 'lib/etsy.rb', line 92 def self.environment=(environment) unless [:sandbox, :production].include?(environment) raise(ArgumentError, "environment must be set to either :sandbox or :production") end @environment = environment @host = (environment == :sandbox) ? SANDBOX_HOST : PRODUCTION_HOST end |
.host ⇒ Object
:nodoc:
117 118 119 |
# File 'lib/etsy.rb', line 117 def self.host # :nodoc: @host || SANDBOX_HOST end |
.myself(token, secret, options = {}) ⇒ Object
Convenience method for accessing the authenticated user’s own user information. Requires authentication.
143 144 145 |
# File 'lib/etsy.rb', line 143 def self.myself(token, secret, = {}) User.myself(token, secret, ) end |
.protocol ⇒ Object
107 108 109 |
# File 'lib/etsy.rb', line 107 def self.protocol @protocol || "https" end |
.protocol=(protocol) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/etsy.rb', line 100 def self.protocol=(protocol) unless ["http", "https"].include?(protocol.to_s) raise(ArgumentError, "protocol must be set to either 'http' or 'https'") end @protocol = protocol.to_s end |
.request_token ⇒ Object
Generate a request token for authorization.
149 150 151 152 |
# File 'lib/etsy.rb', line 149 def self.request_token verification_request.request_token end |
.single_user(access_token, access_secret) ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/etsy.rb', line 174 def self.single_user(access_token, access_secret) @credentials = { :access_token => access_token, :access_secret => access_secret } nil end |
.user(username) ⇒ Object
Find a user by username. See Etsy::User for more information.
136 137 138 |
# File 'lib/etsy.rb', line 136 def self.user(username) User.find(username) end |
.verification_url ⇒ Object
Generate the URL to begin the verification process for a user.
170 171 172 |
# File 'lib/etsy.rb', line 170 def self.verification_url verification_request.url end |