Skip to content

Commit

Permalink
Some changes in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid Akram committed Dec 13, 2012
1 parent 993eb73 commit 76f3a1b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 34 deletions.
40 changes: 27 additions & 13 deletions README.textile
@@ -1,10 +1,10 @@
h1. Expedia

Expedia is a ruby wrapper for "EAN (Expedia Affiliate Network)":www.expediaaffiliate.com APIs.
Expedia is a ruby wrapper for ["EAN (Expedia Affiliate Network)":www.expediaaffiliate.com] APIs.

Other details of this gem are:

* It use the the latest verion of the EAN API. i.e "Version 3":http://developer.ean.com/docs/read/hotels/version_3
* It use the the latest verion of the EAN API. i.e ["Version 3":http://developer.ean.com/docs/read/hotels/version_3]
* Only REST API support (No XML or SOAP support)

h2. Installation
Expand Down Expand Up @@ -35,7 +35,7 @@ $ rake expedia:initialize

h2. Usage

After configuring keys for your EAN application use
After configuring keys for your EAN application kyes, Default locale, currency and minor_rev use

<pre>
# Instentiate api object
Expand All @@ -49,6 +49,7 @@ Following methods are expeosed by Expedia::API object

Note: All method naming is done in correspondence with Expedia services and ruby conventions
see "Hotel API Documentation (Services section)":http://developer.ean.com/docs/read/hotels#.UMf_hiNDt0w

<pre>
get_list({})
geo_search({})
Expand All @@ -65,7 +66,7 @@ get_ping({})
get_static_reservation({}) # To test Reservation (Static Reservation)
</pre>

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.
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.

h3. Success

Expand All @@ -82,32 +83,45 @@ h3. Error

In case of any error a Expedia::APIError object is returned.

Note: Expedia respondes with status of 200 even if there is an exception (most of the times). So no Exception is raised!
Note: Expedia responds with status of 200 even if there is an exception (most of the times). So no Exception is raised!

<pre>
# See http://developer.ean.com/docs/read/error_handling/Hotel_V3_Exception_Details

response.status # Response status
response.error_body # Complete error body
response.error_body # Response status
response.category # Value indicating the nature of the exception or the reason it occurred
response.presentation_message # Presentation error message returned
response.verbose_message # More specific detailed error message
response.handling # value indicating the severity of the exception and how it may be handled
</pre>

h2. Test Booking (Static Reservation)
h3. Test Booking (Static Reservation)

For Static reservation use get_static_reservation() method.

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
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]

A static Booking example.

<pre>
response = api.get_static_reservation({ :arrivalDate => "10/10/2013", :departureDate => "10/12/2013", :hotelID => 359433,
:supplierType => "E", :rateKey => "084eab14-335e-46d6-aa2e-766fce6be32c", :roomTypeCode => 200007964,
:rateCode => 200865704, :chargeableRate => "142.8",
response = api.get_static_reservation({ :arrivalDate => "10/10/2013", :departureDate => "10/12/2013",
:hotelID => 359433, :supplierType => "E", :rateKey => "084eab14-335e-46d6-aa2e-766fce6be32c",
:roomTypeCode => 200007964, :rateCode => 200865704, :chargeableRate => "142.8",
:room1 => "1", :room1FirstName => "test", :room1LastName => "testers", :room1BedTypeId => "15",
:room1SmokingPreference => "NS", :email => "test@tesing.com", :city => 'Bellevue', :stateProvinceCode => 'WA',
:countryCode => 'US', :postalCode => 98004 })
:room1SmokingPreference => "NS", :email => "test@tesing.com", :city => 'Bellevue',
:stateProvinceCode => 'WA', :countryCode => 'US', :postalCode => 98004 })
</pre>

h3. Logging

Expedia::Utils.logger points to STDOUT by default. You can use it to Log in Rails Applications

<pre>
Expedia::Utils.logger = Rails.logger

# And loggig methods available
[:debug, :info, :warn, :error, :fatal]
</pre>


25 changes: 15 additions & 10 deletions lib/expedia/errors.rb
Expand Up @@ -4,20 +4,19 @@ class ExpediaError < StandardError; end

# Expedia respondes with status of 200 even if there is an exception (most of the time)
class APIError < ::Expedia::ExpediaError

# @status The HTTP status code of the response
# @error_body The parsed response body
# @error_info One of the following:
# @category Value indicating the nature of the exception or the reason it occurred
# @presentation_message Presentation error message returned
# @verbose_message More specific detailed error message
# @handling value indicating the severity of the exception and how it may be handled

attr_accessor :category, :presentation_message, :verbose_message,
:status, :error_body, :handling

# Create a new API Error
#
# @param status [Integer] The HTTP status code of the response
# @param error_body The parsed response body
# @param error_info One of the following:
# [Hash] The error information extracted from the request
# ("type", "code", "error_subcode", "message")
# [String] The error description
# If error_info is nil or not provided, the method will attempt to extract
# the error info from the response_body
#
# @return the newly created APIError
def initialize(status, body)
@error_body = body
Expand All @@ -39,6 +38,12 @@ def initialize(status, body)
super(@verbose_message)

end

# Just to enable user to call this method on response object to know if any exception has occured
# Free user form the Hastle of checking the class of object on every request.
def exception?
true
end
end

# A standard Error calss for Raising exception if [cid, shared_secret, api_key] are not provided.
Expand Down
18 changes: 7 additions & 11 deletions lib/expedia/http_service.rb
Expand Up @@ -30,31 +30,25 @@ def server(options = {})
# @param path the server path for this request
# @param args (see Expedia::API#api)
# @param verb the HTTP method to use.
# If not get or post, this will be turned into a POST request with the appropriate :method
# specified in the arguments.
# @param options (see Expedia::API)
# @param options same options passed to server method.
#
# @raise an appropriate connection error if unable to make the request to Expedia
#
# @return [Expedia::HTTPService::Response] a response object representing the results from Facebook
# @return [Expedia::HTTPService::Response] on success. A response object representing the results from Expedia
# @return [Expedia::APIError] on Error.
def make_request(path, args, verb, options = {})
args.merge!(add_common_parameters)
# figure out our options for this request
request_options = {:params => (verb == :get ? args : {})}
# if request_options[:use_ssl]
# ssl = (request_options[:ssl] ||= {})
# ssl[:verify] = true unless ssl.has_key?(:verify)
# end

# set up our Faraday connection
# we have to manually assign params to the URL or the
conn = Faraday.new(server(options), request_options)
response = conn.send(verb, path, (verb == :post ? args : {}))

# Log URL information
# Log URL and params information
Expedia::Utils.debug "\nExpedia [#{verb.upcase}] - #{server(options) + path} params: #{args.inspect} : #{response.status}\n"
response = Expedia::HTTPService::Response.new(response.status.to_i, response.body, response.headers)

# If there is an exception make a [Expedia::APIError] object to return
if response.exception?
Expedia::APIError.new(response.status, response.body)
else
Expand All @@ -71,6 +65,7 @@ def make_request(path, args, verb, options = {})
# => "a=2&b=My+String"
#
# @return the appropriately-encoded string
# Method currently not in use.
def encode_params(param_hash)
((param_hash || {}).sort_by{|k, v| k.to_s}.collect do |key_and_value|
key_and_value[1] = MultiJson.dump(key_and_value[1]) unless key_and_value[1].is_a? String
Expand All @@ -90,6 +85,7 @@ def signature
end

# Common Parameters required for every Call to Expedia Server.
#
def add_common_parameters
{ :cid => Expedia.cid, :sig => signature, :apiKey => Expedia.api_key, :minorRev => Expedia.minor_rev,
:_type => 'json', :locale => Expedia.locale, :currencyCode => Expedia.currency_code }
Expand Down
1 change: 1 addition & 0 deletions lib/expedia/http_service/response.rb
Expand Up @@ -13,6 +13,7 @@ def initialize(status, body, headers)
@headers = headers
end

# Simple predicate method to check if there is any exception
def exception?
@headers['content-type'] != 'application/json' ||
(@body && @body[@body.keys[0]]['EanWsError']) ? true : false
Expand Down
1 change: 1 addition & 0 deletions lib/expedia/railtie.rb
Expand Up @@ -3,6 +3,7 @@
module Expedia
class Railtie < Rails::Railtie

# Load rake tasks
rake_tasks do
load "tasks/expedia.rake"
end
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/expedia.rake
Expand Up @@ -4,7 +4,9 @@ namespace :expedia do

desc "It creates an Expedia initializer"
task :initialize do
# Copy the template to the applicaion's initializers folder.
cp "#{Expedia.root_path}/lib/templates/expedia.txt", "config/initializers/expedia.rb"
# Shashka: Colorize output.
puts "#{'create: '.colorize(:green)} config/initializers/expedia.rb"
end

Expand Down

0 comments on commit 76f3a1b

Please sign in to comment.