Permalink
Browse files

Merge pull request #3 from paloc/master

Options bug fix and reorganization
  • Loading branch information...
2 parents 7aa1ca4 + ed4ec1a commit fcecc748fe40f1c212f00243485516695fd59691 @lapluviosilla lapluviosilla committed Dec 2, 2011
Showing with 25 additions and 15 deletions.
  1. +24 −14 lib/simple_crowd.rb
  2. +1 −1 lib/simple_crowd/client.rb
View
@@ -1,5 +1,6 @@
require 'savon'
require 'hashie'
+require 'yaml'
require 'forwardable'
require 'simple_crowd/crowd_entity'
require 'simple_crowd/crowd_error'
@@ -14,16 +15,13 @@ class << self
def config &config_block
config_block.call(options)
end
- # SimpleCrowd default options
- def options
- @options ||= {
- :service_url => "http://localhost:8095/crowd/",
- :app_name => "crowd",
- :app_password => ""
- }
+
+ def options app_options = {}
+ c = soap_options.merge(default_crowd_options).merge(app_options) and
+ c.merge(:service_url => c[:service_url] + 'services/SecurityServer')
end
- def soap_options base_options = self.options
- @soap_options ||= base_options.merge({
+ def soap_options
+ @soap_options ||= {
:service_ns => "urn:SecurityServer",
:service_namespaces => {
'xmlns:auth' => 'http://authentication.integration.crowd.atlassian.com',
@@ -32,10 +30,22 @@ def soap_options base_options = self.options
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
}
- })
- @soap_options.merge!({:service_url => base_options[:service_url] + 'services/SecurityServer'})
+ }
+ end
+ def default_crowd_options
+ @default_crowd_options ||= {
+ :service_url => "http://localhost:8095/crowd/",
+ :app_name => "crowd",
+ :app_password => ""
+ }
+ defined?(IRB) ? @default_crowd_options.merge(config_file_options) : @default_crowd_options
+ end
+ def config_file_options
+ @config_file_options ||= begin
+ (File.exists?('config/crowd.yml') &&
+ yml = (YAML.load_file('config/crowd.yml')[ENV["RAILS_ENV"] || "development"] || {}) and
+ yml.symbolize_keys!) || {}
+ end
end
end
-end
-
-
+end
@@ -1,7 +1,7 @@
module SimpleCrowd
class Client
def initialize options = {}
- @options = SimpleCrowd.soap_options SimpleCrowd.options.merge(options)
+ @options = SimpleCrowd.options options
# TODO: Fix error handling
# Errors do not contained Exception info so we'll handle the errors ourselves

0 comments on commit fcecc74

Please sign in to comment.