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/receipt.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, Receipt, 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.3.0"
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 global but also local to threads.
- .api_key=(key) ⇒ Object
- .api_secret ⇒ Object
- .api_secret=(secret) ⇒ 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.
-
.silent_errors ⇒ Object
The default will change to false for a 1.0 release (breaking changes).
-
.silent_errors=(bool) ⇒ Object
Allow throwing API errors.
- .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.
144 145 146 |
# File 'lib/etsy.rb', line 144 def self.callback_url @callback_url || 'oob' end |
.permission_scopes ⇒ Object
OAuth permission scopes. Defines which private fields we can have access to.
150 151 152 |
# File 'lib/etsy.rb', line 150 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.
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/etsy.rb', line 177 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 global but also local to threads
73 74 75 |
# File 'lib/etsy.rb', line 73 def self.api_key Thread.current[:etsy_api_key] || @api_key end |
.api_key=(key) ⇒ Object
77 78 79 80 |
# File 'lib/etsy.rb', line 77 def self.api_key=(key) @api_key ||= key Thread.current[:etsy_api_key] = key end |
.api_secret ⇒ Object
82 83 84 |
# File 'lib/etsy.rb', line 82 def self.api_secret Thread.current[:etsy_api_secret] || @api_secret end |
.api_secret=(secret) ⇒ Object
86 87 88 89 |
# File 'lib/etsy.rb', line 86 def self.api_secret=(secret) @api_secret ||= secret Thread.current[:etsy_api_secret] = secret end |
.credentials ⇒ Object
202 203 204 |
# File 'lib/etsy.rb', line 202 def self.credentials @credentials || {} end |
.environment ⇒ Object
The currently configured environment.
127 128 129 |
# File 'lib/etsy.rb', line 127 def self.environment @environment || :production 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.
97 98 99 100 101 102 103 |
# File 'lib/etsy.rb', line 97 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:
137 138 139 |
# File 'lib/etsy.rb', line 137 def self.host # :nodoc: @host || PRODUCTION_HOST end |
.myself(token, secret, options = {}) ⇒ Object
Convenience method for accessing the authenticated user’s own user information. Requires authentication.
163 164 165 |
# File 'lib/etsy.rb', line 163 def self.myself(token, secret, = {}) User.myself(token, secret, ) end |
.protocol ⇒ Object
121 122 123 |
# File 'lib/etsy.rb', line 121 def self.protocol @protocol || "https" end |
.protocol=(protocol) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/etsy.rb', line 105 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.
169 170 171 172 |
# File 'lib/etsy.rb', line 169 def self.request_token verification_request.request_token end |
.silent_errors ⇒ Object
The default will change to false for a 1.0 release (breaking changes)
133 134 135 |
# File 'lib/etsy.rb', line 133 def self.silent_errors @silent_errors.nil? ? true : @silent_errors end |
.silent_errors=(bool) ⇒ Object
Allow throwing API errors
114 115 116 117 118 119 |
# File 'lib/etsy.rb', line 114 def self.silent_errors=(bool) unless [TrueClass, FalseClass].include?(bool.class) raise(ArgumentError, "Silent errors must be set to either true or false'") end @silent_errors = bool end |
.single_user(access_token, access_secret) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/etsy.rb', line 194 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.
156 157 158 |
# File 'lib/etsy.rb', line 156 def self.user(username) User.find(username) end |
.verification_url ⇒ Object
Generate the URL to begin the verification process for a user.
190 191 192 |
# File 'lib/etsy.rb', line 190 def self.verification_url verification_request.url end |