suitcase 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -1
- data/examples/hotel_image_db.rb +24 -0
- data/lib/suitcase/hotel/helpers.rb +33 -1
- data/lib/suitcase/version.rb +1 -1
- data/test/hotels/helpers_test.rb +8 -0
- data/test/minitest_helper.rb +9 -0
- data/test/support/fake_response.rb +13 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -32,7 +32,7 @@ hotel = hotels[1]
|
|
32
32
|
# Get the rooms for a specific date
|
33
33
|
rooms = hotel.rooms(arrival: "7/1/2013", departure: "7/8/2013", rooms: [{ adults: 1, children_ages: [2, 3] }, { adults: 1, children_ages: [4] }])
|
34
34
|
# Find a payment option that is compatible with USD
|
35
|
-
payment_option = Suitcase::PaymentOption.find(currency_code: "USD")
|
35
|
+
payment_option = Suitcase::Hotel::PaymentOption.find(currency_code: "USD")
|
36
36
|
# Pick a specific room
|
37
37
|
room = rooms.first
|
38
38
|
# Set the bed type on each of the rooms to be ordered
|
@@ -45,6 +45,9 @@ room.reserve!(reservation_hash)
|
|
45
45
|
|
46
46
|
You can setup a cache to store all API requests that do not contain secure information (i.e. anything but booking requests). A cache needs to be able store deeply nested Hashes and have a method called #[] to access them. An example of setting the cache is given above. Check the `examples/hash_adapter.rb` for a trivial example of the required methods. A Redis adapter is also in the examples directory.
|
47
47
|
|
48
|
+
#### Using the downloadable images
|
49
|
+
|
50
|
+
EAN provides a [downloadable image "database"](http://developer.ean.com/database_catalogs/relational/Image_Data) that doesn't require using the image URLs fetched by the API.For example usage of this database, check out `examples/hotel_image_db.rb`.
|
48
51
|
|
49
52
|
### Car rentals
|
50
53
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
FILENAME = ENV["HOTEL_IMAGES"] || "HotelImageList.txt"
|
2
|
+
|
3
|
+
IMAGES = {}
|
4
|
+
|
5
|
+
def images_for(hotel)
|
6
|
+
IMAGES[hotel.id.to_i] ||= IO.foreach(FILENAME).map do |line|
|
7
|
+
split = line.split("|")
|
8
|
+
if hotel.id.to_i == split[0].to_i
|
9
|
+
Suitcase::Image.new({
|
10
|
+
"caption" => split[1],
|
11
|
+
"url" => split[2],
|
12
|
+
"thumbnailUrl" => split[6],
|
13
|
+
"width" => split[3],
|
14
|
+
"height" => split[4]
|
15
|
+
})
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
# examples
|
23
|
+
|
24
|
+
images_for(Suitcase::Hotel.find(location: "Boston")[0])
|
@@ -77,12 +77,44 @@ module Suitcase
|
|
77
77
|
url
|
78
78
|
end
|
79
79
|
|
80
|
-
# Internal: Parse the JSON response at the given URL.
|
80
|
+
# Internal: Parse the JSON response at the given URL and handle errors.
|
81
81
|
#
|
82
82
|
# uri - The URI to parse the JSON from.
|
83
83
|
#
|
84
84
|
# Returns the parsed JSON.
|
85
85
|
def parse_response(uri)
|
86
|
+
response = Net::HTTP.get_response(uri)
|
87
|
+
|
88
|
+
if response.code.to_i == 403
|
89
|
+
if response.body.include?("Forbidden")
|
90
|
+
e = EANException.new("You have not been granted permission to access the requested method or object.")
|
91
|
+
e.type = :forbidden
|
92
|
+
elsif response.body.include?("Not Authorized")
|
93
|
+
e = EANException.new("The API key associated with your request was not recognized, or the digital signature was incorrect.")
|
94
|
+
e.type = :not_authorized
|
95
|
+
elsif response.body.include?("Developer Inactive")
|
96
|
+
e = EANException.new("The API key you are using to access the API has not been approved, is not correct, or has been disabled. If using SIG Authentication, your digital signature is incorrect and does not match the one generated when receiving your request.")
|
97
|
+
e.type = :developer_inactive
|
98
|
+
elsif response.body.include?("Queries Per Second Limit")
|
99
|
+
e = EANException.new("The API key you are using has attempted to access the API too many times in one second.")
|
100
|
+
e.type = :query_limit
|
101
|
+
elsif response.body.include?("Account Over Rate Limit")
|
102
|
+
e = EANException.new("The API key you are using has attempted to access the API too many times in the rate limiting period.")
|
103
|
+
e.type = :rate_limit
|
104
|
+
elsif response.body.include?("Rate Limit Exceeded")
|
105
|
+
e = EANException.new("The service you have requested is over capacity.")
|
106
|
+
e.type = :over_capacity
|
107
|
+
elsif response.body.include?("Authentication Failure")
|
108
|
+
e = EANException.new("The combination of authentication checks failed.")
|
109
|
+
e.type = :authentication_failure
|
110
|
+
else
|
111
|
+
e = EANException.new("An unknown error occured: #{response.body}.")
|
112
|
+
e.type = :unknown
|
113
|
+
end
|
114
|
+
|
115
|
+
raise e
|
116
|
+
end
|
117
|
+
|
86
118
|
JSON.parse(Net::HTTP.get_response(uri).body)
|
87
119
|
end
|
88
120
|
|
data/lib/suitcase/version.rb
CHANGED
data/test/hotels/helpers_test.rb
CHANGED
@@ -29,6 +29,14 @@ describe Suitcase::Hotel::Helpers do
|
|
29
29
|
Dummy.parse_response(URI.parse("http://google.com"))
|
30
30
|
end.must_raise JSON::ParserError
|
31
31
|
end
|
32
|
+
|
33
|
+
it "raises an error if a 403 code is received" do
|
34
|
+
proc do
|
35
|
+
response = FakeResponse.new(code: 403, body: "<h1>An error occurred.</h1>")
|
36
|
+
Net::HTTP.stubs(:get_response).returns(response)
|
37
|
+
Dummy.parse_response(URI.parse("http://fake.response.will.be.used"))
|
38
|
+
end.must_raise Suitcase::EANException
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
describe "#generate_signature" do
|
data/test/minitest_helper.rb
CHANGED
@@ -1,15 +1,24 @@
|
|
1
|
+
# Testing frameworks
|
1
2
|
require "turn"
|
2
3
|
require "minitest/spec"
|
3
4
|
require "minitest/autorun"
|
4
5
|
require "mocha"
|
5
6
|
|
7
|
+
# Debugger
|
6
8
|
require "pry"
|
7
9
|
|
10
|
+
# The gem
|
8
11
|
$: << File.dirname(__FILE__) + "/../lib"
|
9
12
|
$: << File.dirname(__FILE__)
|
10
13
|
require "suitcase"
|
14
|
+
|
15
|
+
# API keys
|
11
16
|
require "keys"
|
12
17
|
|
18
|
+
# Support files
|
19
|
+
require "support/fake_response"
|
20
|
+
|
21
|
+
# Turn configuration
|
13
22
|
Turn.config do |config|
|
14
23
|
config.format = :pretty
|
15
24
|
# config.trace = true
|
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.5.
|
4
|
+
version: 1.5.1
|
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-
|
12
|
+
date: 2012-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
138
|
- examples/hash_adapter.rb
|
139
|
+
- examples/hotel_image_db.rb
|
139
140
|
- examples/redis_adapter.rb
|
140
141
|
- lib/suitcase.rb
|
141
142
|
- lib/suitcase/car_rental.rb
|
@@ -169,6 +170,7 @@ files:
|
|
169
170
|
- test/hotels/session_test.rb
|
170
171
|
- test/keys.rb
|
171
172
|
- test/minitest_helper.rb
|
173
|
+
- test/support/fake_response.rb
|
172
174
|
homepage: http://github.com/thoughtfusion/suitcase
|
173
175
|
licenses: []
|
174
176
|
post_install_message:
|
@@ -208,4 +210,5 @@ test_files:
|
|
208
210
|
- test/hotels/session_test.rb
|
209
211
|
- test/keys.rb
|
210
212
|
- test/minitest_helper.rb
|
213
|
+
- test/support/fake_response.rb
|
211
214
|
has_rdoc:
|