rthbound-suitcase 1.7.5 → 1.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@ require "suitcase/hotel/payment_option"
11
11
  require "suitcase/hotel/reservation"
12
12
  require "suitcase/hotel/room"
13
13
  require "suitcase/hotel/surcharge"
14
+ require "suitcase/hotel/cancellation"
14
15
 
15
16
  module Suitcase
16
17
  # Public: A Class representing a single Hotel. It provides methods for
@@ -172,8 +173,13 @@ module Suitcase
172
173
  if Configuration.cache? and Configuration.cache.cached?(:list, params)
173
174
  parsed = Configuration.cache.get_query(:list, params)
174
175
  else
175
- url = url(method: "list", params: params, session: info[:session])
176
- parsed = parse_response(url)
176
+ # Handle large queries as post request
177
+ if info[:large_query]
178
+ url = url(as_form: true, method: "list", params: params, session: info[:session])
179
+ else
180
+ url = url(method: "list", params: params, session: info[:session])
181
+ end
182
+ parsed = parse_response(url, params, info)
177
183
  handle_errors(parsed)
178
184
  if Configuration.cache?
179
185
  Configuration.cache.save_query(:list, params, parsed)
@@ -0,0 +1,55 @@
1
+ module Suitcase
2
+ class Hotel
3
+ class Cancellation
4
+ extend Helpers
5
+ include Helpers
6
+
7
+ attr_accessor :itinerary_id, :email,
8
+ :confirmation_number,
9
+ :reason, :cancellation_number
10
+
11
+ # Accepts a hash with the itinerary_id, confirmation_number, email
12
+ # and optional reason code (COP ILL DEA OTH)
13
+ def initialize(info)
14
+ info.each do |k, v|
15
+ instance_variable_set("@" + k.to_s, v)
16
+ end
17
+ end
18
+
19
+ # Makes the call to EAN and if successful sets the
20
+ # cancellation_number attribute
21
+ def cancel_reservation!
22
+ params = {}
23
+ params["itineraryId"] = itinerary_id
24
+ params["email"] = email
25
+ params["confirmationNumber"] = confirmation_number
26
+ params["reason"] = reason if valid_reason?
27
+
28
+ uri = Cancellation.url(
29
+ method: 'cancel',
30
+ params: params,
31
+ include_key: true,
32
+ include_cid: true,
33
+ secure: true
34
+ )
35
+
36
+ session = Patron::Session.new
37
+ session.timeout = 30000
38
+ session.base_url = "https://" + uri.host
39
+ res = session.post uri.request_uri, {}
40
+ parsed = JSON.parse res.body
41
+ handle_errors(parsed)
42
+ @cancellation_number = parsed["HotelRoomCancellationResponse"]["cancellationNumber"]
43
+ end
44
+
45
+ def reservation_canceled?
46
+ !cancellation_number.nil?
47
+ end
48
+
49
+ def valid_reason?
50
+ %w(COP ILL DEA OTH).include?(reason)
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -83,8 +83,14 @@ module Suitcase
83
83
  # uri - The URI to parse the JSON from.
84
84
  #
85
85
  # Returns the parsed JSON.
86
- def parse_response(uri)
87
- response = Net::HTTP.get_response(uri)
86
+ def parse_response(uri, params = {}, info = {})
87
+ if info[:large_query]
88
+ params["apiKey"] = Suitcase::Configuration.hotel_api_key
89
+ params["cid"] = (Suitcase::Configuration.hotel_cid.to_s ||= '55505')
90
+ response = Net::HTTP.post_form(uri, params)
91
+ else
92
+ response = Net::HTTP.get_response(uri)
93
+ end
88
94
 
89
95
  if response.code.to_i == 403
90
96
  if response.body.include?("Forbidden")
@@ -115,8 +121,8 @@ module Suitcase
115
121
 
116
122
  raise e
117
123
  end
118
-
119
- JSON.parse(Net::HTTP.get_response(uri).body)
124
+
125
+ JSON.parse(response.body)
120
126
  end
121
127
 
122
128
  # Internal: Raise the errors returned from the response.
@@ -1,3 +1,3 @@
1
1
  module Suitcase
2
- VERSION = "1.7.5"
2
+ VERSION = "1.7.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rthbound-suitcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.5
4
+ version: 1.7.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-09 00:00:00.000000000 Z
13
+ date: 2012-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -165,6 +165,7 @@ files:
165
165
  - lib/suitcase/hotel/amenity.rb
166
166
  - lib/suitcase/hotel/bed_type.rb
167
167
  - lib/suitcase/hotel/cache.rb
168
+ - lib/suitcase/hotel/cancellation.rb
168
169
  - lib/suitcase/hotel/ean_exception.rb
169
170
  - lib/suitcase/hotel/helpers.rb
170
171
  - lib/suitcase/hotel/image.rb
@@ -204,23 +205,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
205
  - - ! '>='
205
206
  - !ruby/object:Gem::Version
206
207
  version: '0'
207
- segments:
208
- - 0
209
- hash: 3047620281659721395
210
208
  required_rubygems_version: !ruby/object:Gem::Requirement
211
209
  none: false
212
210
  requirements:
213
211
  - - ! '>='
214
212
  - !ruby/object:Gem::Version
215
213
  version: '0'
216
- segments:
217
- - 0
218
- hash: 3047620281659721395
219
214
  requirements: []
220
215
  rubyforge_project:
221
- rubygems_version: 1.8.24
216
+ rubygems_version: 1.8.21
222
217
  signing_key:
223
218
  specification_version: 3
224
219
  summary: Locates available hotels and rental cars through Expedia and Hotwire. This
225
220
  is a fork of Walter Nelson's gem - suitcase
226
- test_files: []
221
+ test_files:
222
+ - test/car_rentals/car_rental_test.rb
223
+ - test/hotels/amenity_test.rb
224
+ - test/hotels/caching_test.rb
225
+ - test/hotels/ean_exception_test.rb
226
+ - test/hotels/helpers_test.rb
227
+ - test/hotels/hotel_location_test.rb
228
+ - test/hotels/hotel_test.rb
229
+ - test/hotels/image_test.rb
230
+ - test/hotels/payment_option_test.rb
231
+ - test/hotels/reservation_test.rb
232
+ - test/hotels/room_test.rb
233
+ - test/hotels/session_test.rb
234
+ - test/keys.rb
235
+ - test/minitest_helper.rb
236
+ - test/support/fake_response.rb
237
+ has_rdoc: