-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2111b2e
Showing
16 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
lib/**/*.rb | |||
README.rdoc | |||
CHANGELOG.rdoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
html | |||
pkg | |||
*.gem | |||
.DS_Store | |||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
rvm use 1.9.3@confiture --create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
== 0.0.1 | |||
|
|||
* initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
source "http://rubygems.org" | |||
|
|||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
module Confiture | |||
VERSION = "0.0.1" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
secret: 'secret_yml' | |||
key: 'key_yml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |