From 49f2968f4a460994d4d31294b16383932b76f651 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Tue, 2 Jun 2015 14:36:20 +0200 Subject: [PATCH 1/6] 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/6] 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/6] 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 78f69c9fb11869107b584b8c55f9b9f8e787a749 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Thu, 4 Jun 2015 15:05:06 +0200 Subject: [PATCH 4/6] Add api for remove clients from classes --- lib/mindbody-api/services/class_service.rb | 1 + spec/services/client_service_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/mindbody-api/services/class_service.rb b/lib/mindbody-api/services/class_service.rb index 2abacb4..eae54b7 100644 --- a/lib/mindbody-api/services/class_service.rb +++ b/lib/mindbody-api/services/class_service.rb @@ -9,6 +9,7 @@ class ClassService < Service operation :get_class_schedules operation :add_clients_to_enrollments operation :add_clients_to_classes + operation :remove_clients_from_classes end end end diff --git a/spec/services/client_service_spec.rb b/spec/services/client_service_spec.rb index a07f304..a8b87a8 100644 --- a/spec/services/client_service_spec.rb +++ b/spec/services/client_service_spec.rb @@ -24,4 +24,5 @@ it { should respond_to(:validate_login) } it { should respond_to(:update_client_services) } it { should respond_to(:send_user_new_password) } + it { should respond_to(:remove_clients_from_classes)} end From 7a77988fda9ea76035f0decfe1dc7039132891fa Mon Sep 17 00:00:00 2001 From: David Rubin Date: Thu, 4 Jun 2015 15:55:17 +0200 Subject: [PATCH 5/6] Update wsdl files with latest ones --- wsdl/AppointmentService.wsdl | 11 +++ wsdl/ClassService.wsdl | 150 +++++++++++++++++++++++++++--- wsdl/ClientService.wsdl | 33 ++++--- wsdl/FinderService.wsdl | 171 ++++++++++++++++++----------------- wsdl/SaleService.wsdl | 147 ++++++++++++++++-------------- wsdl/SiteService.wsdl | 5 + wsdl/StaffService.wsdl | 31 ++++--- 7 files changed, 361 insertions(+), 187 deletions(-) diff --git a/wsdl/AppointmentService.wsdl b/wsdl/AppointmentService.wsdl index 09c7973..d82eb88 100644 --- a/wsdl/AppointmentService.wsdl +++ b/wsdl/AppointmentService.wsdl @@ -174,6 +174,8 @@ + + @@ -221,6 +223,7 @@ + @@ -264,7 +267,9 @@ + + @@ -321,6 +326,7 @@ + @@ -411,6 +417,7 @@ + @@ -548,6 +555,7 @@ + @@ -584,6 +592,8 @@ + + @@ -673,6 +683,7 @@ + diff --git a/wsdl/ClassService.wsdl b/wsdl/ClassService.wsdl index 1bc0247..3c724e8 100644 --- a/wsdl/ClassService.wsdl +++ b/wsdl/ClassService.wsdl @@ -174,6 +174,8 @@ + + @@ -219,6 +221,7 @@ + @@ -240,6 +243,7 @@ + @@ -304,7 +308,9 @@ + + @@ -352,18 +358,6 @@ - - - - - - - - - - - - @@ -423,6 +417,18 @@ + + + + + + + + + + + + @@ -457,6 +463,7 @@ + @@ -800,6 +807,8 @@ + + @@ -879,6 +888,7 @@ + @@ -954,6 +964,7 @@ + @@ -1115,6 +1126,7 @@ + @@ -1144,13 +1156,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1231,6 +1317,18 @@ + + + + + + + + + + + + Gets a list of classes. @@ -1297,6 +1395,16 @@ + + Substitutes the teacher for a class. + + + + + Cancels a single class instance. + + + @@ -1417,6 +1525,24 @@ + + + + + + + + + + + + + + + + + + Provides methods and attributes relating to classes and enrollments. diff --git a/wsdl/ClientService.wsdl b/wsdl/ClientService.wsdl index 3a6dc9e..9323249 100644 --- a/wsdl/ClientService.wsdl +++ b/wsdl/ClientService.wsdl @@ -141,6 +141,8 @@ + + @@ -150,6 +152,7 @@ + @@ -188,6 +191,7 @@ + @@ -221,6 +225,7 @@ + @@ -353,7 +358,9 @@ + + @@ -401,18 +408,6 @@ - - - - - - - - - - - - @@ -435,6 +430,7 @@ + @@ -485,6 +481,18 @@ + + + + + + + + + + + + @@ -1255,6 +1263,7 @@ + diff --git a/wsdl/FinderService.wsdl b/wsdl/FinderService.wsdl index f423a35..f916cda 100644 --- a/wsdl/FinderService.wsdl +++ b/wsdl/FinderService.wsdl @@ -156,6 +156,8 @@ + + @@ -257,6 +259,7 @@ + @@ -300,7 +303,9 @@ + + @@ -348,18 +353,6 @@ - - - - - - - - - - - - @@ -382,6 +375,7 @@ + @@ -394,6 +388,18 @@ + + + + + + + + + + + + @@ -428,6 +434,7 @@ + @@ -702,31 +709,31 @@ - + + - + - + - + - @@ -741,72 +748,72 @@ - + + + - + - - - - - - - - - - - - + + - + - - + - + - - + + + + + + + + + + + + - + - + - + - @@ -884,47 +891,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -967,6 +933,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wsdl/SaleService.wsdl b/wsdl/SaleService.wsdl index 7243217..aea9ab1 100644 --- a/wsdl/SaleService.wsdl +++ b/wsdl/SaleService.wsdl @@ -167,6 +167,8 @@ + + @@ -188,6 +190,8 @@ + + @@ -282,7 +286,9 @@ + + @@ -330,18 +336,6 @@ - - - - - - - - - - - - @@ -364,6 +358,7 @@ + @@ -392,6 +387,7 @@ + @@ -445,6 +441,18 @@ + + + + + + + + + + + + @@ -479,6 +487,7 @@ + @@ -754,25 +763,26 @@ - + - + + + + + + - - - - + + + + + - - - - - @@ -790,31 +800,30 @@ - - - - - - + - - - - - - + - - - - - + + + + + + + + + + + + + + @@ -830,31 +839,31 @@ - + + - + - + - + - @@ -869,72 +878,72 @@ - + + + - + - - - - - - - - - - - - + + - + - - + - + - - + + + + + + + + + + + + - + - + - + - diff --git a/wsdl/SiteService.wsdl b/wsdl/SiteService.wsdl index ec0cae5..291b757 100644 --- a/wsdl/SiteService.wsdl +++ b/wsdl/SiteService.wsdl @@ -17,6 +17,7 @@ + @@ -120,6 +121,8 @@ + + @@ -295,6 +298,7 @@ + @@ -343,6 +347,7 @@ + diff --git a/wsdl/StaffService.wsdl b/wsdl/StaffService.wsdl index 9ee9f7b..de54e10 100644 --- a/wsdl/StaffService.wsdl +++ b/wsdl/StaffService.wsdl @@ -151,7 +151,9 @@ + + @@ -188,6 +190,8 @@ + + @@ -235,6 +239,7 @@ + @@ -295,6 +300,7 @@ + @@ -445,6 +451,7 @@ + @@ -497,18 +504,6 @@ - - - - - - - - - - - - @@ -530,6 +525,18 @@ + + + + + + + + + + + + From cf504a6346ff3f4e6efae268884bc7d9e4c02850 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Thu, 4 Jun 2015 16:03:42 +0200 Subject: [PATCH 6/6] Fix method in correct place --- spec/services/class_service_spec.rb | 1 + spec/services/client_service_spec.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/class_service_spec.rb b/spec/services/class_service_spec.rb index f47db16..4fd13d6 100644 --- a/spec/services/class_service_spec.rb +++ b/spec/services/class_service_spec.rb @@ -9,4 +9,5 @@ it { should respond_to(:get_class_schedules) } it { should respond_to(:add_clients_to_enrollments) } it { should respond_to(:add_clients_to_classes)} + it { should respond_to(:remove_clients_from_classes)} end diff --git a/spec/services/client_service_spec.rb b/spec/services/client_service_spec.rb index a8b87a8..a07f304 100644 --- a/spec/services/client_service_spec.rb +++ b/spec/services/client_service_spec.rb @@ -24,5 +24,4 @@ it { should respond_to(:validate_login) } it { should respond_to(:update_client_services) } it { should respond_to(:send_user_new_password) } - it { should respond_to(:remove_clients_from_classes)} end