Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
phoet committed Jun 11, 2012
0 parents commit 2111b2e
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .document
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/**/*.rb
README.rdoc
CHANGELOG.rdoc
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
html
pkg
*.gem
.DS_Store
.bundle
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
rvm use 1.9.3@confiture --create
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
script: "bundle exec rake"
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- rbx
- rbx-2.0
- ree
- ruby-head
- jruby
3 changes: 3 additions & 0 deletions CHANGELOG.rdoc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
== 0.0.1

* initial version
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gemspec
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
PATH
remote: .
specs:
confiture (0.0.1)

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.3)
rake (0.9.2.2)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)

PLATFORMS
java
ruby

DEPENDENCIES
confiture!
rake (~> 0.9.2.2)
rspec (~> 2.7.0)
51 changes: 51 additions & 0 deletions README.rdoc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,51 @@
== Infos

Status: http://stillmaintained.com/phoet/asin.png
Build: http://travis-ci.org/phoet/asin.png


== Installation

gem install confiture

or in your Gemfile:

gem "confiture"

== Usage

Rails style initializer (config/initializers/asin.rb):

ASIN::Configuration.configure do |config|
config.secret = 'your-secret'
config.key = 'your-key'
end

YAML style configuration:

ASIN::Configuration.configure :yaml => 'config/asin.yml'

Inline style configuration:

ASIN::Configuration.configure :secret => 'your-secret', :key => 'your-key'
# or
client.configure :secret => 'your-secret', :key => 'your-key'

Have a look at ASIN::Configuration class for all the details.

===API Changes

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].

ASIN::Configuration.configure do |config|
config.secret = 'your-secret'
config.key = 'your-key'
config.associate_tag = 'your-tag'
end

== License

"THE BEER-WARE LICENSE" (Revision 42):
ps@nofail.de[mailto:ps@nofail.de] wrote this file. As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy me a beer in return Peter Schröder
23 changes: 23 additions & 0 deletions confiture.gemspec
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "confiture/version"

Gem::Specification.new do |s|
s.name = "confiture"
s.version = Confiture::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Peter Schröder']
s.email = ['phoetmail@googlemail.com']
s.homepage = 'http://github.com/phoet/confiture'
s.summary = s.description = 'Confiture helps with configuring your gem.'

s.rubyforge_project = "confiture"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_development_dependency('rake', '~> 0.9.2.2')
s.add_development_dependency('rspec', '~> 2.7.0')
end
4 changes: 4 additions & 0 deletions lib/confiture.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
module Confiture
require 'confiture/version'
require 'confiture/configuration'
end
89 changes: 89 additions & 0 deletions lib/confiture/configuration.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,89 @@
require "yaml"
require 'logger'

module Confiture
class Configuration
class << self

attr_accessor :secret, :key

# 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

# 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 = ''
end
end
end
end
3 changes: 3 additions & 0 deletions lib/confiture/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
module Confiture
VERSION = "0.0.1"
end
11 changes: 11 additions & 0 deletions rakefile.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
require "bundler"
require "rspec/core/rake_task"

Bundler::GemHelper.install_tasks

RSpec::Core::RakeTask.new do |t|
t.rspec_opts = ["--color"]
t.pattern = 'spec/**/*_spec.rb'
end

task :default => :spec
2 changes: 2 additions & 0 deletions spec/config.yml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
secret: 'secret_yml'
key: 'key_yml'
33 changes: 33 additions & 0 deletions spec/config_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

module Confiture
describe Confiture do
context "configuration" do
it "should fail with wrong configuration key" do
lambda { @helper.configure :wrong => 'key' }.should raise_error(NoMethodError)
end

it "should work with a configuration block" do
conf = Confiture::Configuration.configure do |config|
config.key = 'bla'
end
conf.key.should eql('bla')
end

it "should read configuration from yml" do
config = Confiture::Configuration.configure :yaml => 'spec/config.yml'
config.secret.should eql('secret_yml')
config.key.should eql('key_yml')
end

it "should read configuration from yml with block" do
conf = Confiture::Configuration.configure :yaml => 'spec/config.yml' do |config, yml|
config.secret = nil
config.key = yml['secret']
end
conf.secret.should be_nil
conf.key.should eql('secret_yml')
end
end
end
end
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
$:.unshift File.join(File.dirname(__FILE__),'..','..','lib')

require 'rspec'
require 'confiture'
require 'pp'

RSpec.configure do |config|
config.mock_with :rspec
config.treat_symbols_as_metadata_keys_with_true_values = true
end

0 comments on commit 2111b2e

Please sign in to comment.