suitcase 1.6.3 → 1.6.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ Changelog
2
+ =========
3
+
4
+ 1.6.3
5
+ -----
6
+ * Use chronic for proper reservation dates in the test suite.
7
+ * Allow access to the raw response on all Hotel and Room objects with the `raw` attribute.
@@ -0,0 +1,21 @@
1
+ module Suitcase
2
+ class Hotel
3
+ # Public: A BedType represents a bed configuration for a Room.
4
+ class BedType
5
+ # Internal: The ID of the BedType.
6
+ attr_accessor :id
7
+
8
+ # Internal: The description of the BedType.
9
+ attr_accessor :description
10
+
11
+ # Internal: Create a new BedType.
12
+ #
13
+ # info - A Hash from the parsed API response with the following keys:
14
+ # :id - The ID of the BedType.
15
+ # :description 3- The description of the BedType.
16
+ def initialize(info)
17
+ @id, @description = info[:id], info[:description]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Suitcase
2
+ class Hotel
3
+ # Public: An Exception to be raised from all EAN API-related errors.
4
+ class EANException < Exception
5
+ # Internal: Setter for the recovery information.
6
+ attr_writer :recovery
7
+
8
+ # Public: Getter for the recovery information.
9
+ attr_reader :recovery
10
+
11
+ # Internal: Setter for the error type.
12
+ attr_writer :type
13
+
14
+ # Public: Getter for the error type..
15
+ attr_reader :type
16
+
17
+ # Internal: Create a new EAN exception.
18
+ #
19
+ # message - The String error message returned by the API.
20
+ # type - The Symbol type of the error.
21
+ def initialize(message, type = nil)
22
+ @type = type
23
+ super(message)
24
+ end
25
+
26
+ # Public: Check if the error is recoverable. If it is, recovery information
27
+ # is in the attribute recovery.
28
+ #
29
+ # Returns a Boolean based on whether the error is recoverable.
30
+ def recoverable?
31
+ @recovery.is_a?(Hash)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -9,7 +9,7 @@ module Suitcase
9
9
  :room_type_description, :price_breakdown, :total_price,
10
10
  :average_nightly_rate, :promo, :arrival, :departure, :rooms,
11
11
  :bed_types, :cancellation_policy, :non_refundable,
12
- :deposit_required, :raw
12
+ :deposit_required, :surcharges, :raw
13
13
 
14
14
  extend Helpers
15
15
 
@@ -0,0 +1,22 @@
1
+ module Suitcase
2
+ class Hotel
3
+ # Public: A Surcharge represents a single surcharge on a Room.
4
+ class Surcharge
5
+ # Internal: Create a new Surcharge.
6
+ #
7
+ # info - A Hash of parsed info from Surcharge.parse.
8
+ def initialize(info)
9
+ @amount, @type = info[:amount], info[:type]
10
+ end
11
+
12
+ # Internal: Parse a Surcharge from the room response.
13
+ #
14
+ # info - A Hash of the parsed JSON relevant to the surhcarge.
15
+ #
16
+ # Returns a Surcharge representing the info.
17
+ def self.parse(info)
18
+ new(amount: info["@amount"], type: info["@type"])
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,54 +1,18 @@
1
- module Suitcase
2
- # Public: An Exception to be raised from all EAN API-related errors.
3
- class EANException < Exception
4
- # Internal: Setter for the recovery information.
5
- attr_writer :recovery
6
-
7
- # Public: Getter for the recovery information.
8
- attr_reader :recovery
9
-
10
- # Internal: Setter for the error type.
11
- attr_writer :type
12
-
13
- # Public: Getter for the error type..
14
- attr_reader :type
15
-
16
- # Internal: Create a new EAN exception.
17
- #
18
- # message - The String error message returned by the API.
19
- # type - The Symbol type of the error.
20
- def initialize(message, type = nil)
21
- @type = type
22
- super(message)
23
- end
24
-
25
- # Public: Check if the error is recoverable. If it is, recovery information
26
- # is in the attribute recovery.
27
- #
28
- # Returns a Boolean based on whether the error is recoverable.
29
- def recoverable?
30
- @recovery.is_a?(Hash)
31
- end
32
- end
33
-
34
- # Public: A BedType represents a bed configuration for a Room.
35
- class BedType
36
- # Internal: The ID of the BedType.
37
- attr_accessor :id
38
-
39
- # Internal: The description of the BedType.
40
- attr_accessor :description
41
-
42
- # Internal: Create a new BedType.
43
- #
44
- # info - A Hash from the parsed API response with the following keys:
45
- # :id - The ID of the BedType.
46
- # :description 3- The description of the BedType.
47
- def initialize(info)
48
- @id, @description = info[:id], info[:description]
49
- end
50
- end
1
+ require "suitcase/hotel/amenity"
2
+ require "suitcase/hotel/session"
3
+ require "suitcase/hotel/bed_type"
4
+ require "suitcase/hotel/cache"
5
+ require "suitcase/hotel/ean_exception"
6
+ require "suitcase/hotel/helpers"
7
+ require "suitcase/hotel/image"
8
+ require "suitcase/hotel/location"
9
+ require "suitcase/hotel/nightly_rate"
10
+ require "suitcase/hotel/payment_option"
11
+ require "suitcase/hotel/reservation"
12
+ require "suitcase/hotel/room"
13
+ require "suitcase/hotel/surcharge"
51
14
 
15
+ module Suitcase
52
16
  # Public: A Class representing a single Hotel. It provides methods for
53
17
  # all Hotel EAN-related queries in the gem.
54
18
  class Hotel
@@ -385,7 +349,10 @@ module Suitcase
385
349
  room_data[:hotel_id] = hotel_id
386
350
  room_data[:supplier_type] = supplier_type
387
351
  room_data[:rooms] = params[:rooms]
388
- binding.pry
352
+ room_data[:surcharges] = raw_data["RateInfo"]["ChargeableRateInfo"] &&
353
+ raw_data["RateInfo"]["ChargeableRateInfo"]["Surcharges"] &&
354
+ [raw_data["RateInfo"]["ChargeableRateInfo"]["Surcharges"]["Surcharge"]].
355
+ flatten.map { |s| Surcharge.parse(s) }
389
356
  room_data[:bed_types] = [raw_data["BedTypes"]["BedType"]].flatten.map do |x|
390
357
  BedType.new(id: x["@id"], description: x["description"])
391
358
  end if raw_data["BedTypes"] && raw_data["BedTypes"]["BedType"]
@@ -1,3 +1,3 @@
1
1
  module Suitcase
2
- VERSION = "1.6.3"
2
+ VERSION = "1.6.5"
3
3
  end
data/lib/suitcase.rb CHANGED
@@ -11,16 +11,6 @@ require "suitcase/core_ext/string"
11
11
 
12
12
  require "suitcase/configuration"
13
13
 
14
- require "suitcase/hotel/session"
15
- require "suitcase/hotel/helpers"
16
- require "suitcase/hotel/cache"
17
- require "suitcase/hotel/location"
18
- require "suitcase/hotel/amenity"
19
- require "suitcase/hotel/reservation"
20
- require "suitcase/hotel/nightly_rate"
21
- require "suitcase/hotel/room"
22
- require "suitcase/hotel/payment_option"
23
- require "suitcase/hotel/hotel"
24
- require "suitcase/hotel/image"
14
+ require "suitcase/hotel"
25
15
 
26
16
  require "suitcase/car_rental"
@@ -13,7 +13,7 @@ describe Suitcase do
13
13
  Suitcase::Hotel.find(location: "Boston, US")
14
14
 
15
15
  # Query 3
16
- room = hotel.rooms(arrival: "6/23/2012", departure: "6/30/2012").first
16
+ room = hotel.rooms(arrival: Keys::RESERVATION_START_TIME, departure: Keys::RESERVATION_END_TIME).first
17
17
 
18
18
  # Query 4
19
19
  Suitcase::Hotel::PaymentOption.find currency_code: "USD"
@@ -29,14 +29,14 @@ describe Suitcase do
29
29
  it "retrieves from the cache if it's there" do
30
30
  hotel = Suitcase::Hotel.find(id: 123904)
31
31
  Suitcase::Hotel.find(location: "Boston, US")
32
- hotel.rooms(arrival: "6/23/2012", departure: "6/30/2012")
32
+ hotel.rooms(arrival: Keys::RESERVATION_START_TIME, departure: Keys::RESERVATION_END_TIME)
33
33
  Suitcase::Hotel::PaymentOption.find currency_code: "USD"
34
34
 
35
35
  # Disable API access
36
36
  Net::HTTP.expects(:get_response).never
37
37
  hotel = Suitcase::Hotel.find(id: 123904)
38
38
  Suitcase::Hotel.find(location: "Boston, US")
39
- hotel.rooms(arrival: "6/23/2012", departure: "6/30/2012")
39
+ hotel.rooms(arrival: Keys::RESERVATION_START_TIME, departure: Keys::RESERVATION_END_TIME)
40
40
  Suitcase::Hotel::PaymentOption.find currency_code: "USD"
41
41
  end
42
42
  end
@@ -1,8 +1,8 @@
1
1
  require "minitest_helper"
2
2
 
3
- describe Suitcase::EANException do
3
+ describe Suitcase::Hotel::EANException do
4
4
  before :each do
5
- @exception = Suitcase::EANException.new(nil)
5
+ @exception = Suitcase::Hotel::EANException.new(nil)
6
6
  end
7
7
 
8
8
  it "has an accessor recovery" do
@@ -35,7 +35,7 @@ describe Suitcase::Hotel::Helpers do
35
35
  response = FakeResponse.new(code: 403, body: "<h1>An error occurred.</h1>")
36
36
  Net::HTTP.stubs(:get_response).returns(response)
37
37
  Dummy.parse_response(URI.parse("http://fake.response.will.be.used"))
38
- end.must_raise Suitcase::EANException
38
+ end.must_raise Suitcase::Hotel::EANException
39
39
  end
40
40
  end
41
41
 
@@ -47,7 +47,7 @@ describe Suitcase::Hotel do
47
47
  it "sets a recovery attribute on the raised error when the location is not specific enough" do
48
48
  begin
49
49
  Suitcase::Hotel.find(location: "Mexico")
50
- rescue Suitcase::EANException => e
50
+ rescue Suitcase::Hotel::EANException => e
51
51
  e.recoverable?.must_equal(true) if e.type == :multiple_locations
52
52
  end
53
53
  end
@@ -55,7 +55,7 @@ describe Suitcase::Hotel do
55
55
  it "sets the error type when the location is not specific enough" do
56
56
  begin
57
57
  Suitcase::Hotel.find(location: "Mexico")
58
- rescue Suitcase::EANException => e
58
+ rescue Suitcase::Hotel::EANException => e
59
59
  e.type.must_equal(:multiple_locations)
60
60
  e.recovery.must_be_kind_of(Hash)
61
61
  e.recovery[:alternate_locations].must_be_kind_of(Array)
@@ -107,7 +107,6 @@ describe Suitcase::Hotel do
107
107
  @rooms.each do |r|
108
108
  r.deposit_required.wont_be_nil
109
109
  end
110
- binding.pry
111
110
  end
112
111
  end
113
112
  end
@@ -2,7 +2,7 @@ require "minitest_helper"
2
2
 
3
3
  describe Suitcase::Hotel::Room do
4
4
  before :each do
5
- @room = Suitcase::Hotel.find(id: 123904).rooms(arrival: "6/23/2012", departure: "6/30/2012").first
5
+ @room = Suitcase::Hotel.find(id: 123904).rooms(arrival: Keys::RESERVATION_START_TIME, departure: Keys::RESERVATION_END_TIME).first
6
6
  end
7
7
 
8
8
  %w(arrival departure rate_code room_type_code supplier_type tax_rate
@@ -19,7 +19,7 @@ describe Suitcase::Hotel::Room do
19
19
 
20
20
  describe "#reserve!" do
21
21
  before :each do
22
- @info = { email: "walter.john.nelson@gmail.com",
22
+ @info = { email: Keys::SENDING_EMAIL,
23
23
  first_name: "Walter",
24
24
  last_name: "Nelson",
25
25
  home_phone: "3831039402",
data/test/keys.rb CHANGED
@@ -23,6 +23,8 @@ module Keys
23
23
  CREDIT_CARD_CVV_TESTING = "123"
24
24
  CREDIT_CARD_EXPIRATION_DATE_TESTING = "2014/03/01"
25
25
 
26
+ SENDING_EMAIL = "testemail@gmail.com"
27
+
26
28
  VALID_RESERVATION_INFO = {
27
29
  email: "testemail@gmail.com",
28
30
  first_name: "Test Booking",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suitcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -148,6 +148,7 @@ extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
150
  - .gitignore
151
+ - CHANGELOG.md
151
152
  - Gemfile
152
153
  - README.md
153
154
  - Rakefile
@@ -159,10 +160,12 @@ files:
159
160
  - lib/suitcase/codes.rb
160
161
  - lib/suitcase/configuration.rb
161
162
  - lib/suitcase/core_ext/string.rb
163
+ - lib/suitcase/hotel.rb
162
164
  - lib/suitcase/hotel/amenity.rb
165
+ - lib/suitcase/hotel/bed_type.rb
163
166
  - lib/suitcase/hotel/cache.rb
167
+ - lib/suitcase/hotel/ean_exception.rb
164
168
  - lib/suitcase/hotel/helpers.rb
165
- - lib/suitcase/hotel/hotel.rb
166
169
  - lib/suitcase/hotel/image.rb
167
170
  - lib/suitcase/hotel/location.rb
168
171
  - lib/suitcase/hotel/nightly_rate.rb
@@ -170,6 +173,7 @@ files:
170
173
  - lib/suitcase/hotel/reservation.rb
171
174
  - lib/suitcase/hotel/room.rb
172
175
  - lib/suitcase/hotel/session.rb
176
+ - lib/suitcase/hotel/surcharge.rb
173
177
  - lib/suitcase/version.rb
174
178
  - suitcase.gemspec
175
179
  - test/car_rentals/car_rental_test.rb