lib/etsy.rb in etsy-0.2.6 vs lib/etsy.rb in etsy-0.2.7

- old
+ new

@@ -65,24 +65,28 @@ class << self attr_writer :callback_url attr_writer :permission_scopes end - # Make Etsy.api_key and Etsy.api_secret thread safe + # Make Etsy.api_key and Etsy.api_secret global but also local to threads # def self.api_key - Thread.current[:etsy_api_key] + Thread.current[:etsy_api_key] || @api_key end - def self.api_key=(val) - Thread.current[:etsy_api_key] = val + def self.api_key=(key) + @api_key ||= key + Thread.current[:etsy_api_key] = key end + def self.api_secret - Thread.current[:etsy_api_secret] + Thread.current[:etsy_api_secret] || @api_secret end - def self.api_secret=(val) - Thread.current[:etsy_api_secret] = val + + def self.api_secret=(secret) + @api_secret ||= secret + Thread.current[:etsy_api_secret] = secret end SANDBOX_HOST = 'sandbox.openapi.etsy.com' PRODUCTION_HOST = 'openapi.etsy.com' @@ -102,21 +106,36 @@ raise(ArgumentError, "protocol must be set to either 'http' or 'https'") end @protocol = protocol.to_s end + # Allow throwing API errors + # + 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 + def self.protocol @protocol || "https" end # The currently configured environment. # def self.environment - @environment || :sandbox + @environment || :production end + # The default will change to false for a 1.0 release (breaking changes) + # + def self.silent_errors + @silent_errors.nil? ? true : @silent_errors + end + def self.host # :nodoc: - @host || SANDBOX_HOST + @host || PRODUCTION_HOST end # 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. #