Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

integrating confiture gem

  • Loading branch information...
commit b92744ef5b47a332cbb90e28e16695989fe519ed 1 parent 4fdf0a2
@phoet authored
View
20 Gemfile.lock
@@ -1,17 +1,18 @@
PATH
remote: .
specs:
- asin (0.7.0)
+ asin (0.8.0)
+ confiture (~> 0.1)
crack (~> 0.3)
hashie (~> 1.1)
httpi (~> 0.9)
- jruby-openssl
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.6)
- bouncy-castle-java (1.5.0146.1)
+ coderay (1.0.7)
+ confiture (0.1.0)
crack (0.3.1)
diff-lcs (1.1.3)
fuubar (0.0.6)
@@ -20,11 +21,14 @@ GEM
ruby-progressbar (~> 0.0.10)
hashie (1.1.0)
httpclient (2.2.3)
- httpi (0.9.5)
+ httpi (0.9.7)
rack
- jruby-openssl (0.7.4)
- bouncy-castle-java
- rack (1.3.5)
+ method_source (0.7.1)
+ pry (0.9.9.6)
+ coderay (~> 1.0.5)
+ method_source (~> 0.7.1)
+ slop (>= 2.4.4, < 3)
+ rack (1.4.1)
rake (0.9.2.2)
rash (0.3.1)
hashie (~> 1.1.0)
@@ -38,6 +42,7 @@ GEM
rspec-instafail (0.1.9)
rspec-mocks (2.7.0)
ruby-progressbar (0.0.10)
+ slop (2.4.4)
vcr (1.11.3)
webmock (1.7.7)
addressable (~> 2.2, > 2.2.5)
@@ -51,6 +56,7 @@ DEPENDENCIES
asin!
fuubar (~> 0.0.5)
httpclient (~> 2.2.3)
+ pry (~> 0.9.9)
rake (~> 0.9.2.2)
rash (~> 0.3.1)
rspec (~> 2.7.0)
View
8 asin.gemspec
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency('crack', '~> 0.3')
- s.add_dependency('hashie', '~> 1.1')
- s.add_dependency('httpi', '~> 0.9')
+ s.add_dependency('crack', '~> 0.3')
+ s.add_dependency('hashie', '~> 1.1')
+ s.add_dependency('httpi', '~> 0.9')
+ s.add_dependency('confiture', '~> 0.1')
s.add_runtime_dependency('jruby-openssl') if RUBY_PLATFORM == 'java'
@@ -33,4 +34,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('webmock', '~> 1.7.7')
s.add_development_dependency('rspec', '~> 2.7.0')
s.add_development_dependency('fuubar', '~> 0.0.5')
+ s.add_development_dependency('pry', '~> 0.9.9')
end
View
137 lib/asin/configuration.rb
@@ -1,70 +1,59 @@
-require "yaml"
-require 'logger'
+require "logger"
+require "confiture"
module ASIN
- class Configuration
- class << self
-
- attr_accessor :secret, :key, :host, :logger
- attr_accessor :item_type, :cart_type, :node_type
- attr_accessor :version, :associate_tag
- # 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[https://affiliate-program.amazon.com/gp/advertising/api/detail/api-changes.html].
- #
- # 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
- #
- def configure(options={})
- init_config
- if yml_path = options[:yaml] || options[: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
- options.each do |key, value|
- send(:"#{key}=", value)
- end
- end
- self
- end
+ # 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[https://affiliate-program.amazon.com/gp/advertising/api/detail/api-changes.html].
+ #
+ # 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
+ #
+ class Configuration
+ include Confiture::Configuration
+ confiture_allowed_keys(:secret, :key, :host, :version, :associate_tag, :logger, :item_type, :cart_type, :node_type)
+ confiture_defaults({
+ :secret => '',
+ :key => '',
+ :host => 'webservices.amazon.com',
+ :version => '2010-11-01',
+ :associate_tag => '',
+ :logger => Logger.new(STDERR),
+ :item_type => SimpleItem,
+ :cart_type => SimpleCart,
+ :node_type => SimpleNode,
+ })
+ class << self
# Checks if given credentials are valid and raises an error if not.
#
def validate_credentials!
@@ -72,34 +61,12 @@ def validate_credentials!
[: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
- # Resets configuration to defaults
- #
- def reset
- init_config(true)
- end
-
# Check if a key is set
#
def blank?(key)
val = self.send :key
val.nil? || val.empty?
end
-
- private()
-
- 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
end
end
end
View
2  lib/asin/version.rb
@@ -1,3 +1,3 @@
module ASIN
- VERSION = "0.7.0"
+ VERSION = "0.8.0"
end
View
2  spec/config_spec.rb
@@ -13,7 +13,7 @@ module ASIN
end
it "should fail with wrong configuration key" do
- lambda { @helper.configure :wrong => 'key' }.should raise_error(NoMethodError)
+ lambda { @helper.configure :wrong => 'key' }.should raise_error(ArgumentError)
end
it "should not override the configuration" do
View
6 spec/spec_helper.rb
@@ -1,9 +1,7 @@
-$:.unshift File.join(File.dirname(__FILE__),'..','..','lib')
-
require 'rspec'
require 'asin'
require 'asin/client' # is somehow needed for jruby
-require 'pp'
+require 'pry'
require 'httpclient'
require 'vcr'
require 'httpi'
@@ -33,7 +31,7 @@
config.before :each do
HTTPI.log = false
- ASIN::Configuration.reset
+ ASIN::Configuration.reset!
@helper = ASIN::Client.instance
@helper.configure :logger => nil
Please sign in to comment.
Something went wrong with that request. Please try again.