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,
lib/etsy/variation/property_set.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, Variation 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.1"
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.
145 146 147 |
# File 'lib/etsy.rb', line 145 def self.callback_url @callback_url || 'oob' end |
.permission_scopes ⇒ Object
OAuth permission scopes. Defines which private fields we can have access to.
151 152 153 |
# File 'lib/etsy.rb', line 151 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.
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/etsy.rb', line 178 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
74 75 76 |
# File 'lib/etsy.rb', line 74 def self.api_key Thread.current[:etsy_api_key] || @api_key end |
.api_key=(key) ⇒ Object
78 79 80 81 |
# File 'lib/etsy.rb', line 78 def self.api_key=(key) @api_key ||= key Thread.current[:etsy_api_key] = key end |
.api_secret ⇒ Object
83 84 85 |
# File 'lib/etsy.rb', line 83 def self.api_secret Thread.current[:etsy_api_secret] || @api_secret end |
.api_secret=(secret) ⇒ Object
87 88 89 90 |
# File 'lib/etsy.rb', line 87 def self.api_secret=(secret) @api_secret ||= secret Thread.current[:etsy_api_secret] = secret end |
.credentials ⇒ Object
203 204 205 |
# File 'lib/etsy.rb', line 203 def self.credentials @credentials || {} end |
.environment ⇒ Object
The currently configured environment.
128 129 130 |
# File 'lib/etsy.rb', line 128 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.
98 99 100 101 102 103 104 |
# File 'lib/etsy.rb', line 98 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:
138 139 140 |
# File 'lib/etsy.rb', line 138 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.
164 165 166 |
# File 'lib/etsy.rb', line 164 def self.myself(token, secret, = {}) User.myself(token, secret, ) end |
.protocol ⇒ Object
122 123 124 |
# File 'lib/etsy.rb', line 122 def self.protocol @protocol || "https" end |
.protocol=(protocol) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/etsy.rb', line 106 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.
170 171 172 173 |
# File 'lib/etsy.rb', line 170 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)
134 135 136 |
# File 'lib/etsy.rb', line 134 def self.silent_errors @silent_errors.nil? ? true : @silent_errors end |
.silent_errors=(bool) ⇒ Object
Allow throwing API errors
115 116 117 118 119 120 |
# File 'lib/etsy.rb', line 115 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
195 196 197 198 199 200 201 |
# File 'lib/etsy.rb', line 195 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.
157 158 159 |
# File 'lib/etsy.rb', line 157 def self.user(username) User.find(username) end |
.verification_url ⇒ Object
Generate the URL to begin the verification process for a user.
191 192 193 |
# File 'lib/etsy.rb', line 191 def self.verification_url verification_request.url end |