bookingsync 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +20 -0
- data/README.md +72 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/bookingsync.gemspec +115 -0
- data/examples/config_initializers_bookingsync.rb +3 -0
- data/examples/sample.rb +8 -0
- data/lib/bookingsync.rb +5 -0
- data/lib/bookingsync/base.rb +20 -0
- data/lib/bookingsync/booking.rb +13 -0
- data/lib/bookingsync/client.rb +9 -0
- data/lib/bookingsync/pagination.rb +36 -0
- data/lib/bookingsync/rental.rb +9 -0
- data/spec/bookingsync/base_spec.rb +49 -0
- data/spec/bookingsync/booking_spec.rb +28 -0
- data/spec/bookingsync/client_spec.rb +14 -0
- data/spec/bookingsync/pagination_behavior.rb +24 -0
- data/spec/bookingsync/pagination_spec.rb +8 -0
- data/spec/bookingsync/rental_spec.rb +14 -0
- data/spec/spec_helper.rb +17 -0
- metadata +269 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "activeresource", ">= 3.0.0"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.2.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.1"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem "ZenTest", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.4.2)
|
5
|
+
activemodel (3.0.3)
|
6
|
+
activesupport (= 3.0.3)
|
7
|
+
builder (~> 2.1.2)
|
8
|
+
i18n (~> 0.4)
|
9
|
+
activeresource (3.0.3)
|
10
|
+
activemodel (= 3.0.3)
|
11
|
+
activesupport (= 3.0.3)
|
12
|
+
activesupport (3.0.3)
|
13
|
+
builder (2.1.2)
|
14
|
+
diff-lcs (1.1.2)
|
15
|
+
git (1.2.5)
|
16
|
+
i18n (0.5.0)
|
17
|
+
jeweler (1.5.2)
|
18
|
+
bundler (~> 1.0.0)
|
19
|
+
git (>= 1.2.5)
|
20
|
+
rake
|
21
|
+
rake (0.8.7)
|
22
|
+
rcov (0.9.9)
|
23
|
+
rspec (2.2.0)
|
24
|
+
rspec-core (~> 2.2)
|
25
|
+
rspec-expectations (~> 2.2)
|
26
|
+
rspec-mocks (~> 2.2)
|
27
|
+
rspec-core (2.2.1)
|
28
|
+
rspec-expectations (2.2.0)
|
29
|
+
diff-lcs (~> 1.1.2)
|
30
|
+
rspec-mocks (2.2.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
ZenTest
|
37
|
+
activeresource (>= 3.0.0)
|
38
|
+
bundler (~> 1.0.0)
|
39
|
+
jeweler (~> 1.5.1)
|
40
|
+
rcov
|
41
|
+
rspec (~> 2.2.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Sebastien Grosjean
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# BookingSync (0.1.0)
|
2
|
+
|
3
|
+
## What is it?
|
4
|
+
|
5
|
+
This gem provides a set of classes to access information on [BookingSync][bs] via the published [API][api]:
|
6
|
+
|
7
|
+
Booking, Client, Rental.
|
8
|
+
|
9
|
+
All these classes are inherited from ActiveResouce::Base. Refer to the [ActiveResouce][ar] documentation for more information.
|
10
|
+
|
11
|
+
## Installing
|
12
|
+
|
13
|
+
gem install bookingsync
|
14
|
+
|
15
|
+
### Dependencies (see <code>bookingsync.gemspec</code> or run <code>bundle check</code>)
|
16
|
+
|
17
|
+
### Documentation
|
18
|
+
|
19
|
+
It will be on [rdoc.info][rdoc]
|
20
|
+
|
21
|
+
### Configure your key
|
22
|
+
|
23
|
+
require 'bookingsync'
|
24
|
+
|
25
|
+
BookingSync::Base.user = 'api-auth-token'
|
26
|
+
|
27
|
+
If you are using this in a Rails application, putting this code in a config/initializers/bookingsync.rb
|
28
|
+
file is recommended. See config_initializers_bookingsync.rb in the examples/ directory.
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
@rental = BookingSync::Rental.create(:name => 'Wonderful Rental')
|
33
|
+
|
34
|
+
@rentals = BookingSync::Rental.all
|
35
|
+
|
36
|
+
@bookings = BookingSync::Booking.find_all_across_pages(:params => {:rental_id => 12345})
|
37
|
+
|
38
|
+
@bookings = BookingSync::Rental.find(12345).bookings
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
This code is free to be used under the terms of the [MIT license][mit].
|
43
|
+
|
44
|
+
## Bugs, Issues, Kudos and Catcalls
|
45
|
+
|
46
|
+
Comments are welcome. Send your feedback through the [issue tracker on GitHub][i]
|
47
|
+
|
48
|
+
If you have fixes: Submit via pull requests. Do not include version changes to the
|
49
|
+
version file.
|
50
|
+
|
51
|
+
## Contributing to BookingSync
|
52
|
+
|
53
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
54
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
55
|
+
* Fork the project
|
56
|
+
* Start a feature/bugfix branch
|
57
|
+
* Commit and push until you are happy with your contribution
|
58
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
59
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
60
|
+
|
61
|
+
## Authors
|
62
|
+
|
63
|
+
* [Sébastien Grosjean][zencocoon]
|
64
|
+
|
65
|
+
|
66
|
+
[api]: http://www.bookingsync.com/en/documentation/api
|
67
|
+
[ar]: http://api.rubyonrails.org/classes/ActiveResource/Base.html
|
68
|
+
[bs]: http://www.bookingsync.com
|
69
|
+
[rdoc]: http://rdoc.info/projects/bookingsync/bookingsync-ruby
|
70
|
+
[mit]:http://www.opensource.org/licenses/mit-license.php
|
71
|
+
[i]: https://github.com/bookingsync/bookingsync-ruby/issues
|
72
|
+
[zencocoon]: https://github.com/ZenCocoon
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "bookingsync"
|
16
|
+
gem.homepage = "http://github.com/BookingSync/bookingsync-ruby"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Ruby wrapper around BookingSync API}
|
19
|
+
gem.description = <<-EOT
|
20
|
+
Ruby wrapper around BookingSync API
|
21
|
+
|
22
|
+
Configure by adding the following:
|
23
|
+
|
24
|
+
require 'bookingsync'
|
25
|
+
BookingSync::Base.user = 'your_api_auth_token'
|
26
|
+
EOT
|
27
|
+
gem.email = "public@zencocoon.com"
|
28
|
+
gem.authors = ["Sebastien Grosjean"]
|
29
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
30
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
31
|
+
gem.add_runtime_dependency 'activeresource', '>= 3.0.0'
|
32
|
+
gem.add_development_dependency 'rspec', '>= 2.2.0'
|
33
|
+
gem.add_development_dependency "bundler", "~> 1.0.0"
|
34
|
+
gem.add_development_dependency "jeweler", "~> 1.5.1"
|
35
|
+
gem.add_development_dependency "rcov", ">= 0"
|
36
|
+
gem.add_development_dependency "ZenTest", ">= 0"
|
37
|
+
end
|
38
|
+
Jeweler::RubygemsDotOrgTasks.new
|
39
|
+
|
40
|
+
require 'rspec/core'
|
41
|
+
require 'rspec/core/rake_task'
|
42
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
43
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
47
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
48
|
+
spec.rcov = true
|
49
|
+
end
|
50
|
+
|
51
|
+
task :default => :spec
|
52
|
+
|
53
|
+
require 'rake/rdoctask'
|
54
|
+
Rake::RDocTask.new do |rdoc|
|
55
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
56
|
+
|
57
|
+
rdoc.rdoc_dir = 'rdoc'
|
58
|
+
rdoc.title = "bookingsync #{version}"
|
59
|
+
rdoc.rdoc_files.include('README*')
|
60
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/bookingsync.gemspec
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bookingsync}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sebastien Grosjean"]
|
12
|
+
s.date = %q{2011-01-07}
|
13
|
+
s.description = %q{ Ruby wrapper around BookingSync API
|
14
|
+
|
15
|
+
Configure by adding the following:
|
16
|
+
|
17
|
+
require 'bookingsync'
|
18
|
+
BookingSync::Base.user = 'your_api_auth_token'
|
19
|
+
}
|
20
|
+
s.email = %q{public@zencocoon.com}
|
21
|
+
s.extra_rdoc_files = [
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.md"
|
24
|
+
]
|
25
|
+
s.files = [
|
26
|
+
".document",
|
27
|
+
".rspec",
|
28
|
+
"Gemfile",
|
29
|
+
"Gemfile.lock",
|
30
|
+
"LICENSE.txt",
|
31
|
+
"README.md",
|
32
|
+
"Rakefile",
|
33
|
+
"VERSION",
|
34
|
+
"autotest/discover.rb",
|
35
|
+
"bookingsync.gemspec",
|
36
|
+
"examples/config_initializers_bookingsync.rb",
|
37
|
+
"examples/sample.rb",
|
38
|
+
"lib/bookingsync.rb",
|
39
|
+
"lib/bookingsync/base.rb",
|
40
|
+
"lib/bookingsync/booking.rb",
|
41
|
+
"lib/bookingsync/client.rb",
|
42
|
+
"lib/bookingsync/pagination.rb",
|
43
|
+
"lib/bookingsync/rental.rb",
|
44
|
+
"spec/bookingsync/base_spec.rb",
|
45
|
+
"spec/bookingsync/booking_spec.rb",
|
46
|
+
"spec/bookingsync/client_spec.rb",
|
47
|
+
"spec/bookingsync/pagination_behavior.rb",
|
48
|
+
"spec/bookingsync/pagination_spec.rb",
|
49
|
+
"spec/bookingsync/rental_spec.rb",
|
50
|
+
"spec/spec_helper.rb"
|
51
|
+
]
|
52
|
+
s.homepage = %q{http://github.com/BookingSync/bookingsync-ruby}
|
53
|
+
s.licenses = ["MIT"]
|
54
|
+
s.require_paths = ["lib"]
|
55
|
+
s.rubygems_version = %q{1.3.7}
|
56
|
+
s.summary = %q{Ruby wrapper around BookingSync API}
|
57
|
+
s.test_files = [
|
58
|
+
"examples/config_initializers_bookingsync.rb",
|
59
|
+
"examples/sample.rb",
|
60
|
+
"spec/bookingsync/base_spec.rb",
|
61
|
+
"spec/bookingsync/booking_spec.rb",
|
62
|
+
"spec/bookingsync/client_spec.rb",
|
63
|
+
"spec/bookingsync/pagination_behavior.rb",
|
64
|
+
"spec/bookingsync/pagination_spec.rb",
|
65
|
+
"spec/bookingsync/rental_spec.rb",
|
66
|
+
"spec/spec_helper.rb"
|
67
|
+
]
|
68
|
+
|
69
|
+
if s.respond_to? :specification_version then
|
70
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
|
+
s.specification_version = 3
|
72
|
+
|
73
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 3.0.0"])
|
75
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.2.0"])
|
76
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
78
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<ZenTest>, [">= 0"])
|
80
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 3.0.0"])
|
81
|
+
s.add_development_dependency(%q<rspec>, [">= 2.2.0"])
|
82
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
83
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
84
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
85
|
+
s.add_development_dependency(%q<ZenTest>, [">= 0"])
|
86
|
+
else
|
87
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.0"])
|
88
|
+
s.add_dependency(%q<rspec>, ["~> 2.2.0"])
|
89
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
91
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
92
|
+
s.add_dependency(%q<ZenTest>, [">= 0"])
|
93
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.0"])
|
94
|
+
s.add_dependency(%q<rspec>, [">= 2.2.0"])
|
95
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
96
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
97
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
98
|
+
s.add_dependency(%q<ZenTest>, [">= 0"])
|
99
|
+
end
|
100
|
+
else
|
101
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.0"])
|
102
|
+
s.add_dependency(%q<rspec>, ["~> 2.2.0"])
|
103
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
104
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
105
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
106
|
+
s.add_dependency(%q<ZenTest>, [">= 0"])
|
107
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.0"])
|
108
|
+
s.add_dependency(%q<rspec>, [">= 2.2.0"])
|
109
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
110
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
111
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
112
|
+
s.add_dependency(%q<ZenTest>, [">= 0"])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
data/examples/sample.rb
ADDED
data/lib/bookingsync.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
module BookingSync
|
4
|
+
class Base < ActiveResource::Base
|
5
|
+
self.site = 'https://www.bookingsync.com'
|
6
|
+
|
7
|
+
protected
|
8
|
+
# Dynamic finder for attributes
|
9
|
+
def self.method_missing(method, *args)
|
10
|
+
if method.to_s =~ /^find_(all_)?by_([_a-zA-Z]\w*)$/
|
11
|
+
raise ArgumentError, "Dynamic finder method must take an argument." if args.empty?
|
12
|
+
options = args.extract_options!
|
13
|
+
resources = respond_to?(:find_all_across_pages) ? send(:find_all_across_pages, options) : send(:find, :all)
|
14
|
+
resources.send($1 == 'all_' ? 'select' : 'detect') { |container| container.send($2) == args.first }
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module BookingSync
|
2
|
+
module Pagination
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def find_all_across_pages(options = {})
|
9
|
+
records = []
|
10
|
+
each(options) { |record| records << record }
|
11
|
+
records
|
12
|
+
end
|
13
|
+
|
14
|
+
# This only is usefull for bookings, but should be safely ignored by other classes
|
15
|
+
def find_all_across_pages_from(time)
|
16
|
+
find_all_across_pages(:params => { :from => time.utc.strftime("%Y%m%d") })
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def each(options = {})
|
22
|
+
options[:params] ||= {}
|
23
|
+
options[:params][:page] = 1
|
24
|
+
|
25
|
+
loop do
|
26
|
+
if (records = self.find(:all, options)).try(:any?)
|
27
|
+
records.each { |record| yield record }
|
28
|
+
options[:params][:page] += 1
|
29
|
+
else
|
30
|
+
break # no booking included on that page, there's no more booking
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BookingSync::Base do
|
4
|
+
it { subject.should be_a_kind_of ActiveResource::Base }
|
5
|
+
|
6
|
+
describe "dynamic finder methods" do
|
7
|
+
context "without pagination" do
|
8
|
+
before do
|
9
|
+
@rental_one = BookingSync::Base.new(:id => 1, :name => "A rental")
|
10
|
+
@rental_two = BookingSync::Base.new(:id => 2, :name => "A rental")
|
11
|
+
@rental_three = BookingSync::Base.new(:id => 3, :name => "Another rental")
|
12
|
+
BookingSync::Base.should_receive(:find).with(:all).and_return([@rental_one, @rental_two, @rental_three])
|
13
|
+
end
|
14
|
+
|
15
|
+
it ".find_by_(attribute) finds one" do
|
16
|
+
BookingSync::Base.find_by_name("A rental").should == @rental_one
|
17
|
+
end
|
18
|
+
|
19
|
+
it ".find_all_by_(attribute) finds all" do
|
20
|
+
BookingSync::Base.find_all_by_name("A rental").should == [@rental_one, @rental_two]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with pagination" do
|
25
|
+
before do
|
26
|
+
class PaginatedBaseClass < BookingSync::Base; include BookingSync::Pagination; end
|
27
|
+
@john_doe = PaginatedBaseClass.new(:id => 1, :first_name => "John")
|
28
|
+
@john_baker = PaginatedBaseClass.new(:id => 2, :first_name => "John")
|
29
|
+
@joe_smith = PaginatedBaseClass.new(:id => 3, :first_name => "Joe")
|
30
|
+
PaginatedBaseClass.should_receive(:find_all_across_pages).and_return([@john_doe, @john_baker, @joe_smith])
|
31
|
+
end
|
32
|
+
it ".find_by_(attribute) finds one" do
|
33
|
+
PaginatedBaseClass.find_by_first_name("John").should == @john_doe
|
34
|
+
end
|
35
|
+
|
36
|
+
it ".find_all_by_(attribute) finds all" do
|
37
|
+
PaginatedBaseClass.find_all_by_first_name("John").should == [@john_doe, @john_baker]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "expects arguments to the finder" do
|
42
|
+
expect { BookingSync::Base.find_all_by_first_name }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "falls back to regular method missing" do
|
46
|
+
expect { BookingSync::Base.any_other_method }.to raise_error(NoMethodError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BookingSync::Booking do
|
4
|
+
subject { BookingSync::Booking.new(:id => 1) }
|
5
|
+
|
6
|
+
it { should be_a_kind_of BookingSync::Booking }
|
7
|
+
|
8
|
+
it_should_behave_like "a paginated class"
|
9
|
+
|
10
|
+
it "#rental should delegate to BookingSync::Rental" do
|
11
|
+
subject.should_receive(:rental_id).at_least(1).times.and_return(1)
|
12
|
+
BookingSync::Rental.should_receive(:find).with(1).and_return("rental")
|
13
|
+
subject.rental.should == "rental"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#client" do
|
17
|
+
it "returns nil when it doesn't have a client" do
|
18
|
+
subject.should_receive(:client_id).and_return(nil)
|
19
|
+
subject.client.should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "delegate to BookingSync::Client when it have a client_id" do
|
23
|
+
subject.should_receive(:client_id).at_least(2).times.and_return(1)
|
24
|
+
BookingSync::Client.should_receive(:find).with(1).and_return("client")
|
25
|
+
subject.client.should == "client"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BookingSync::Client do
|
4
|
+
subject { BookingSync::Client.new(:id => 1) }
|
5
|
+
|
6
|
+
it { should be_a_kind_of BookingSync::Client }
|
7
|
+
|
8
|
+
it_should_behave_like "a paginated class"
|
9
|
+
|
10
|
+
it "#bookings" do
|
11
|
+
BookingSync::Booking.should_receive(:find_all_across_pages).with(:from=>"/clients/1/bookings.xml").and_return("bookings")
|
12
|
+
subject.bookings.should == 'bookings'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
shared_examples_for "a paginated class" do
|
2
|
+
it { subject.class.included_modules.should include(BookingSync::Pagination) }
|
3
|
+
|
4
|
+
it ".find_all_across_pages" do
|
5
|
+
subject.class.should_receive(:find).with(:all, {
|
6
|
+
:params => { :page => 1 }}).and_return(["things"])
|
7
|
+
subject.class.should_receive(:find).with(:all,{
|
8
|
+
:params => { :page => 2 }}).and_return([])
|
9
|
+
subject.class.find_all_across_pages.should == ["things"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it ".find_all_across_pages with zero results" do
|
13
|
+
subject.class.should_receive(:find).with(:all,{
|
14
|
+
:params => { :page => 1 }}).and_return(nil)
|
15
|
+
subject.class.find_all_across_pages.should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
it ".find_all_across_pages_since" do
|
19
|
+
time = Time.parse("Fri Jan 07 12:34:56 +0200 2011")
|
20
|
+
subject.class.should_receive(:find_all_across_pages).with({
|
21
|
+
:params => { :from => "20110107"}}).and_return("result")
|
22
|
+
subject.class.find_all_across_pages_from(time).should == "result"
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BookingSync::Rental do
|
4
|
+
subject { BookingSync::Rental.new(:id => 1) }
|
5
|
+
|
6
|
+
it { should be_a_kind_of BookingSync::Rental }
|
7
|
+
|
8
|
+
it_should_behave_like "a paginated class"
|
9
|
+
|
10
|
+
it "#bookings" do
|
11
|
+
BookingSync::Booking.should_receive(:find_all_across_pages).with(:from=>"/rentals/1/bookings.xml").and_return("bookings")
|
12
|
+
subject.bookings.should == 'bookings'
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'bookingsync'
|
5
|
+
|
6
|
+
|
7
|
+
BookingSync::Base.user = ENV['BOOKINGSYNC_USER'] || 'x'
|
8
|
+
|
9
|
+
require 'bookingsync/pagination_behavior'
|
10
|
+
|
11
|
+
# Requires supporting files with custom matchers and macros, etc,
|
12
|
+
# in ./support/ and its subdirectories.
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,269 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bookingsync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Sebastien Grosjean
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-07 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activeresource
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 3.0.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
version: 2.2.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 0
|
60
|
+
- 0
|
61
|
+
version: 1.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: jeweler
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 5
|
75
|
+
- 1
|
76
|
+
version: 1.5.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rcov
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: ZenTest
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: *id006
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: activeresource
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 3
|
115
|
+
- 0
|
116
|
+
- 0
|
117
|
+
version: 3.0.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: *id007
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: rspec
|
123
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
segments:
|
129
|
+
- 2
|
130
|
+
- 2
|
131
|
+
- 0
|
132
|
+
version: 2.2.0
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: *id008
|
136
|
+
- !ruby/object:Gem::Dependency
|
137
|
+
name: bundler
|
138
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ~>
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
segments:
|
144
|
+
- 1
|
145
|
+
- 0
|
146
|
+
- 0
|
147
|
+
version: 1.0.0
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: *id009
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: jeweler
|
153
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ~>
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
segments:
|
159
|
+
- 1
|
160
|
+
- 5
|
161
|
+
- 1
|
162
|
+
version: 1.5.1
|
163
|
+
type: :development
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: *id010
|
166
|
+
- !ruby/object:Gem::Dependency
|
167
|
+
name: rcov
|
168
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: *id011
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: ZenTest
|
181
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: *id012
|
192
|
+
description: " Ruby wrapper around BookingSync API\n \n Configure by adding the following:\n\n require 'bookingsync'\n BookingSync::Base.user = 'your_api_auth_token'\n"
|
193
|
+
email: public@zencocoon.com
|
194
|
+
executables: []
|
195
|
+
|
196
|
+
extensions: []
|
197
|
+
|
198
|
+
extra_rdoc_files:
|
199
|
+
- LICENSE.txt
|
200
|
+
- README.md
|
201
|
+
files:
|
202
|
+
- .document
|
203
|
+
- .rspec
|
204
|
+
- Gemfile
|
205
|
+
- Gemfile.lock
|
206
|
+
- LICENSE.txt
|
207
|
+
- README.md
|
208
|
+
- Rakefile
|
209
|
+
- VERSION
|
210
|
+
- autotest/discover.rb
|
211
|
+
- bookingsync.gemspec
|
212
|
+
- examples/config_initializers_bookingsync.rb
|
213
|
+
- examples/sample.rb
|
214
|
+
- lib/bookingsync.rb
|
215
|
+
- lib/bookingsync/base.rb
|
216
|
+
- lib/bookingsync/booking.rb
|
217
|
+
- lib/bookingsync/client.rb
|
218
|
+
- lib/bookingsync/pagination.rb
|
219
|
+
- lib/bookingsync/rental.rb
|
220
|
+
- spec/bookingsync/base_spec.rb
|
221
|
+
- spec/bookingsync/booking_spec.rb
|
222
|
+
- spec/bookingsync/client_spec.rb
|
223
|
+
- spec/bookingsync/pagination_behavior.rb
|
224
|
+
- spec/bookingsync/pagination_spec.rb
|
225
|
+
- spec/bookingsync/rental_spec.rb
|
226
|
+
- spec/spec_helper.rb
|
227
|
+
has_rdoc: true
|
228
|
+
homepage: http://github.com/BookingSync/bookingsync-ruby
|
229
|
+
licenses:
|
230
|
+
- MIT
|
231
|
+
post_install_message:
|
232
|
+
rdoc_options: []
|
233
|
+
|
234
|
+
require_paths:
|
235
|
+
- lib
|
236
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
237
|
+
none: false
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
hash: -4045062373654225274
|
242
|
+
segments:
|
243
|
+
- 0
|
244
|
+
version: "0"
|
245
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
|
+
none: false
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
segments:
|
251
|
+
- 0
|
252
|
+
version: "0"
|
253
|
+
requirements: []
|
254
|
+
|
255
|
+
rubyforge_project:
|
256
|
+
rubygems_version: 1.3.7
|
257
|
+
signing_key:
|
258
|
+
specification_version: 3
|
259
|
+
summary: Ruby wrapper around BookingSync API
|
260
|
+
test_files:
|
261
|
+
- examples/config_initializers_bookingsync.rb
|
262
|
+
- examples/sample.rb
|
263
|
+
- spec/bookingsync/base_spec.rb
|
264
|
+
- spec/bookingsync/booking_spec.rb
|
265
|
+
- spec/bookingsync/client_spec.rb
|
266
|
+
- spec/bookingsync/pagination_behavior.rb
|
267
|
+
- spec/bookingsync/pagination_spec.rb
|
268
|
+
- spec/bookingsync/rental_spec.rb
|
269
|
+
- spec/spec_helper.rb
|