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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b442fa8e1dd84060190628131cdc1411cd170780
4
- data.tar.gz: 3f0e1420814abb2208119060056f66f813ef32e2
3
+ metadata.gz: e1978562931f0a0eb9f68a1cb5d1b029d8b3ee96
4
+ data.tar.gz: 41dcd93235fe76f1f9e0ecf2d5ff2976ade0d831
5
5
  SHA512:
6
- metadata.gz: 873348c0c1b44e5218efd5f0f784cf6c235ea9e61327f312b40e474925e99a04d7406fcf882ecafa447d4bed2742fc4687a4247293824898c763608eb2f9bd48
7
- data.tar.gz: 9405c30f24d1b2fd0e4428f70ed96205059ed97dd4b0f3143fa6d4036d7dd8f960c5e6a62da847621c17d5af6d251b138983bbbcc2adda9dfaef2bb69a7e71b2
6
+ metadata.gz: 2ca33626ebcbad9693a03f51a20434acd2c6554f847f7f13a17ce61bd02bf27656e7547c1bcd9201487a82b83bd2f01522604b2037866f632445476d14a88895
7
+ data.tar.gz: a138600c3a1df6e22c751e094c8f37e406b834a06282dc93302d729a534e799779c27a0832ea5914102d7d422e7c23acf46f12948caa4d583158f2a67b34f353
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Codeship Status](https://www.codeship.io/projects/808271e0-e973-0131-1052-5240ebfefa5a/status)](https://www.codeship.io/projects/26188) [![Code Climate](https://codeclimate.com/github/platformq/hotel_beds.png)](https://codeclimate.com/github/platformq/hotel_beds) [![Code Climate](https://codeclimate.com/github/platformq/hotel_beds/coverage.png)](https://codeclimate.com/github/platformq/hotel_beds)
1
+ [![Codeship Status](https://www.codeship.io/projects/808271e0-e973-0131-1052-5240ebfefa5a/status)](https://www.codeship.io/projects/26188) [![Gem Version](https://badge.fury.io/rb/hotel_beds.svg)](https://rubygems.org/gems/hotel_beds) [![Code Climate](https://codeclimate.com/github/platformq/hotel_beds.png)](https://codeclimate.com/github/platformq/hotel_beds) [![Code Climate](https://codeclimate.com/github/platformq/hotel_beds/coverage.png)](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", "~> 0.0.1"
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(room)
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: ((room.at_css("HotelRoom") > "Price") > "Amount").first.content,
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
- Array(prices).map do |price|
40
- HotelBeds::HotelSearch::Parser::Price.call(price)
41
- end.inject(Hash.new, :merge)
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
@@ -1,3 +1,3 @@
1
1
  module HotelBeds
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -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 + rand(3) + rand(2) + 1
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 { response.hotels.first.results.first.rooms.first }
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
- expect(subject.price).to eq(subject.rates.values.inject(:+))
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
- expect(subject.rates.size).to eq(check_out_date - check_in_date)
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.0
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-29 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon