expedia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.textile +138 -0
- data/Rakefile +1 -0
- data/expedia.gemspec +28 -0
- data/lib/expedia/api.rb +69 -0
- data/lib/expedia/errors.rb +52 -0
- data/lib/expedia/http_service/response.rb +26 -0
- data/lib/expedia/http_service.rb +97 -0
- data/lib/expedia/railtie.rb +12 -0
- data/lib/expedia/utils.rb +33 -0
- data/lib/expedia/version.rb +3 -0
- data/lib/expedia.rb +36 -0
- data/lib/tasks/expedia.rake +13 -0
- data/lib/templates/expedia.txt +8 -0
- data/spec/http_service_spec.rb +56 -0
- data/spec/spec_helper.rb +18 -0
- metadata +163 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Zaid Akram
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
h1. Expedia
|
2
|
+
|
3
|
+
Expedia is a ruby wrapper for ["EAN - Expedia Affiliate Network":http://www.expediaaffiliate.com] APIs.
|
4
|
+
|
5
|
+
Other details of this gem are:
|
6
|
+
|
7
|
+
* It uses the the latest verion of the EAN API. i.e ["Version 3":http://developer.ean.com/docs/read/hotels/version_3]
|
8
|
+
* Only REST API support (No XML or SOAP support)
|
9
|
+
|
10
|
+
h2. Installation
|
11
|
+
|
12
|
+
For Rails Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
<pre>
|
15
|
+
gem 'expedia'
|
16
|
+
</pre>
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
<pre>
|
21
|
+
$ bundle
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
<pre>
|
27
|
+
$ gem install expedia
|
28
|
+
</pre>
|
29
|
+
|
30
|
+
Either you can configure Expedia in code on run-time
|
31
|
+
|
32
|
+
<pre>
|
33
|
+
Expedia.cid = 55505
|
34
|
+
Expedia.api_key = 'your_api_key'
|
35
|
+
Expedia.shared_secret = 'your_shared_secret'
|
36
|
+
Expedia.locale = 'en_US'
|
37
|
+
Expedia.currency_code = 'USD'
|
38
|
+
Expedia.minor_rev = 13
|
39
|
+
</pre>
|
40
|
+
|
41
|
+
Or you can execute the following command to create an intializer:
|
42
|
+
|
43
|
+
<pre>
|
44
|
+
$ rake expedia:initialize
|
45
|
+
</pre>
|
46
|
+
|
47
|
+
h2. Usage
|
48
|
+
|
49
|
+
After configuring keys for your EAN application kyes, Default locale, currency and minor_rev use
|
50
|
+
|
51
|
+
<pre>
|
52
|
+
# Instentiate api object
|
53
|
+
api = Expedia::API.new
|
54
|
+
|
55
|
+
# Method to search hotel. see http://developer.ean.com/docs/read/hotels/version_3/request_hotel_list
|
56
|
+
response = api.get_list({:propertyName => 'Hotel Moa Berlin', :destinationString => 'berlin'})
|
57
|
+
</pre>
|
58
|
+
|
59
|
+
Following methods are expeosed by Expedia::API object
|
60
|
+
|
61
|
+
Note: All method naming is done in correspondence with Expedia services and ruby conventions
|
62
|
+
see "Hotel API Documentation - Services section":http://developer.ean.com/docs/read/hotels#.UMf_hiNDt0w
|
63
|
+
|
64
|
+
<pre>
|
65
|
+
get_list({})
|
66
|
+
geo_search({})
|
67
|
+
get_availability({})
|
68
|
+
get_room_images({})
|
69
|
+
get_information({})
|
70
|
+
get_rules({})
|
71
|
+
get_itinerary({})
|
72
|
+
get_alternate_properties({})
|
73
|
+
get_reservation({})
|
74
|
+
get_payment_info({})
|
75
|
+
get_cancel({})
|
76
|
+
get_ping({})
|
77
|
+
get_static_reservation({}) # To test Reservation (Static Reservation)
|
78
|
+
</pre>
|
79
|
+
|
80
|
+
Every method accepts Hash of parameter specific to every API. see ["EAN Docs":http://developer.ean.com/docs/read/hotels/version_3] for more details.
|
81
|
+
|
82
|
+
h3. Success
|
83
|
+
|
84
|
+
if request is successfull you will get a Expedia::HTTPService::Response object in response.
|
85
|
+
and you can use
|
86
|
+
|
87
|
+
<pre>
|
88
|
+
response.status
|
89
|
+
response.body
|
90
|
+
response.headers
|
91
|
+
</pre>
|
92
|
+
|
93
|
+
h3. Error
|
94
|
+
|
95
|
+
In case of any error a Expedia::APIError object is returned.
|
96
|
+
|
97
|
+
Note: Expedia responds with status of 200 even if there is an exception (most of the times). So no Exception is raised!
|
98
|
+
|
99
|
+
<pre>
|
100
|
+
# See http://developer.ean.com/docs/read/error_handling/Hotel_V3_Exception_Details
|
101
|
+
|
102
|
+
response.status # Response status
|
103
|
+
response.error_body # Complete error body
|
104
|
+
response.category # Value indicating the nature of the exception or the reason it occurred
|
105
|
+
response.presentation_message # Presentation error message returned
|
106
|
+
response.verbose_message # More specific detailed error message
|
107
|
+
response.handling # value indicating the severity of the exception and how it may be handled
|
108
|
+
</pre>
|
109
|
+
|
110
|
+
h3. Test Booking (Static Reservation)
|
111
|
+
|
112
|
+
For Static reservation use get_static_reservation() method.
|
113
|
+
|
114
|
+
CAUTION: Do Not send adress and booking information (creditCardNumber, creditCardIdentifier, creditCardExpirationMonth, creditCardExpirationYear, address1) in parameters to the method. Especially do not pass address1 parameter They are already been taken care of. For more on Static booking see ["Static Test Booking Credit Card Information":http://developer.ean.com/docs/Test_Booking_Procedures]
|
115
|
+
|
116
|
+
A static Booking example.
|
117
|
+
|
118
|
+
<pre>
|
119
|
+
response = api.get_static_reservation({ :arrivalDate => "10/10/2013", :departureDate => "10/12/2013",
|
120
|
+
:hotelID => 359433, :supplierType => "E", :rateKey => "084eab14-335e-46d6-aa2e-766fce6be32c",
|
121
|
+
:roomTypeCode => 200007964, :rateCode => 200865704, :chargeableRate => "142.8",
|
122
|
+
:room1 => "1", :room1FirstName => "test", :room1LastName => "testers", :room1BedTypeId => "15",
|
123
|
+
:room1SmokingPreference => "NS", :email => "test@tesing.com", :city => 'Bellevue',
|
124
|
+
:stateProvinceCode => 'WA', :countryCode => 'US', :postalCode => 98004 })
|
125
|
+
</pre>
|
126
|
+
|
127
|
+
h3. Logging
|
128
|
+
|
129
|
+
Expedia::Utils.logger points to STDOUT by default. You can use it to Log in Rails Applications
|
130
|
+
|
131
|
+
<pre>
|
132
|
+
Expedia::Utils.logger = Rails.logger
|
133
|
+
|
134
|
+
# And loggig methods available
|
135
|
+
[:debug, :info, :warn, :error, :fatal]
|
136
|
+
</pre>
|
137
|
+
|
138
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/expedia.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'expedia/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "expedia"
|
8
|
+
gem.version = Expedia::VERSION
|
9
|
+
gem.authors = ["Zaid Akram"]
|
10
|
+
gem.email = ["zaidakrammughal@gmail.com"]
|
11
|
+
gem.description = "Expedia is a lightweight, flexible Ruby SDK for EAN. It allows read/write access to the EAN APIs."
|
12
|
+
gem.summary = "Expedia is a ruby wrapper for 'EAN (Expedia Affiliate Network)'"
|
13
|
+
gem.homepage = "https://github.com/zaidakram/expedia"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency(%q<multi_json>, ["~> 1.3"])
|
21
|
+
gem.add_runtime_dependency(%q<faraday>, ["~> 0.8"])
|
22
|
+
gem.add_runtime_dependency(%q<colorize>, ["~> 0.5.8"])
|
23
|
+
gem.add_runtime_dependency(%q<addressable>, ["~> 2.2"])
|
24
|
+
gem.add_development_dependency(%q<rspec>, ["~> 2.8"])
|
25
|
+
gem.add_development_dependency(%q<rake>, ["~> 0.8"])
|
26
|
+
|
27
|
+
|
28
|
+
end
|
data/lib/expedia/api.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Expedia
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# All method naming is done in correspondence with Expedia services and ruby conventions
|
5
|
+
# see http://developer.ean.com/docs/read/hotels#.UMf_hiNDt0w
|
6
|
+
|
7
|
+
def get_list(args)
|
8
|
+
services('/ean-services/rs/hotel/v3/list', args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def geo_search(args)
|
12
|
+
services('/ean-services/rs/hotel/v3/geoSearch', args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_availability(args)
|
16
|
+
services('/ean-services/rs/hotel/v3/avail', args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_room_images(args)
|
20
|
+
services('/ean-services/rs/hotel/v3/roomImages', args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_information(args)
|
24
|
+
services('/ean-services/rs/hotel/v3/info', args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_rules(args)
|
28
|
+
services('/ean-services/rs/hotel/v3/rules', args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_itinerary(args)
|
32
|
+
services('/ean-services/rs/hotel/v3/itin', args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_alternate_properties(args)
|
36
|
+
services('/ean-services/rs/hotel/v3/altProps', args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_reservation(args)
|
40
|
+
HTTPService.make_request('/ean-services/rs/hotel/v3/res', args, :post, { :reservation_api => true, :use_ssl => true })
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_payment_info(args)
|
44
|
+
services('/ean-services/rs/hotel/v3/paymentInfo', args)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_cancel(args)
|
48
|
+
services('/ean-services/rs/hotel/v3/cancel', args)
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_ping(args)
|
52
|
+
services('/ean-services/rs/hotel/v3/ping', args)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_static_reservation(args)
|
56
|
+
get_reservation(args.merge!({:firstName => "Test Booking", :lastName => "Test Booking", :creditCardType => "CA",
|
57
|
+
:creditCardNumber => 5401999999999999, :creditCardIdentifier => 123,
|
58
|
+
:creditCardExpirationMonth => 11, :creditCardExpirationYear => Time.now.year + 2,
|
59
|
+
:address1 => 'travelnow' }))
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def services(path, args)
|
65
|
+
HTTPService.make_request(path, args, :get)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Expedia
|
2
|
+
|
3
|
+
class ExpediaError < StandardError; end
|
4
|
+
|
5
|
+
# Expedia respondes with status of 200 even if there is an exception (most of the time)
|
6
|
+
class APIError < ::Expedia::ExpediaError
|
7
|
+
|
8
|
+
# @status The HTTP status code of the response
|
9
|
+
# @error_body The parsed response body
|
10
|
+
# @error_info One of the following:
|
11
|
+
# @category Value indicating the nature of the exception or the reason it occurred
|
12
|
+
# @presentation_message Presentation error message returned
|
13
|
+
# @verbose_message More specific detailed error message
|
14
|
+
# @handling value indicating the severity of the exception and how it may be handled
|
15
|
+
|
16
|
+
attr_accessor :category, :presentation_message, :verbose_message,
|
17
|
+
:status, :error_body, :handling
|
18
|
+
|
19
|
+
# Create a new API Error
|
20
|
+
# @return the newly created APIError
|
21
|
+
def initialize(status, body)
|
22
|
+
@error_body = body
|
23
|
+
@status = status
|
24
|
+
|
25
|
+
begin
|
26
|
+
@error_body = @error_body[@error_body.keys[0]]['EanWsError']
|
27
|
+
rescue
|
28
|
+
end
|
29
|
+
|
30
|
+
unless @error_body.nil? || @error_body.empty?
|
31
|
+
@category = error_body['category']
|
32
|
+
@presentation_message = error_body['presentationMessage']
|
33
|
+
@verbose_message = error_body['verboseMessage']
|
34
|
+
@handling = error_body['handling']
|
35
|
+
error_array = []
|
36
|
+
end
|
37
|
+
|
38
|
+
super(@verbose_message)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# Just to enable user to call this method on response object to know if any exception has occured
|
43
|
+
# Free user form the Hastle of checking the class of object on every request.
|
44
|
+
def exception?
|
45
|
+
true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# A standard Error calss for Raising exception if [cid, shared_secret, api_key] are not provided.
|
50
|
+
class AuthCredentialsError < ::Expedia::ExpediaError; end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Expedia
|
2
|
+
|
3
|
+
module HTTPService
|
4
|
+
|
5
|
+
class Response
|
6
|
+
|
7
|
+
attr_reader :status, :body, :headers
|
8
|
+
|
9
|
+
# Creates a new Response object, which standardizes the response received From Expedia.
|
10
|
+
def initialize(status, body, headers)
|
11
|
+
@status = status
|
12
|
+
@body = MultiJson.load(body) rescue ''
|
13
|
+
@headers = headers
|
14
|
+
end
|
15
|
+
|
16
|
+
# Simple predicate method to check if there is any exception
|
17
|
+
def exception?
|
18
|
+
@headers['content-type'] != 'application/json' ||
|
19
|
+
(@body && @body[@body.keys[0]]['EanWsError']) ? true : false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'expedia/http_service/response'
|
3
|
+
|
4
|
+
module Expedia
|
5
|
+
module HTTPService
|
6
|
+
|
7
|
+
API_SERVER = 'api.ean.com'
|
8
|
+
RESERVATION_SERVER = 'book.api.ean.com'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
|
13
|
+
# The address of the appropriate Expedia server.
|
14
|
+
#
|
15
|
+
# @param options various flags to indicate which server to use.
|
16
|
+
# @option options :reservation_api use the RESERVATION API instead of the REGULAR API
|
17
|
+
# @option options :use_ssl force https, even if not needed
|
18
|
+
#
|
19
|
+
# @return a complete server address with protocol
|
20
|
+
def server(options = {})
|
21
|
+
server = "#{options[:reservation_api] ? RESERVATION_SERVER : API_SERVER}"
|
22
|
+
"#{options[:use_ssl] ? "https" : "http"}://#{server}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Makes a request directly to Expedia.
|
26
|
+
# @note You'll rarely need to call this method directly.
|
27
|
+
#
|
28
|
+
# @see Expedia::API#api
|
29
|
+
#
|
30
|
+
# @param path the server path for this request
|
31
|
+
# @param args (see Expedia::API#api)
|
32
|
+
# @param verb the HTTP method to use.
|
33
|
+
# @param options same options passed to server method.
|
34
|
+
#
|
35
|
+
# @raise an appropriate connection error if unable to make the request to Expedia
|
36
|
+
#
|
37
|
+
# @return [Expedia::HTTPService::Response] on success. A response object representing the results from Expedia
|
38
|
+
# @return [Expedia::APIError] on Error.
|
39
|
+
def make_request(path, args, verb, options = {})
|
40
|
+
args.merge!(add_common_parameters)
|
41
|
+
# figure out our options for this request
|
42
|
+
request_options = {:params => (verb == :get ? args : {})}
|
43
|
+
# set up our Faraday connection
|
44
|
+
conn = Faraday.new(server(options), request_options)
|
45
|
+
response = conn.send(verb, path, (verb == :post ? args : {}))
|
46
|
+
|
47
|
+
# Log URL and params information
|
48
|
+
Expedia::Utils.debug "\nExpedia [#{verb.upcase}] - #{server(options) + path} params: #{args.inspect} : #{response.status}\n"
|
49
|
+
response = Expedia::HTTPService::Response.new(response.status.to_i, response.body, response.headers)
|
50
|
+
|
51
|
+
# If there is an exception make a [Expedia::APIError] object to return
|
52
|
+
if response.exception?
|
53
|
+
Expedia::APIError.new(response.status, response.body)
|
54
|
+
else
|
55
|
+
response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Encodes a given hash into a query string.
|
60
|
+
#
|
61
|
+
# @param params_hash a hash of values to CGI-encode and appropriately join
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# Expedia.http_service.encode_params({:a => 2, :b => "My String"})
|
65
|
+
# => "a=2&b=My+String"
|
66
|
+
#
|
67
|
+
# @return the appropriately-encoded string
|
68
|
+
# Method currently not in use.
|
69
|
+
def encode_params(param_hash)
|
70
|
+
((param_hash || {}).sort_by{|k, v| k.to_s}.collect do |key_and_value|
|
71
|
+
key_and_value[1] = MultiJson.dump(key_and_value[1]) unless key_and_value[1].is_a? String
|
72
|
+
"#{key_and_value[0].to_s}=#{CGI.escape key_and_value[1]}"
|
73
|
+
end).join("&")
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Creates a Signature for Expedia using MD5 Checksum Auth.
|
78
|
+
# Shared and Api keys are required for Signature along with the current utc time.
|
79
|
+
def signature
|
80
|
+
if Expedia.cid && Expedia.api_key && Expedia.shared_secret
|
81
|
+
Digest::MD5.hexdigest(Expedia.api_key+Expedia.shared_secret+Time.now.utc.to_i.to_s)
|
82
|
+
else
|
83
|
+
raise Expedia::AuthCredentialsError, "cid, api_key and shared_secret are required for Expedia Authentication."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Common Parameters required for every Call to Expedia Server.
|
88
|
+
#
|
89
|
+
def add_common_parameters
|
90
|
+
{ :cid => Expedia.cid, :sig => signature, :apiKey => Expedia.api_key, :minorRev => Expedia.minor_rev,
|
91
|
+
:_type => 'json', :locale => Expedia.locale, :currencyCode => Expedia.currency_code }
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Expedia
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
# Utility methods used by Expedia.
|
5
|
+
require 'logger'
|
6
|
+
require 'forwardable'
|
7
|
+
|
8
|
+
extend Forwardable
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def_delegators :logger, :debug, :info, :warn, :error, :fatal, :level, :level=
|
12
|
+
|
13
|
+
# The Expedia logger, an instance of the standard Ruby logger, pointing to STDOUT by default.
|
14
|
+
# In Rails projects, you can set this to Rails.logger.
|
15
|
+
attr_accessor :logger
|
16
|
+
self.logger = Logger.new(STDOUT)
|
17
|
+
self.logger.level = Logger::ERROR
|
18
|
+
|
19
|
+
# @private
|
20
|
+
DEPRECATION_PREFIX = "EXPEDIA: Deprecation warning: "
|
21
|
+
|
22
|
+
# Prints a deprecation message.
|
23
|
+
# Each individual message will only be printed once to avoid spamming.
|
24
|
+
def deprecate(message)
|
25
|
+
@posted_deprecations ||= []
|
26
|
+
unless @posted_deprecations.include?(message)
|
27
|
+
# only include each message once
|
28
|
+
Kernel.warn("#{DEPRECATION_PREFIX}#{message}")
|
29
|
+
@posted_deprecations << message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/expedia.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# useful tools
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
# include koala modules
|
6
|
+
require 'expedia/errors'
|
7
|
+
require 'expedia/api'
|
8
|
+
|
9
|
+
# HTTP module so we can communicate with Expedia
|
10
|
+
require 'expedia/http_service'
|
11
|
+
|
12
|
+
# miscellaneous
|
13
|
+
require 'expedia/utils'
|
14
|
+
require 'expedia/version'
|
15
|
+
require 'expedia/railtie' if defined?(Rails)
|
16
|
+
|
17
|
+
module Expedia
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
attr_accessor :cid, :api_key, :shared_secret, :format, :locale,
|
22
|
+
:currency_code, :minor_rev
|
23
|
+
|
24
|
+
# Default way to setup Devise. Run generator to create
|
25
|
+
# a fresh initializer with all configuration values.
|
26
|
+
def setup
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
def root_path
|
31
|
+
Gem::Specification.find_by_name("expedia").gem_dir
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "colorize"
|
2
|
+
|
3
|
+
namespace :expedia do
|
4
|
+
|
5
|
+
desc "It creates an Expedia initializer"
|
6
|
+
task :initialize do
|
7
|
+
# Copy the template to the applicaion's initializers folder.
|
8
|
+
cp "#{Expedia.root_path}/lib/templates/expedia.txt", "config/initializers/expedia.rb"
|
9
|
+
# Shashka: Colorize output.
|
10
|
+
puts "#{'create: '.colorize(:green)} config/initializers/expedia.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Expedia.setup do |config|
|
2
|
+
config.cid = 55505 # your cid once you go live.
|
3
|
+
config.api_key = 'your_api_key'
|
4
|
+
config.shared_secret = 'your_shared_secret'
|
5
|
+
config.locale = 'en_US' # For Example 'de_DE'. Default is 'en_US'
|
6
|
+
config.currency_code = 'USD' # For Example 'EUR'. Default is 'USD'
|
7
|
+
config.minor_rev = 13 # between 4-19 as of Dec 2012. Default is 4. 19 being latest
|
8
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Expedia::HTTPService" do
|
4
|
+
|
5
|
+
it "has an API_SERVER Constant" do
|
6
|
+
Expedia::HTTPService.constants.should include(:API_SERVER)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has an RESERVATION_SERVER Constant" do
|
10
|
+
Expedia::HTTPService.constants.should include(:RESERVATION_SERVER)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "server" do
|
14
|
+
|
15
|
+
it "return API server when no options are provided" do
|
16
|
+
Expedia::HTTPService.server.should =~ Regexp.new(Expedia::HTTPService::API_SERVER)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "return server with http when options[:use_ssl] are not provided" do
|
20
|
+
Expedia::HTTPService.server.should eql "http://#{Expedia::HTTPService::API_SERVER}"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "return RESERVATION server when options[:reservation_api]" do
|
24
|
+
Expedia::HTTPService.server({ :reservation_api => true }).should =~ Regexp.new(Expedia::HTTPService::RESERVATION_SERVER)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "return server with https when options[:use_ssl]" do
|
28
|
+
Expedia::HTTPService.server( {:use_ssl => true }).should eql "https://#{Expedia::HTTPService::API_SERVER}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "signature and add_common_parameters" do
|
34
|
+
|
35
|
+
before :each do
|
36
|
+
Expedia.cid = ''
|
37
|
+
Expedia.api_key =''
|
38
|
+
Expedia.shared_secret = ''
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
it "returns a ligit MD5 checksum" do
|
44
|
+
Expedia::HTTPService.signature.should_not eql nil
|
45
|
+
Expedia::HTTPService.signature.should_not eql ''
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns a hash containing common params" do
|
49
|
+
Expedia::HTTPService.add_common_parameters.keys.should include(:cid)
|
50
|
+
Expedia::HTTPService.add_common_parameters.keys.should include(:apiKey)
|
51
|
+
Expedia::HTTPService.add_common_parameters.keys.should include(:sig)
|
52
|
+
Expedia::HTTPService.add_common_parameters.keys.should include(:_type)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'expedia'
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
5
|
+
# loaded once.
|
6
|
+
#
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: expedia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Zaid Akram
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.8'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.8'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: colorize
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.5.8
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.8
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: addressable
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.2'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.2'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.8'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.8'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.8'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.8'
|
110
|
+
description: Expedia is a lightweight, flexible Ruby SDK for EAN. It allows read/write
|
111
|
+
access to the EAN APIs.
|
112
|
+
email:
|
113
|
+
- zaidakrammughal@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.textile
|
123
|
+
- Rakefile
|
124
|
+
- expedia.gemspec
|
125
|
+
- lib/expedia.rb
|
126
|
+
- lib/expedia/api.rb
|
127
|
+
- lib/expedia/errors.rb
|
128
|
+
- lib/expedia/http_service.rb
|
129
|
+
- lib/expedia/http_service/response.rb
|
130
|
+
- lib/expedia/railtie.rb
|
131
|
+
- lib/expedia/utils.rb
|
132
|
+
- lib/expedia/version.rb
|
133
|
+
- lib/tasks/expedia.rake
|
134
|
+
- lib/templates/expedia.txt
|
135
|
+
- spec/http_service_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
homepage: https://github.com/zaidakram/expedia
|
138
|
+
licenses: []
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.24
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Expedia is a ruby wrapper for 'EAN (Expedia Affiliate Network)'
|
161
|
+
test_files:
|
162
|
+
- spec/http_service_spec.rb
|
163
|
+
- spec/spec_helper.rb
|