hotel_beds 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/hotel_beds/hotel_search/parser/hotel.rb +5 -1
- data/lib/hotel_beds/hotel_search/parser/room.rb +22 -7
- data/lib/hotel_beds/version.rb +1 -1
- data/spec/features/hotel_search_spec.rb +20 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e1978562931f0a0eb9f68a1cb5d1b029d8b3ee96
|
|
4
|
+
data.tar.gz: 41dcd93235fe76f1f9e0ecf2d5ff2976ade0d831
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ca33626ebcbad9693a03f51a20434acd2c6554f847f7f13a17ce61bd02bf27656e7547c1bcd9201487a82b83bd2f01522604b2037866f632445476d14a88895
|
|
7
|
+
data.tar.gz: a138600c3a1df6e22c751e094c8f37e406b834a06282dc93302d729a534e799779c27a0832ea5914102d7d422e7c23acf46f12948caa4d583158f2a67b34f353
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://www.codeship.io/projects/26188) [](https://codeclimate.com/github/platformq/hotel_beds) [](https://codeclimate.com/github/platformq/hotel_beds)
|
|
1
|
+
[](https://www.codeship.io/projects/26188) [](https://rubygems.org/gems/hotel_beds) [](https://codeclimate.com/github/platformq/hotel_beds) [](https://codeclimate.com/github/platformq/hotel_beds)
|
|
2
2
|
|
|
3
3
|
The `hotel_beds` gem interfaces with the [HotelBeds.com](http://www.hotelbeds.com/) SOAP API to search for and book hotel rooms.
|
|
4
4
|
|
|
@@ -8,7 +8,9 @@ I'm sure you know how to install Ruby gems by now...
|
|
|
8
8
|
|
|
9
9
|
In your Gemfile, before a `bundle install`, add:
|
|
10
10
|
|
|
11
|
-
gem "hotel_beds", "~>
|
|
11
|
+
gem "hotel_beds", "~> X.X.X"
|
|
12
|
+
|
|
13
|
+
**Note:** you'll need to replace `X.X.X` in the example above with the [latest gem version](https://rubygems.org/gems/hotel_beds) visible in the badge above.
|
|
12
14
|
|
|
13
15
|
Manually, via command line:
|
|
14
16
|
|
|
@@ -58,7 +58,11 @@ module HotelBeds
|
|
|
58
58
|
|
|
59
59
|
def parsed_available_rooms
|
|
60
60
|
Array(rooms).map do |room|
|
|
61
|
-
HotelBeds::HotelSearch::Parser::Room.call(
|
|
61
|
+
HotelBeds::HotelSearch::Parser::Room.call(
|
|
62
|
+
room,
|
|
63
|
+
check_in_date: request.check_in_date,
|
|
64
|
+
check_out_date: request.check_out_date
|
|
65
|
+
)
|
|
62
66
|
end
|
|
63
67
|
end
|
|
64
68
|
end
|
|
@@ -9,11 +9,13 @@ module HotelBeds
|
|
|
9
9
|
new(*args, &block).call
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
attr_accessor :room
|
|
13
|
-
private :room=
|
|
12
|
+
attr_accessor :room, :check_in_date, :check_out_date
|
|
13
|
+
private :room=, :check_in_date=, :check_out_date=
|
|
14
14
|
|
|
15
|
-
def initialize(room)
|
|
15
|
+
def initialize(room, check_in_date:, check_out_date:)
|
|
16
16
|
self.room = room
|
|
17
|
+
self.check_in_date = check_in_date
|
|
18
|
+
self.check_out_date = check_out_date
|
|
17
19
|
freeze
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -29,16 +31,29 @@ module HotelBeds
|
|
|
29
31
|
board_code: room.at_css("HotelRoom Board").attr("code"),
|
|
30
32
|
room_type_code: room.at_css("HotelRoom RoomType").attr("code"),
|
|
31
33
|
room_type_characteristic: room.at_css("HotelRoom RoomType").attr("characteristic"),
|
|
32
|
-
price:
|
|
34
|
+
price: total_price,
|
|
33
35
|
rates: parse_price_list(room.css("Price PriceList Price"))
|
|
34
36
|
})
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
private
|
|
40
|
+
def total_price
|
|
41
|
+
raw = ((room.at_css("HotelRoom") > "Price") > "Amount").first.content
|
|
42
|
+
BigDecimal.new(raw.to_s)
|
|
43
|
+
end
|
|
44
|
+
|
|
38
45
|
def parse_price_list(prices)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
if prices.empty?
|
|
47
|
+
dates = (check_in_date..check_out_date).to_a
|
|
48
|
+
amount = (total_price / dates)
|
|
49
|
+
dates.inject(Hash.new) do |result, date|
|
|
50
|
+
result.merge(date => amount)
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
Array(prices).map do |price|
|
|
54
|
+
HotelBeds::HotelSearch::Parser::Price.call(price)
|
|
55
|
+
end.inject(Hash.new, :merge)
|
|
56
|
+
end
|
|
42
57
|
end
|
|
43
58
|
end
|
|
44
59
|
end
|
data/lib/hotel_beds/version.rb
CHANGED
|
@@ -9,8 +9,9 @@ RSpec.describe "performing a hotel search" do
|
|
|
9
9
|
password: ENV.fetch("HOTEL_BEDS_PASSWORD"),
|
|
10
10
|
proxy: ENV.fetch("HOTEL_BEDS_PROXY", nil)
|
|
11
11
|
})
|
|
12
|
+
@stay_length_in_days = rand(3) + 1
|
|
12
13
|
@check_in_date = Date.today + 28 + rand(10)
|
|
13
|
-
@check_out_date = @check_in_date +
|
|
14
|
+
@check_out_date = @check_in_date + @stay_length_in_days
|
|
14
15
|
@response = @client.perform_hotel_search({
|
|
15
16
|
check_in_date: @check_in_date,
|
|
16
17
|
check_out_date: @check_out_date,
|
|
@@ -21,6 +22,7 @@ RSpec.describe "performing a hotel search" do
|
|
|
21
22
|
|
|
22
23
|
let(:check_in_date) { @check_in_date }
|
|
23
24
|
let(:check_out_date) { @check_out_date }
|
|
25
|
+
let(:stay_length_in_days) { @stay_length_in_days }
|
|
24
26
|
let(:response) { @response }
|
|
25
27
|
|
|
26
28
|
describe "#errors" do
|
|
@@ -45,6 +47,12 @@ RSpec.describe "performing a hotel search" do
|
|
|
45
47
|
expect(room_counts.to_a.flatten.uniq).to eq([1])
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
it "should have a destination code" do
|
|
51
|
+
subject.each do |hotel|
|
|
52
|
+
expect(hotel.destination_code).to be_present
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
48
56
|
it "should have an availability token" do
|
|
49
57
|
subject.each do |hotel|
|
|
50
58
|
expect(hotel.availability_token).to be_present
|
|
@@ -65,14 +73,22 @@ RSpec.describe "performing a hotel search" do
|
|
|
65
73
|
|
|
66
74
|
describe "#results" do
|
|
67
75
|
describe "#rooms" do
|
|
68
|
-
subject
|
|
76
|
+
subject do
|
|
77
|
+
results = response.hotels.map(&:results).to_a.flatten
|
|
78
|
+
results.map(&:rooms).to_a.flatten
|
|
79
|
+
end
|
|
69
80
|
|
|
70
81
|
it "should parse the rates correctly" do
|
|
71
|
-
|
|
82
|
+
subject.each do |room|
|
|
83
|
+
expect(room.price).to eq(room.rates.values.inject(:+))
|
|
84
|
+
end
|
|
72
85
|
end
|
|
73
86
|
|
|
74
87
|
it "should have the same number of rates as nights requested" do
|
|
75
|
-
|
|
88
|
+
subject.each do |room|
|
|
89
|
+
expect(room.rates).to_not be_empty
|
|
90
|
+
expect(room.rates.size).to eq(stay_length_in_days)
|
|
91
|
+
end
|
|
76
92
|
end
|
|
77
93
|
end
|
|
78
94
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hotel_beds
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Townsend
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-07-
|
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: savon
|