Class: ASIN::Configuration
- Inherits:
-
Object
- Object
- ASIN::Configuration
- Defined in:
- lib/asin/configuration.rb
Class Attribute Summary collapse
-
.associate_tag ⇒ Object
Returns the value of attribute associate_tag.
-
.cart_type ⇒ Object
Returns the value of attribute cart_type.
-
.host ⇒ Object
Returns the value of attribute host.
-
.item_type ⇒ Object
Returns the value of attribute item_type.
-
.key ⇒ Object
Returns the value of attribute key.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.node_type ⇒ Object
Returns the value of attribute node_type.
-
.secret ⇒ Object
Returns the value of attribute secret.
-
.version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.blank?(key) ⇒ Boolean
Check if a key is set.
-
.configure(options = {}) ⇒ Object
Rails initializer configuration.
- .init_config(force = false) ⇒ Object
-
.reset ⇒ Object
Resets configuration to defaults.
-
.validate_credentials! ⇒ Object
Checks if given credentials are valid and raises an error if not.
Class Attribute Details
.associate_tag ⇒ Object
Returns the value of attribute associate_tag.
10 11 12 |
# File 'lib/asin/configuration.rb', line 10 def associate_tag @associate_tag end |
.cart_type ⇒ Object
Returns the value of attribute cart_type.
9 10 11 |
# File 'lib/asin/configuration.rb', line 9 def cart_type @cart_type end |
.host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/asin/configuration.rb', line 8 def host @host end |
.item_type ⇒ Object
Returns the value of attribute item_type.
9 10 11 |
# File 'lib/asin/configuration.rb', line 9 def item_type @item_type end |
.key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/asin/configuration.rb', line 8 def key @key end |
.logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/asin/configuration.rb', line 8 def logger @logger end |
.node_type ⇒ Object
Returns the value of attribute node_type.
9 10 11 |
# File 'lib/asin/configuration.rb', line 9 def node_type @node_type end |
.secret ⇒ Object
Returns the value of attribute secret.
8 9 10 |
# File 'lib/asin/configuration.rb', line 8 def secret @secret end |
.version ⇒ Object
Returns the value of attribute version.
10 11 12 |
# File 'lib/asin/configuration.rb', line 10 def version @version end |
Class Method Details
.blank?(key) ⇒ Boolean
Check if a key is set
83 84 85 86 |
# File 'lib/asin/configuration.rb', line 83 def blank?(key) val = self.send :key val.nil? || val.empty? end |
.configure(options = {}) ⇒ Object
Rails initializer configuration.
Expects at least secret
and key
for the API call:
ASIN::Configuration.configure do |config|
config.secret = 'your-secret'
config.key = 'your-key'
end
With the latest version of the Product Advertising API you need to include your associate_tag.
You may pass options as a hash as well:
ASIN::Configuration.configure :secret => 'your-secret', :key => 'your-key'
Or configure everything using YAML:
ASIN::Configuration.configure :yaml => 'config/asin.yml'
ASIN::Configuration.configure :yaml => 'config/asin.yml' do |config, yml|
config.key = yml[Rails.env]['aws_access_key']
end
Options:
- secret
-
the API secret key (required)
- key
-
the API access key (required)
- associate_tag
-
your Amazon associate tag. Default is blank (required in latest API version)
- host
-
the host, which defaults to ‘webservices.amazon.com’
- logger
-
a different logger than logging to STDERR (nil for no logging)
- version
-
a custom version of the API calls. Default is 2010-11-01
- item_type
-
a different class for SimpleItem, use :mash / :rash for Hashie::Mash / Hashie::Rash or :raw for a plain hash
- cart_type
-
a different class for SimpleCart, use :mash / :rash for Hashie::Mash / Hashie::Rash or :raw for a plain hash
- node_type
-
a different class for SimpleNode, use :mash / :rash for Hashie::Mash / Hashie::Rash or :raw for a plain hash
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/asin/configuration.rb', line 47 def configure(={}) init_config if yml_path = [:yaml] || [:yml] yml = File.open(yml_path) { |file| YAML.load(file) } if block_given? yield self, yml else yml.each do |key, value| send(:"#{key}=", value) end end elsif block_given? yield self else .each do |key, value| send(:"#{key}=", value) end end self end |
.init_config(force = false) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/asin/configuration.rb', line 90 def init_config(force=false) return if @init && !force @init = true @secret = '' @key = '' @host = 'webservices.amazon.com' @logger = Logger.new(STDERR) @item_type = SimpleItem @cart_type = SimpleCart @node_type = SimpleNode @version = '2010-11-01' @associate_tag = '' end |
.reset ⇒ Object
Resets configuration to defaults
77 78 79 |
# File 'lib/asin/configuration.rb', line 77 def reset init_config(true) end |
.validate_credentials! ⇒ Object
Checks if given credentials are valid and raises an error if not.
70 71 72 73 |
# File 'lib/asin/configuration.rb', line 70 def validate_credentials! raise "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key'" if blank?(:secret) || blank?(:key) [:host, :item_type, :cart_type, :node_type, :version, :associate_tag].each { |item| raise "nil is not a valid value for #{item}" unless self.send item } end |