tapi 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +152 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/tapi.rb +9 -0
- data/lib/tapi/v3/client.rb +261 -0
- data/lib/tapi/v3/configurable.rb +27 -0
- data/lib/tapi/v3/errors.rb +26 -0
- data/lib/tapi/v3/flights/search.rb +124 -0
- data/lib/tapi/v3/generic_search.rb +97 -0
- data/lib/tapi/v3/hotels/search.rb +213 -0
- data/lib/tapi/v3/utils.rb +64 -0
- data/lib/tapi/v3/validations.rb +58 -0
- data/spec/client_spec.rb +320 -0
- data/spec/configurable_spec.rb +27 -0
- data/spec/flights/search_spec.rb +102 -0
- data/spec/hotels/search_spec.rb +143 -0
- data/spec/spec_helper.rb +12 -0
- metadata +201 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
describe TAPI::V3::Flights::Search, " validations" do
|
6
|
+
before(:each) do
|
7
|
+
@params = {
|
8
|
+
:leaves_on => "01.01.#{Date.today.year + 1}",
|
9
|
+
:returns_on => "01.02.#{Date.today.year + 1}",
|
10
|
+
:origin => 'BLI',
|
11
|
+
:destination => 'BLA',
|
12
|
+
:adults => 1,
|
13
|
+
:children => 0,
|
14
|
+
:infants => 0,
|
15
|
+
:comfort => 'E'
|
16
|
+
}
|
17
|
+
@search = TAPI::V3::Flights::Search.new(@params)
|
18
|
+
|
19
|
+
TAPI::V3::Flights::Search.new(@params)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be valid" do
|
23
|
+
@search.should be_valid
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not accept dates in the past" do
|
27
|
+
@search.leaves_on = Date.today - 1
|
28
|
+
@search.should_not be_valid
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not accept returns before the leaving date" do
|
32
|
+
@search.leaves_on = Date.today + 5
|
33
|
+
@search.returns_on = Date.today + 3
|
34
|
+
@search.should_not be_valid
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should accept one way flights" do
|
38
|
+
@search.leaves_on = Date.today + 5
|
39
|
+
@search.returns_on = nil
|
40
|
+
@search.one_way = true
|
41
|
+
@search.should be_valid
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not accept missing dates" do
|
45
|
+
@search.leaves_on = Date.today + 5
|
46
|
+
@search.returns_on = 'asdkjhsadd'
|
47
|
+
@search.one_way = false
|
48
|
+
@search.should_not be_valid
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not accept wrong infants" do
|
52
|
+
@search.infants = 3
|
53
|
+
@search.adults = 1
|
54
|
+
@search.should_not be_valid
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should accept ISO date format" do
|
58
|
+
@search.leaves_on = (Date.today + 1.day).to_s
|
59
|
+
@search.should be_valid
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe TAPI::V3::Flights::Search, " starting" do
|
65
|
+
before(:each) do
|
66
|
+
# TAPI::V3::Flights::Search.config = {:host => 'staging-apiv3.travel-iq.com', :port => 80, :path => '/api/v3', :key => 'traveliq'}
|
67
|
+
|
68
|
+
# TAPI::V3::Flights::Search.config = {:host => 'host', :port => 1, :path => 'path', :key => 'key'}
|
69
|
+
@params = {
|
70
|
+
:leaves_on => "01.01.#{Date.today.year + 1}",
|
71
|
+
:returns_on => "01.02.#{Date.today.year + 1}",
|
72
|
+
:origin => 'BLI',
|
73
|
+
:destination => 'BLA',
|
74
|
+
:adults => 1,
|
75
|
+
:children => 0,
|
76
|
+
:infants => 0,
|
77
|
+
:comfort => 'E'
|
78
|
+
}
|
79
|
+
@search = TAPI::V3::Flights::Search.new(@params)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should instanciate a client' do
|
83
|
+
@search.should_receive(:post_url).and_return('the url')
|
84
|
+
@search.should_receive(:config).and_return({:key => 'the key'})
|
85
|
+
client_params = {
|
86
|
+
:leaves_on => "#{Date.today.year + 1}-01-01",
|
87
|
+
:returns_on => "#{Date.today.year + 1}-02-01",
|
88
|
+
:origin => 'BLI',
|
89
|
+
:destination => 'BLA',
|
90
|
+
:adults => 1,
|
91
|
+
:children => 0,
|
92
|
+
:infants => 0,
|
93
|
+
:comfort => 'E',
|
94
|
+
:format => 'json',
|
95
|
+
:one_way => false,
|
96
|
+
:key=>"the key"
|
97
|
+
}
|
98
|
+
client = mock('Client', :to_hash => 'the resources').as_null_object
|
99
|
+
TAPI::V3::Client.should_receive(:new_from_post).with('the url', client_params).and_return(client)
|
100
|
+
@search.start!
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
describe TAPI::V3::Hotels::Search, " validations" do
|
6
|
+
before(:each) do
|
7
|
+
@params = {
|
8
|
+
:arrival_date => "01.01.#{Date.today.year + 1}",
|
9
|
+
:departure_date => "01.02.#{Date.today.year + 1}",
|
10
|
+
:city_id => 1,
|
11
|
+
:single_rooms_count => 1,
|
12
|
+
:double_rooms_count => 2
|
13
|
+
}
|
14
|
+
@search = TAPI::V3::Hotels::Search.new(@params)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be valid with city" do
|
18
|
+
@search.should be_valid
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be valid with region" do
|
22
|
+
@params[:city_id] = nil
|
23
|
+
@params[:region_id] = 1
|
24
|
+
@params[:hotel_id] = nil
|
25
|
+
@search = TAPI::V3::Hotels::Search.new(@params)
|
26
|
+
@search.should be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be valid with hotel" do
|
30
|
+
@params[:city_id] = nil
|
31
|
+
@params[:region_id] = nil
|
32
|
+
@params[:hotel_id] = 1
|
33
|
+
@search = TAPI::V3::Hotels::Search.new(@params)
|
34
|
+
@search.should be_valid
|
35
|
+
end
|
36
|
+
|
37
|
+
@params = {
|
38
|
+
:arrival_date => "01.01.#{Date.today.year + 1}",
|
39
|
+
:departure_date => "01.02.#{Date.today.year + 1}",
|
40
|
+
:city_id => 1,
|
41
|
+
:single_rooms_count => 1,
|
42
|
+
:double_rooms_count => 2
|
43
|
+
}
|
44
|
+
|
45
|
+
[:arrival_date, :departure_date].each do |key|
|
46
|
+
it "should be invalid when #{key} has some stupid value" do
|
47
|
+
params = @params.dup
|
48
|
+
params[key] = 'schnabu'
|
49
|
+
TAPI::V3::Hotels::Search.new(params).should_not be_valid
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should accept room configurations" do
|
54
|
+
search = TAPI::V3::Hotels::Search.new
|
55
|
+
|
56
|
+
lambda { search.room_configuration = '[A|2]' }.should_not raise_error
|
57
|
+
lambda { search.room_configuration = '[A|13][A|2|12][A]' }.should_not raise_error
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not accept invalid room configurations" do
|
61
|
+
lambda { search.room_configuration = '[A|2]x' }.should raise_error
|
62
|
+
lambda { search.room_configuration = '[X]' }.should raise_error
|
63
|
+
lambda { search.room_configuration = '[A][A][B]' }.should raise_error
|
64
|
+
lambda { search.room_configuration = '[A][A][A][A]' }.should raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should accept ISO date format" do
|
68
|
+
TAPI::V3::Hotels::Search.new(@params.merge(:arrival_date => Date.today.to_s)).should be_valid
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should accept date objects" do
|
72
|
+
TAPI::V3::Hotels::Search.new(@params.merge(:arrival_date => Date.today)).should be_valid
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe TAPI::V3::Hotels::Search, " starting" do
|
78
|
+
before(:each) do
|
79
|
+
# TAPI::V3::Hotels::Search.config = {:host => 'staging-apiv3.travel-iq.com', :port => 80, :path => '/api/v3', :key => 'traveliq'}
|
80
|
+
|
81
|
+
TAPI::V3::Hotels::Search.config = {:host => 'host', :port => 1, :path => 'path', :key => 'key'}
|
82
|
+
@params = {
|
83
|
+
:arrival_date => "01.01.#{Date.today.year + 1}",
|
84
|
+
:departure_date => "01.02.#{Date.today.year + 1}",
|
85
|
+
:city_id => 1,
|
86
|
+
:single_rooms_count => 1,
|
87
|
+
:double_rooms_count => 2
|
88
|
+
}
|
89
|
+
@search = TAPI::V3::Hotels::Search.new(@params)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should instanciate a client' do
|
93
|
+
@search.should_receive(:post_url).and_return('the url')
|
94
|
+
@search.should_receive(:config).and_return({:key => 'the key'})
|
95
|
+
client_params = {
|
96
|
+
:key => 'the key',
|
97
|
+
:format => 'json',
|
98
|
+
:arrival_date => "#{Date.today.year + 1}-01-01",
|
99
|
+
:departure_date => "#{Date.today.year + 1}-02-01",
|
100
|
+
:city_id => 1,
|
101
|
+
:region_id => nil,
|
102
|
+
:hotel_id => nil,
|
103
|
+
:room_configuration => '[A][A|A][A|A]'
|
104
|
+
}
|
105
|
+
client = mock('Client', :resources => 'the resources').as_null_object
|
106
|
+
TAPI::V3::Client.should_receive(:new_from_post).with('the url', client_params).and_return(client)
|
107
|
+
# @search.should_receive(:load_client)
|
108
|
+
@search.start!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe TAPI::V3::Hotels::Search, " hotel_searches" do
|
113
|
+
before(:each) do
|
114
|
+
TAPI::V3::Hotels::Search.config = {:host => 'host', :port => 1, :path => 'path', :key => 'key'}
|
115
|
+
@params = {
|
116
|
+
:arrival_date => "01.01.#{Date.today.year + 1}",
|
117
|
+
:departure_date => "01.02.#{Date.today.year + 1}",
|
118
|
+
:city_id => 1,
|
119
|
+
:single_rooms_count => 1,
|
120
|
+
:double_rooms_count => 2
|
121
|
+
}
|
122
|
+
@search = TAPI::V3::Hotels::Search.new(@params)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should create a hotel search from an ID' do
|
126
|
+
hs = @search.hotel_search(666)
|
127
|
+
hs.arrival_date.should == Date.new(Date.today.year + 1, 1, 1)
|
128
|
+
hs.departure_date.should == Date.new(Date.today.year + 1, 2, 1)
|
129
|
+
hs.city_id.should == nil
|
130
|
+
hs.room_configuration.should == '[A][A|A][A|A]'
|
131
|
+
hs.hotel_id.should == 666
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should create a hotel search from an ID' do
|
135
|
+
result = mock('Result', :hotel_id => 666)
|
136
|
+
hs = @search.hotel_search(result)
|
137
|
+
hs.arrival_date.should == Date.new(Date.today.year + 1, 1, 1)
|
138
|
+
hs.departure_date.should == Date.new(Date.today.year + 1, 2, 1)
|
139
|
+
hs.city_id.should == nil
|
140
|
+
hs.room_configuration.should == '[A][A|A][A|A]'
|
141
|
+
hs.hotel_id.should == 666
|
142
|
+
end
|
143
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
#require 'rspec'
|
4
|
+
require 'tapi'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Martin Tepper
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-11 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 5
|
33
|
+
version: 2.3.5
|
34
|
+
name: activesupport
|
35
|
+
version_requirements: *id001
|
36
|
+
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :runtime
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 7
|
48
|
+
- 10
|
49
|
+
version: 0.7.10
|
50
|
+
name: curb
|
51
|
+
version_requirements: *id002
|
52
|
+
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :runtime
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 1
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 5
|
64
|
+
- 1
|
65
|
+
version: 1.5.1
|
66
|
+
name: json
|
67
|
+
version_requirements: *id003
|
68
|
+
prerelease: false
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
type: :development
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 2
|
79
|
+
- 3
|
80
|
+
- 0
|
81
|
+
version: 2.3.0
|
82
|
+
name: rspec
|
83
|
+
version_requirements: *id004
|
84
|
+
prerelease: false
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
type: :development
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 23
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 0
|
96
|
+
- 0
|
97
|
+
version: 1.0.0
|
98
|
+
name: bundler
|
99
|
+
version_requirements: *id005
|
100
|
+
prerelease: false
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
type: :development
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 7
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 5
|
112
|
+
- 2
|
113
|
+
version: 1.5.2
|
114
|
+
name: jeweler
|
115
|
+
version_requirements: *id006
|
116
|
+
prerelease: false
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
type: :development
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
name: rcov
|
129
|
+
version_requirements: *id007
|
130
|
+
prerelease: false
|
131
|
+
description: Reference client to the Travel IQ API at http://apiv3.travel-iq.com/
|
132
|
+
email: developer@traveliq.net
|
133
|
+
executables: []
|
134
|
+
|
135
|
+
extensions: []
|
136
|
+
|
137
|
+
extra_rdoc_files:
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.rdoc
|
140
|
+
files:
|
141
|
+
- .document
|
142
|
+
- Gemfile
|
143
|
+
- Gemfile.lock
|
144
|
+
- LICENSE.txt
|
145
|
+
- README.rdoc
|
146
|
+
- Rakefile
|
147
|
+
- VERSION
|
148
|
+
- lib/tapi.rb
|
149
|
+
- lib/tapi/v3/client.rb
|
150
|
+
- lib/tapi/v3/configurable.rb
|
151
|
+
- lib/tapi/v3/errors.rb
|
152
|
+
- lib/tapi/v3/flights/search.rb
|
153
|
+
- lib/tapi/v3/generic_search.rb
|
154
|
+
- lib/tapi/v3/hotels/search.rb
|
155
|
+
- lib/tapi/v3/utils.rb
|
156
|
+
- lib/tapi/v3/validations.rb
|
157
|
+
- spec/client_spec.rb
|
158
|
+
- spec/configurable_spec.rb
|
159
|
+
- spec/flights/search_spec.rb
|
160
|
+
- spec/hotels/search_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
has_rdoc: true
|
163
|
+
homepage: http://github.com/traveliq/tapi
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
hash: 3
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
version: "0"
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
hash: 3
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
requirements: []
|
190
|
+
|
191
|
+
rubyforge_project:
|
192
|
+
rubygems_version: 1.6.2
|
193
|
+
signing_key:
|
194
|
+
specification_version: 3
|
195
|
+
summary: Reference client to the Travel IQ API at http://apiv3.travel-iq.com/
|
196
|
+
test_files:
|
197
|
+
- spec/client_spec.rb
|
198
|
+
- spec/configurable_spec.rb
|
199
|
+
- spec/flights/search_spec.rb
|
200
|
+
- spec/hotels/search_spec.rb
|
201
|
+
- spec/spec_helper.rb
|