Skip to content
Browse files

config via yaml file

  • Loading branch information...
1 parent 19549cc commit 3f5c67a5b631c82c114201fdb3d825d90584f5d3 @jzw jzw committed Sep 20, 2012
Showing with 29 additions and 25 deletions.
  1. +1 −0 .gitignore
  2. +25 −5 lib/powa_api.rb
  3. +0 −13 lib/powa_api/config.rb
  4. +3 −7 lib/powa_api/powa_service.rb
View
1 .gitignore
@@ -11,6 +11,7 @@ spec/reports
test/tmp
test/version_tmp
tmp
+*.yml
# YARD artifacts
.yardoc
View
30 lib/powa_api.rb
@@ -1,6 +1,6 @@
require 'savon'
+require 'yaml'
require 'powa_api/version'
-require 'powa_api/config'
require 'powa_api/powa_service'
require 'powa_api/product_service'
require 'powa_api/order_service'
@@ -9,12 +9,32 @@ module PowaApi
extend self
- def configure
- yield config
+ @config = {
+ :integration_security_key => "KEY-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
+ :website_authorisation_token => "TOKEN-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
+ :environment => "sandbox"
+ }
+
+ @valid_config_keys = @config.keys
+
+ def self.configure(opts = {})
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
+ end
+
+ def self.configure_with(path_to_yaml_file)
+ begin
+ config = YAML::load(IO.read(path_to_yaml_file))
+ rescue Errno::ENOENT
+ log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
+ rescue Psych::SyntaxError
+ log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
+ end
+
+ configure(config)
end
- def config
- @config ||= Config.default
+ def self.config
+ @config
end
end
View
13 lib/powa_api/config.rb
@@ -1,13 +0,0 @@
-module PowaApi
- Config = Struct.new(:environment, :integration_security_key, :website_authorisation_token) do
-
- def self.default
- config = new
- config.integration_security_key = "KEY-6b05827d-e9c4-4d86-9c45-92394dfadf62"
- config.website_authorisation_token = "TOKEN-03980096-5437-465a-8ce0-f6cd510c1f7a"
- config.environment = "sandbox"
- config
- end
-
- end
-end
View
10 lib/powa_api/powa_service.rb
@@ -1,10 +1,6 @@
module PowaApi
class PowaService
- def self.config
- Config.default
- end
-
def self.get_publish_info
client = Savon.client wsdl
@@ -32,7 +28,7 @@ def self.wsdl
end
def self.base_url
- if config.environment == "production"
+ if ::PowaApi.config[:environment] == "production"
"https://api.powa.com/ws/soap/v2/"
else
"https://api.sandbox.powa.com/ws/soap/v2/"
@@ -42,8 +38,8 @@ def self.base_url
def self.header_block(xml)
xml.soapenv(:Header) do |xml|
xml.urn(:Credentials) do |xml|
- xml.integrationSecurityKey config.integration_security_key
- xml.websiteAuthorisationToken config.website_authorisation_token
+ xml.integrationSecurityKey ::PowaApi.config[:integration_security_key]
+ xml.websiteAuthorisationToken ::PowaApi.config[:website_authorisation_token]
end
end
end

0 comments on commit 3f5c67a

Please sign in to comment.
Something went wrong with that request. Please try again.