mindbody-api 1.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +5 -0
  4. data/CONTRIBUTING.md +16 -0
  5. data/Gemfile +12 -0
  6. data/Guardfile +6 -0
  7. data/LICENSE.md +22 -0
  8. data/README.md +79 -0
  9. data/Rakefile +52 -0
  10. data/lib/mindbody-api.rb +35 -0
  11. data/lib/mindbody-api/api_status.rb +109 -0
  12. data/lib/mindbody-api/client.rb +39 -0
  13. data/lib/mindbody-api/ext/savon_ext.rb +53 -0
  14. data/lib/mindbody-api/models.rb +34 -0
  15. data/lib/mindbody-api/models/appointment.rb +22 -0
  16. data/lib/mindbody-api/models/appointment_status.rb +13 -0
  17. data/lib/mindbody-api/models/availability.rb +11 -0
  18. data/lib/mindbody-api/models/class.rb +31 -0
  19. data/lib/mindbody-api/models/class_description.rb +14 -0
  20. data/lib/mindbody-api/models/class_schedule.rb +26 -0
  21. data/lib/mindbody-api/models/client.rb +32 -0
  22. data/lib/mindbody-api/models/client_service.rb +16 -0
  23. data/lib/mindbody-api/models/course.rb +16 -0
  24. data/lib/mindbody-api/models/level.rb +8 -0
  25. data/lib/mindbody-api/models/location.rb +38 -0
  26. data/lib/mindbody-api/models/payment.rb +11 -0
  27. data/lib/mindbody-api/models/program.rb +9 -0
  28. data/lib/mindbody-api/models/resource.rb +8 -0
  29. data/lib/mindbody-api/models/sale.rb +10 -0
  30. data/lib/mindbody-api/models/sale_item.rb +14 -0
  31. data/lib/mindbody-api/models/schedule_type.rb +13 -0
  32. data/lib/mindbody-api/models/semester.rb +9 -0
  33. data/lib/mindbody-api/models/service.rb +13 -0
  34. data/lib/mindbody-api/models/session_type.rb +8 -0
  35. data/lib/mindbody-api/models/site.rb +23 -0
  36. data/lib/mindbody-api/models/staff.rb +32 -0
  37. data/lib/mindbody-api/models/unavailability.rb +7 -0
  38. data/lib/mindbody-api/models/visit.rb +19 -0
  39. data/lib/mindbody-api/response.rb +119 -0
  40. data/lib/mindbody-api/service.rb +39 -0
  41. data/lib/mindbody-api/services/appointment_service.rb +15 -0
  42. data/lib/mindbody-api/services/class_service.rb +12 -0
  43. data/lib/mindbody-api/services/client_service.rb +30 -0
  44. data/lib/mindbody-api/services/finder_service.rb +11 -0
  45. data/lib/mindbody-api/services/sale_service.rb +14 -0
  46. data/lib/mindbody-api/services/site_service.rb +15 -0
  47. data/lib/mindbody-api/services/staff_service.rb +12 -0
  48. data/lib/mindbody-api/version.rb +4 -0
  49. data/mindbody-api.gemspec +29 -0
  50. data/spec/api_status_spec.rb +110 -0
  51. data/spec/client_spec.rb +51 -0
  52. data/spec/fixtures/wsdl/geotrust.wsdl +156 -0
  53. data/spec/mindbody_spec.rb +79 -0
  54. data/spec/model_spec.rb +7 -0
  55. data/spec/models/appointment_spec.rb +18 -0
  56. data/spec/models/appointment_status_spec.rb +17 -0
  57. data/spec/models/availability.rb +8 -0
  58. data/spec/models/class_description_spec.rb +12 -0
  59. data/spec/models/class_schedule_spec.rb +24 -0
  60. data/spec/models/class_spec.rb +39 -0
  61. data/spec/models/client_service_spec.rb +13 -0
  62. data/spec/models/client_spec.rb +33 -0
  63. data/spec/models/course_spec.rb +14 -0
  64. data/spec/models/level_spec.rb +6 -0
  65. data/spec/models/location_spec.rb +34 -0
  66. data/spec/models/payment_spec.rb +9 -0
  67. data/spec/models/program_spec.rb +7 -0
  68. data/spec/models/resource_spec.rb +6 -0
  69. data/spec/models/sale_item_spec.rb +12 -0
  70. data/spec/models/sale_spec.rb +8 -0
  71. data/spec/models/schedule_type_spec.rb +17 -0
  72. data/spec/models/semester_spec.rb +7 -0
  73. data/spec/models/service_spec.rb +11 -0
  74. data/spec/models/session_type_spec.rb +6 -0
  75. data/spec/models/site_spec.rb +31 -0
  76. data/spec/models/staff_spec.rb +29 -0
  77. data/spec/models/unavailability.rb +5 -0
  78. data/spec/models/visit_spec.rb +16 -0
  79. data/spec/response_spec.rb +115 -0
  80. data/spec/service_spec.rb +106 -0
  81. data/spec/services/appointment_service_spec.rb +13 -0
  82. data/spec/services/class_service_spec.rb +10 -0
  83. data/spec/services/client_service_spec.rb +27 -0
  84. data/spec/services/finder_service_spec.rb +9 -0
  85. data/spec/services/sale_service_spec.rb +12 -0
  86. data/spec/services/site_service_spec.rb +13 -0
  87. data/spec/services/staff_service_spec.rb +10 -0
  88. data/spec/spec_helper.rb +18 -0
  89. data/wsdl/AppointmentService.wsdl +1084 -0
  90. data/wsdl/ClassService.wsdl +1656 -0
  91. data/wsdl/ClientService.wsdl +2295 -0
  92. data/wsdl/FinderService.wsdl +1427 -0
  93. data/wsdl/SaleService.wsdl +1678 -0
  94. data/wsdl/SiteService.wsdl +915 -0
  95. data/wsdl/StaffService.wsdl +939 -0
  96. metadata +277 -0
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Course do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:name) }
6
+ it { should respond_to(:description) }
7
+ it { should respond_to(:notes) }
8
+ it { should respond_to(:start_date) }
9
+ it { should respond_to(:end_date) }
10
+ it { should respond_to(:location) }
11
+ it { should respond_to(:organizer) }
12
+ it { should respond_to(:program) }
13
+ it { should respond_to(:image_url) }
14
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Level do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:name) }
6
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Location do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:business_id) }
6
+ it { should respond_to(:site_id) }
7
+ it { should respond_to(:business_description) }
8
+ it { should respond_to(:additional_image_ur_ls) }
9
+ it { should respond_to(:facility_square_feet) }
10
+ it { should respond_to(:treatment_rooms) }
11
+ it { should respond_to(:pro_spa_finder_site) }
12
+ it { should respond_to(:has_classes) }
13
+ it { should respond_to(:phone_extension) }
14
+ it { should respond_to(:name) }
15
+ it { should respond_to(:address) }
16
+ it { should respond_to(:address2) }
17
+ it { should respond_to(:tax1) }
18
+ it { should respond_to(:tax2) }
19
+ it { should respond_to(:tax3) }
20
+ it { should respond_to(:tax4) }
21
+ it { should respond_to(:tax5) }
22
+ it { should respond_to(:phone) }
23
+ it { should respond_to(:city) }
24
+ it { should respond_to(:state_prov_code) }
25
+ it { should respond_to(:postal_code) }
26
+ it { should respond_to(:latitude) }
27
+ it { should respond_to(:longitude) }
28
+ it { should respond_to(:distance_in_miles) }
29
+ it { should respond_to(:image_url) }
30
+ it { should respond_to(:description) }
31
+ it { should respond_to(:has_site) }
32
+ it { should respond_to(:can_book) }
33
+ it { should respond_to(:additional_image_urls) }
34
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Payment do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:amount) }
6
+ it { should respond_to(:method) }
7
+ it { should respond_to(:type) }
8
+ it { should respond_to(:notes) }
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Program do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:name) }
6
+ it { should respond_to(:schedule_type) }
7
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Resource do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:name) }
6
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::SaleItem do
4
+ it { should respond_to(:sale) }
5
+ it { should respond_to(:description) }
6
+ it { should respond_to(:price) }
7
+ it { should respond_to(:amount_paid) }
8
+ it { should respond_to(:discount) }
9
+ it { should respond_to(:tax) }
10
+ it { should respond_to(:returned) }
11
+ it { should respond_to(:quantity) }
12
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Sale do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:sale_date_time) }
6
+ it { should respond_to(:location) }
7
+ it { should respond_to(:payments) }
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::ScheduleType do
4
+ context 'when a valid type is specified' do
5
+ before { @type = MindBody::Models::ScheduleType.new('All') }
6
+ subject { @type }
7
+
8
+ its(:type) { should eql('All') }
9
+ end
10
+
11
+ context 'when an invalid type is specified' do
12
+ before { @type = MindBody::Models::ScheduleType.new('foobar') }
13
+ subject { @type }
14
+
15
+ its(:type) { should be_nil }
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Semester do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:start_date) }
6
+ it { should respond_to(:end_date) }
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Service do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:price) }
6
+ it { should respond_to(:online_price) }
7
+ it { should respond_to(:tax_rate) }
8
+ it { should respond_to(:product_id) }
9
+ it { should respond_to(:name) }
10
+ it { should respond_to(:count) }
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::SessionType do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:name) }
6
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Site do
4
+ before do
5
+ @site = MindBody::Models::Site.new(:page_color1 => 'red',
6
+ :page_color2 => 'green',
7
+ :page_color3 => 'blue',
8
+ :page_color4 => 'yellow')
9
+ end
10
+
11
+ subject { @site }
12
+
13
+ it { should respond_to(:id) }
14
+ it { should respond_to(:name) }
15
+ it { should respond_to(:description) }
16
+ it { should respond_to(:logo_url) }
17
+ it { should respond_to(:page_color1) }
18
+ it { should respond_to(:page_color2) }
19
+ it { should respond_to(:page_color3) }
20
+ it { should respond_to(:page_color4) }
21
+ it { should respond_to(:accepts_visa) }
22
+ it { should respond_to(:accepts_discover) }
23
+ it { should respond_to(:accepts_master_card) }
24
+ it { should respond_to(:accepts_american_express) }
25
+ it { should respond_to(:contact_email) }
26
+ it { should respond_to(:page_colors) }
27
+
28
+ it 'should return an array of page colors' do
29
+ expect(subject.page_colors).to eql(['red', 'green', 'blue', 'yellow'])
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Staff do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:email) }
6
+ it { should respond_to(:mobile_phone) }
7
+ it { should respond_to(:home_phone) }
8
+ it { should respond_to(:work_phone) }
9
+ it { should respond_to(:address) }
10
+ it { should respond_to(:address2) }
11
+ it { should respond_to(:city) }
12
+ it { should respond_to(:state) }
13
+ it { should respond_to(:country) }
14
+ it { should respond_to(:postal_code) }
15
+ it { should respond_to(:foreign_zip) }
16
+ it { should respond_to(:login_locations) }
17
+ it { should respond_to(:name) }
18
+ it { should respond_to(:first_name) }
19
+ it { should respond_to(:last_name) }
20
+ it { should respond_to(:image_url) }
21
+ it { should respond_to(:bio) }
22
+ it { should respond_to(:is_male) }
23
+ it { should respond_to(:username) }
24
+
25
+ it 'should alias photo_url to image_url' do
26
+ subject.image_url = 'http://foobar.com/image.jpg'
27
+ expect(subject.photo_url).to eql('http://foobar.com/image.jpg')
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Unavailability do
4
+ it { should respond_to(:description) }
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Models::Visit do
4
+ it { should respond_to(:id) }
5
+ it { should respond_to(:class_id) }
6
+ it { should respond_to(:start_date_time) }
7
+ it { should respond_to(:end_date_time) }
8
+ it { should respond_to(:name) }
9
+ it { should respond_to(:staff) }
10
+ it { should respond_to(:location) }
11
+ it { should respond_to(:client) }
12
+ it { should respond_to(:web_signup) }
13
+ it { should respond_to(:signed_in) }
14
+ it { should respond_to(:make_up) }
15
+ it { should respond_to(:service) }
16
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Services::Response do
4
+ RESPONSE_HASH = {
5
+ :foo_response => {
6
+ :foo_result => {
7
+ :status => 'Success',
8
+ :clients => {
9
+ :client => [{}, {}, {}]
10
+ },
11
+ :visits => nil,
12
+ :string_list => {
13
+ :string => ['a', 'b', 'c']
14
+ },
15
+ :int_list => {
16
+ :int => [1,2,3,4,5,6]
17
+ },
18
+ :staff_members => {},
19
+ :organizer => {},
20
+ :purchases => {},
21
+ :image_url => 'http://foobar.com/image.jpg',
22
+ :mobile_image_url => 'http://foobar.com/mobile_image.jpg'
23
+ }
24
+ }
25
+ }
26
+
27
+ before :each do
28
+ resp = double('response')
29
+ resp.stub(:to_hash).and_return(RESPONSE_HASH)
30
+ @response = MindBody::Services::Response.new resp
31
+ end
32
+
33
+ subject { @response }
34
+ it { should respond_to(:response) }
35
+ it { should respond_to(:result) }
36
+ it { should respond_to(:status) }
37
+ it { should respond_to(:error_code) }
38
+ it { should respond_to(:xml_detail) }
39
+ it { should respond_to(:result_count) }
40
+ it { should respond_to(:current_page_index) }
41
+ it { should respond_to(:total_page_count) }
42
+ it { should respond_to(:remote_method) }
43
+ it { should respond_to(:message) }
44
+ it { should respond_to(:api_status) }
45
+
46
+ context 'when delegating to @response' do
47
+ before :each do
48
+ subject.response.stub(:foo).and_return('foo')
49
+ end
50
+
51
+ it 'should respond_to methods on @response' do
52
+ expect(subject.respond_to?(:foo)).to be true
53
+ end
54
+
55
+ it 'should dynamically define a delegate method' do
56
+ subject.should_receive(:method_missing).with(:foo).once.and_call_original
57
+ 2.times { subject.foo }
58
+ end
59
+
60
+ it 'should call through to @response' do
61
+ subject.response.should_receive(:foo).once
62
+ expect(subject.foo).to eql('foo')
63
+ end
64
+
65
+ it 'should call super for methods @response does not respond_to' do
66
+ expect{subject.bar}.to raise_error(NoMethodError)
67
+ end
68
+ end
69
+
70
+ context 'when normalizing a response' do
71
+ it 'should assign the normalized response to @result' do
72
+ expect(subject.result).to_not be_nil
73
+ end
74
+
75
+ it 'should strip the *_response and *_result wrapper hashes' do
76
+ expect(subject.result.has_key?(:foo_response)).to eql(false)
77
+ end
78
+
79
+ it 'should populate instance variables' do
80
+ expect(subject.status).to eql('Success')
81
+ end
82
+
83
+ it 'should map :staff_members to Staff' do
84
+ expect(subject.result[:staff_members]).to be_an_instance_of(MindBody::Models::Staff)
85
+ end
86
+
87
+ it 'should map :organizer to Staff' do
88
+ expect(subject.result[:organizer]).to be_an_instance_of(MindBody::Models::Staff)
89
+ end
90
+
91
+ it 'should map :purchases to SaleItem' do
92
+ expect(subject.result[:purchases]).to be_an_instance_of(MindBody::Models::SaleItem)
93
+ end
94
+
95
+ it 'should map :image_url to String' do
96
+ expect(subject.result[:image_url]).to be_an_instance_of(String)
97
+ end
98
+
99
+ it 'should map :mobile_image_url to String' do
100
+ expect(subject.result[:mobile_image_url]).to be_an_instance_of(String)
101
+ end
102
+
103
+ it 'should flatten a string list' do
104
+ expect(subject.result[:string_list].class).to be(Array)
105
+ end
106
+
107
+ it 'should flatten an int list' do
108
+ expect(subject.result[:int_list].class).to be(Array)
109
+ end
110
+
111
+ it 'should return nil for a nil entry' do
112
+ expect(subject.result[:visits]).to be(nil)
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe MindBody::Services::Service do
4
+ subject { MindBody::Services::Service }
5
+
6
+ it 'should extend Savon::Model' do
7
+ should respond_to(:operations)
8
+ end
9
+
10
+ context 'with class method' do
11
+ describe '#service' do
12
+ before { subject.service(:test) }
13
+
14
+ it 'should set the wsdl for the "test" service name' do
15
+ expect(subject.instance_variable_get('@wsdl')).to match(/wsdl\/test\.wsdl/)
16
+ end
17
+ end
18
+
19
+ describe '#client' do
20
+ its(:client) { should be_an_instance_of(MindBody::Services::Client) }
21
+ end
22
+
23
+ describe '#operation' do
24
+ before do
25
+ MindBody::Services::Client.any_instance.stub(:call)
26
+ end
27
+
28
+ context 'with no options' do
29
+ before :all do
30
+ MindBody::Services::Service.operation :test
31
+ end
32
+
33
+ it { should respond_to(:test) }
34
+ its(:new) { should respond_to(:test) }
35
+
36
+ it 'should have optional locals' do
37
+ expect(subject.method(:test).arity).to eql(-1)
38
+ end
39
+
40
+ it 'should delegate to the class method' do
41
+ instance = subject.new
42
+ locals = {:foo => :bar}
43
+
44
+ subject.should_receive(:test).with(locals).once
45
+
46
+ instance.test(locals)
47
+ end
48
+ end
49
+
50
+ context 'with required params' do
51
+ before :all do
52
+ MindBody::Services::Service.operation :test_required, :required => [:foo, :bar]
53
+ end
54
+
55
+ it { should respond_to(:test_required) }
56
+ its(:new) { should respond_to(:test_required) }
57
+
58
+ it 'should have two required params and optional locals' do
59
+ expect(subject.method(:test_required).arity).to eql(-3)
60
+ end
61
+
62
+ it 'should delegate to the class method' do
63
+ instance = subject.new
64
+ locals = {:foo => :bar}
65
+
66
+ subject.should_receive(:test_required).with(:foo, :bar, locals).once
67
+
68
+ instance.test_required(:foo, :bar, locals)
69
+ end
70
+
71
+ it 'should require two params' do
72
+ expect{subject.send(:test_required)}.to raise_error(ArgumentError)
73
+ end
74
+ end
75
+
76
+ context 'with no locals' do
77
+ before :all do
78
+ MindBody::Services::Service.operation :test_no_locals, :required => [:foo, :bar], :locals => false
79
+ end
80
+
81
+ it { should respond_to(:test_no_locals) }
82
+ its(:new) { should respond_to(:test_no_locals) }
83
+
84
+ it 'should have two required params and optional locals' do
85
+ expect(subject.method(:test_no_locals).arity).to eql(2)
86
+ end
87
+
88
+ it 'should delegate to the class method' do
89
+ instance = subject.new
90
+
91
+ subject.should_receive(:test_no_locals).with(:foo, :bar).once
92
+
93
+ instance.test_no_locals(:foo, :bar)
94
+ end
95
+
96
+ it 'should require two params' do
97
+ expect{subject.send(:test_no_locals)}.to raise_error(ArgumentError)
98
+ end
99
+
100
+ it 'should not allow locals' do
101
+ expect{subject.send(:test_no_locals, :foo, :bar, :foobar => 'foobar')}.to raise_error(ArgumentError)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end