suitcase 1.6.7 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -251,34 +251,6 @@ module Suitcase
251
251
  images || []
252
252
  end
253
253
 
254
- # Internal: Raise the errors returned from the response.
255
- #
256
- # info - The parsed JSON to get the errors from.
257
- #
258
- # Returns nothing.
259
- def self.handle_errors(info)
260
- key = info.keys.first
261
- if info[key] && info[key]["EanWsError"]
262
- message = info[key]["EanWsError"]["presentationMessage"]
263
- exception = EANException.new(message)
264
- if message =~ /Multiple locations/ && (info = info[key]["LocationInfos"])
265
- exception.type = :multiple_locations
266
- exception.recovery = {
267
- alternate_locations: info["LocationInfo"].map do |info|
268
- Location.new(
269
- destination_id: info["destinationId"],
270
- type: info["type"],
271
- city: info["city"],
272
- province: info["stateProvinceCode"]
273
- )
274
- end
275
- }
276
- end
277
-
278
- raise exception
279
- end
280
- end
281
-
282
254
  # Internal: Split an Array of multiple Hotels.
283
255
  #
284
256
  # parsed - The parsed JSON of the Hotels.
@@ -58,7 +58,7 @@ module Suitcase
58
58
  params["apiKey"] = Configuration.hotel_api_key if builder[:include_key]
59
59
  params["cid"] = (Configuration.hotel_cid ||= 55505) if builder[:include_cid]
60
60
  params["sig"] = generate_signature if Configuration.use_signature_auth?
61
-
61
+
62
62
  url = main_url(builder[:secure]) + method.to_s + (builder[:as_form] ? "" : "?")
63
63
 
64
64
  params.merge!(build_session_params(builder[:session]))
@@ -111,13 +111,43 @@ module Suitcase
111
111
  e = EANException.new("An unknown error occured: #{response.body}.")
112
112
  e.type = :unknown
113
113
  end
114
-
114
+
115
115
  raise e
116
116
  end
117
117
 
118
118
  JSON.parse(Net::HTTP.get_response(uri).body)
119
119
  end
120
120
 
121
+ # Internal: Raise the errors returned from the response.
122
+ #
123
+ # info - The parsed JSON to get the errors from.
124
+ #
125
+ # Returns nothing.
126
+ def handle_errors(info)
127
+ key = info.keys.first
128
+ if info[key] && info[key]["EanWsError"]
129
+ message = info[key]["EanWsError"]["presentationMessage"]
130
+ exception = EANException.new(message)
131
+ if message =~ /Multiple locations/ && (info = info[key]["LocationInfos"])
132
+ exception.type = :multiple_locations
133
+ exception.recovery = {
134
+ alternate_locations: info["LocationInfo"].map do |info|
135
+ Location.new(
136
+ destination_id: info["destinationId"],
137
+ type: info["type"],
138
+ city: info["city"],
139
+ province: info["stateProvinceCode"]
140
+ )
141
+ end
142
+ }
143
+ elsif message =~ /Data in this request could not be validated/
144
+ exception.type = :invalid_data
145
+ end
146
+
147
+ raise exception
148
+ end
149
+ end
150
+
121
151
  # Internal: Get the base URL based on a Hash of info.
122
152
  #
123
153
  # info - A Hash with only one required key:
@@ -10,9 +10,10 @@ module Suitcase
10
10
  :average_nightly_rate, :promo, :arrival, :departure, :rooms,
11
11
  :bed_types, :cancellation_policy, :non_refundable,
12
12
  :guarantee_required, :deposit_required, :surcharges,
13
- :rate_description, :raw
13
+ :rate_description, :raw, :rate_change, :guarantee_only
14
14
 
15
15
  extend Helpers
16
+ include Helpers
16
17
 
17
18
  # Internal: Create a new Room from within a Room search query.
18
19
  #
@@ -50,12 +51,18 @@ module Suitcase
50
51
  params["extension"] = info[:work_phone_extension] if info[:work_phone_extension]
51
52
  params["faxPhone"] = info[:fax_phone] if info[:fax_phone]
52
53
  params["companyName"] = info[:company_name] if info[:company_name]
53
- params["emailIntineraryList"] = info[:additional_emails].join(",") if info[:additional_emails]
54
+ if info[:additional_emails]
55
+ params["emailIntineraryList"] = info[:additional_emails].join(",")
56
+ end
54
57
  params["creditCardType"] = info[:payment_option].code
55
58
  params["creditCardNumber"] = info[:credit_card_number]
56
59
  params["creditCardIdentifier"] = info[:credit_card_verification_code]
57
60
  expiration_date = Date._parse(info[:credit_card_expiration_date])
58
- params["creditCardExpirationMonth"] = (expiration_date[:mon].to_s.length == 1 ? "0" + expiration_date[:mon].to_s : expiration_date[:mon].to_s)
61
+ params["creditCardExpirationMonth"] = if expiration_date[:mon] < 10
62
+ "0" + expiration_date[:mon].to_s
63
+ else
64
+ expiration_date[:mon].to_s
65
+ end
59
66
  params["creditCardExpirationYear"] = expiration_date[:year].to_s
60
67
  params["address1"] = info[:address1]
61
68
  params["address2"] = info[:address2] if info[:address2]
@@ -73,7 +80,13 @@ module Suitcase
73
80
  params["countryCode"] = info[:country]
74
81
  params["postalCode"] = info[:postal_code]
75
82
 
76
- uri = Room.url :method => "res", :params => params, :include_key => true, :include_cid => true, :secure => true
83
+ uri = Room.url(
84
+ method: "res",
85
+ params: params,
86
+ include_key: true,
87
+ include_cid: true,
88
+ secure: true
89
+ )
77
90
  session = Patron::Session.new
78
91
  session.timeout = 30000
79
92
  session.base_url = "https://" + uri.host
@@ -81,7 +94,8 @@ module Suitcase
81
94
  parsed = JSON.parse res.body
82
95
 
83
96
  reservation_res = parsed["HotelRoomReservationResponse"]
84
- surcharges = if @supplier_type == "E"
97
+ handle_errors(parsed)
98
+ surcharges = if @supplier_type == "E" && reservation_res["RateInfo"]["ChargeableRateInfo"]["Surcharges"]
85
99
  [reservation_res["RateInfo"]["ChargeableRateInfo"]["Surcharges"]["Surcharge"]].
86
100
  flatten.map { |s| Surcharge.parse(s) }
87
101
  else
@@ -2,6 +2,7 @@ module Suitcase
2
2
  class Hotel
3
3
  # Public: A Surcharge represents a single surcharge on a Room.
4
4
  class Surcharge
5
+ attr_accessor :amount, :type
5
6
  # Internal: Create a new Surcharge.
6
7
  #
7
8
  # info - A Hash of parsed info from Surcharge.parse.
@@ -1,3 +1,3 @@
1
1
  module Suitcase
2
- VERSION = "1.6.7"
2
+ VERSION = "1.7.0"
3
3
  end
@@ -41,5 +41,10 @@ describe Suitcase::Hotel::Room do
41
41
  reservation = @room.reserve!(@info)
42
42
  reservation.must_be_kind_of(Suitcase::Hotel::Reservation)
43
43
  end
44
+
45
+ it "raises errors on invalid info" do
46
+ lambda { @room.reserve!(@info.merge(credit_card_number: "")) }.must_raise Suitcase::Hotel::EANException
47
+ end
44
48
  end
45
49
  end
50
+
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.7
4
+ version: 1.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-12 00:00:00.000000000 Z
12
+ date: 2012-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  segments:
207
207
  - 0
208
- hash: 1258883948376164129
208
+ hash: -43637358386494450
209
209
  required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  none: false
211
211
  requirements:
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  segments:
216
216
  - 0
217
- hash: 1258883948376164129
217
+ hash: -43637358386494450
218
218
  requirements: []
219
219
  rubyforge_project:
220
220
  rubygems_version: 1.8.24