From 49f2968f4a460994d4d31294b16383932b76f651 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Tue, 2 Jun 2015 14:36:20 +0200 Subject: [PATCH 1/4] Allow you to pass savon client configuration options --- README.md | 11 ++++++++--- lib/mindbody-api.rb | 3 ++- lib/mindbody-api/client.rb | 7 ++++++- spec/client_spec.rb | 3 +++ spec/mindbody_spec.rb | 2 ++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b8fe77e..971b759 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,16 @@ Alternatively, you may set them in an initializer: config.site_ids = -99 config.source_key = 'abcd1234' config.source_name = 'SuperFoo' - config.log_level = :info # Savon logging level. Default is :debug, options are [:debug, :info, :warn, :error, :fatal] + config.savon_globals[:log_level] = :info # Savon logging level. Default is :debug, options are [:debug, :info, :warn, :error, :fatal] + config.savon_globals[:filters] = ['Password'] + # Enable as you see fit + # See http://savonrb.com/version2/globals.html for more information settings. + #config.savon_globals[:read_timeout] = 0 + #config.savon_globals[:open_timeout] = 0 + #config.savon_globals[:pretty_print_xml] = true + #config.savon_globals[:log] = true end -See http://savonrb.com/version2/globals.html for more information on the logging -setting. ## Usage diff --git a/lib/mindbody-api.rb b/lib/mindbody-api.rb index ef100cb..0ffb833 100644 --- a/lib/mindbody-api.rb +++ b/lib/mindbody-api.rb @@ -18,10 +18,11 @@ def configuration end class Config - attr_accessor :log_level, :open_timeout, :read_timeout, :source_name, :source_key, :site_ids + attr_accessor :log_level, :source_name, :source_key, :site_ids, :open_timeout, :read_timeout, :savon_globals def initialize @log_level = :debug + @savon_globals = {} @source_name = ENV['MINDBODY_SOURCE_NAME'] || '' @source_key = ENV['MINDBODY_SOURCE_KEY'] || '' @site_ids = (ENV['MINDBODY_SITE_IDS'] || '').scan(/-?\d+/).map(&:to_i) diff --git a/lib/mindbody-api/client.rb b/lib/mindbody-api/client.rb index 6d17444..c55b583 100644 --- a/lib/mindbody-api/client.rb +++ b/lib/mindbody-api/client.rb @@ -7,9 +7,14 @@ class Client < Savon::Client def call(operation_name, locals = {}, &block) # Inject the auth params into the request and setup the # correct request structure + @globals.log_level(MindBody.configuration.log_level) @globals.open_timeout(MindBody.configuration.open_timeout) @globals.read_timeout(MindBody.configuration.read_timeout) - @globals.log_level(MindBody.configuration.log_level) + #Allow you to override Savon global properties + MindBody.configuration.savon_globals.each do |key, value| + @globals.send(key, value) + end + locals = locals.has_key?(:message) ? locals[:message] : locals locals = fixup_locals(locals) params = {:message => {'Request' => auth_params.merge(locals)}} diff --git a/spec/client_spec.rb b/spec/client_spec.rb index e6e22de..6b95d86 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -7,6 +7,9 @@ creds.stub(:source_name).and_return('test') creds.stub(:source_key).and_return('test_key') creds.stub(:site_ids).and_return([-99]) + creds.stub(:open_timeout).and_return(0) + creds.stub(:read_timeout).and_return(0) + creds.stub(:savon_globals).and_return({log: false}) MindBody.stub(:configuration).and_return(creds) @client = MindBody::Services::Client.new(:wsdl => 'spec/fixtures/wsdl/geotrust.wsdl') diff --git a/spec/mindbody_spec.rb b/spec/mindbody_spec.rb index 57c2770..8a29ba4 100644 --- a/spec/mindbody_spec.rb +++ b/spec/mindbody_spec.rb @@ -30,6 +30,7 @@ it { should respond_to(:source_name) } it { should respond_to(:source_key) } it { should respond_to(:site_ids) } + it { should respond_to(:savon_globals) } end describe '#new' do @@ -39,6 +40,7 @@ expect(@config.source_name).to eq('') expect(@config.source_key).to eq('') expect(@config.site_ids).to eq([]) + expect(@config.savon_globals).to eq({}) end it 'should load config data from ENV' do From 57e494ed7fc5d1bac760a06239bf41811269d2a7 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Wed, 3 Jun 2015 11:06:04 +0200 Subject: [PATCH 2/4] Change configruation api to pass every thing to savon --- README.md | 14 ++++++------ lib/mindbody-api.rb | 26 +++++++++++----------- lib/mindbody-api/client.rb | 10 ++++----- lib/mindbody-api/services/class_service.rb | 2 ++ spec/client_spec.rb | 6 ++--- spec/mindbody_spec.rb | 4 ++-- 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 971b759..4ab4362 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ Alternatively, you may set them in an initializer: config.site_ids = -99 config.source_key = 'abcd1234' config.source_name = 'SuperFoo' - config.savon_globals[:log_level] = :info # Savon logging level. Default is :debug, options are [:debug, :info, :warn, :error, :fatal] - config.savon_globals[:filters] = ['Password'] + config.log_level = :info # Savon logging level. Default is :debug, options are [:debug, :info, :warn, :error, :fatal] + config.filters = ['Password'] # Enable as you see fit # See http://savonrb.com/version2/globals.html for more information settings. - #config.savon_globals[:read_timeout] = 0 - #config.savon_globals[:open_timeout] = 0 - #config.savon_globals[:pretty_print_xml] = true - #config.savon_globals[:log] = true + #config.read_timeout = 0 + #config.open_timeout] = 0 + #config.pretty_print_xml = true + #config.log = true end @@ -80,5 +80,5 @@ See the various [issues](https://github.com/wingrunr21/mindbody-api/issues?state This gem is written by [Stafford Brunk](https://github.com/wingrunr21) -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/wingrunr21/mindbody-api/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/wingrunr21/mindbody-api/trend.png)](https://bitdeli.com/free "Bitdeli Badge") [![Build Status](https://travis-ci.org/wingrunr21/mindbody-api.png)](https://travis-ci.org/wingrunr21/mindbody-api) diff --git a/lib/mindbody-api.rb b/lib/mindbody-api.rb index 0ffb833..f7ef3a5 100644 --- a/lib/mindbody-api.rb +++ b/lib/mindbody-api.rb @@ -17,20 +17,20 @@ def configuration end end - class Config - attr_accessor :log_level, :source_name, :source_key, :site_ids, :open_timeout, :read_timeout, :savon_globals + class Config < OpenStruct - def initialize - @log_level = :debug - @savon_globals = {} - @source_name = ENV['MINDBODY_SOURCE_NAME'] || '' - @source_key = ENV['MINDBODY_SOURCE_KEY'] || '' - @site_ids = (ENV['MINDBODY_SITE_IDS'] || '').scan(/-?\d+/).map(&:to_i) - end - - # Make sure site_ids is always an Array - def site_ids=(ids) - @site_ids = [*ids] + def initialize() + defaults = + { + log_level: :debug, + source_name: ENV['MINDBODY_SOURCE_NAME'] || '', + source_key: ENV['MINDBODY_SOURCE_KEY'] || '', + site_ids: (ENV['MINDBODY_SITE_IDS'] || '').scan(/-?\d+/).map(&:to_i), + filters: ['Password'] + } + super(defaults) + # Override site_id to make sure its always an array + define_singleton_method("site_ids=") { |x| modifiable[:site_ids] = [*x] } end end end diff --git a/lib/mindbody-api/client.rb b/lib/mindbody-api/client.rb index c55b583..85cf657 100644 --- a/lib/mindbody-api/client.rb +++ b/lib/mindbody-api/client.rb @@ -6,13 +6,11 @@ class Client < Savon::Client def call(operation_name, locals = {}, &block) # Inject the auth params into the request and setup the - # correct request structure - @globals.log_level(MindBody.configuration.log_level) - @globals.open_timeout(MindBody.configuration.open_timeout) - @globals.read_timeout(MindBody.configuration.read_timeout) #Allow you to override Savon global properties - MindBody.configuration.savon_globals.each do |key, value| - @globals.send(key, value) + MindBody.configuration.to_h.each do |key, value| + if @globals.respond_to?(key) + @globals.send(key, value) + end end locals = locals.has_key?(:message) ? locals[:message] : locals diff --git a/lib/mindbody-api/services/class_service.rb b/lib/mindbody-api/services/class_service.rb index 63ffbaf..2abacb4 100644 --- a/lib/mindbody-api/services/class_service.rb +++ b/lib/mindbody-api/services/class_service.rb @@ -7,6 +7,8 @@ class ClassService < Service operation :get_class_visits, required:[:class_id] operation :get_class_descriptions operation :get_class_schedules + operation :add_clients_to_enrollments + operation :add_clients_to_classes end end end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 6b95d86..f6e8c00 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -3,13 +3,11 @@ describe MindBody::Services::Client do before do creds = double('credentials') - creds.stub(:log_level).and_return(:debug) creds.stub(:source_name).and_return('test') creds.stub(:source_key).and_return('test_key') creds.stub(:site_ids).and_return([-99]) - creds.stub(:open_timeout).and_return(0) - creds.stub(:read_timeout).and_return(0) - creds.stub(:savon_globals).and_return({log: false}) + #Savon options + creds.stub(:to_h).and_return({open_timeout: 0, read_timeout: 0}) MindBody.stub(:configuration).and_return(creds) @client = MindBody::Services::Client.new(:wsdl => 'spec/fixtures/wsdl/geotrust.wsdl') diff --git a/spec/mindbody_spec.rb b/spec/mindbody_spec.rb index 8a29ba4..7b24387 100644 --- a/spec/mindbody_spec.rb +++ b/spec/mindbody_spec.rb @@ -30,7 +30,8 @@ it { should respond_to(:source_name) } it { should respond_to(:source_key) } it { should respond_to(:site_ids) } - it { should respond_to(:savon_globals) } + # Savon global options + it { should respond_to(:filters) } end describe '#new' do @@ -40,7 +41,6 @@ expect(@config.source_name).to eq('') expect(@config.source_key).to eq('') expect(@config.site_ids).to eq([]) - expect(@config.savon_globals).to eq({}) end it 'should load config data from ENV' do From 8872ff3f74caba904ddeb41fb402c62ff57ea3b3 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Wed, 3 Jun 2015 11:13:27 +0200 Subject: [PATCH 3/4] Adding tests for service calls --- spec/services/class_service_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/services/class_service_spec.rb b/spec/services/class_service_spec.rb index 08a94e8..f47db16 100644 --- a/spec/services/class_service_spec.rb +++ b/spec/services/class_service_spec.rb @@ -7,4 +7,6 @@ it { should respond_to(:get_class_visits) } it { should respond_to(:get_class_descriptions) } it { should respond_to(:get_class_schedules) } + it { should respond_to(:add_clients_to_enrollments) } + it { should respond_to(:add_clients_to_classes)} end From e285dcd690a6c8eebfdacbcca7175b6a46e3acc3 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Thu, 4 Jun 2015 16:06:55 +0200 Subject: [PATCH 4/4] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ab4362..feb3294 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Alternatively, you may set them in an initializer: # Enable as you see fit # See http://savonrb.com/version2/globals.html for more information settings. #config.read_timeout = 0 - #config.open_timeout] = 0 + #config.open_timeout = 0 #config.pretty_print_xml = true #config.log = true end