forked from phoet/asin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rails initializer configuration style
- Loading branch information
Showing
3 changed files
with
78 additions
and
20 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module ASIN | ||
class Configuration | ||
class << self | ||
|
||
attr_accessor :secret, :key, :host, :logger | ||
|
||
# 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 | ||
# | ||
# ==== Options: | ||
# | ||
# [secret] the API secret key | ||
# [key] the API access key | ||
# [host] the host, which defaults to 'webservices.amazon.com' | ||
# [logger] a different logger than logging to STDERR | ||
# | ||
def configure(options={}) | ||
init_config | ||
if block_given? | ||
yield self | ||
else | ||
options.each do |key, value| | ||
send(:"#{key}=", value) | ||
end | ||
end | ||
self | ||
end | ||
|
||
private | ||
|
||
def init_config(force=false) | ||
return if @init && !force | ||
@init = true | ||
@secret = '' | ||
@key = '' | ||
@host = 'webservices.amazon.com' | ||
@logger = Logger.new(STDERR) | ||
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