Module: Expedia::HTTPService
- Defined in:
- lib/expedia/http_service.rb,
lib/expedia/http_service/response.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- API_SERVER =
'api.eancdn.com'- RESERVATION_SERVER =
'book.api.ean.com'- DEVELOPMENT_SERVER =
'dev.api.ean.com'
Class Method Summary collapse
-
.add_timeouts(conn, options) ⇒ Object
Adding open and read timeouts.
-
.common_parameters ⇒ Hash
Common Parameters required for every Call to Expedia Server.
-
.make_request(path, args, verb, options = {}) ⇒ Expedia::HTTPService::Response, Expedia::APIError
Makes a request directly to Expedia.
-
.server(options = {}) ⇒ Object
The address of the appropriate Expedia server.
-
.signature ⇒ Object
Creates a Signature for Expedia using MD5 Checksum Auth.
Class Method Details
.add_timeouts(conn, options) ⇒ Object
Adding open and read timeouts
open timeout - the amount of time you are willing to wait for ‘opening a connection’ (read) timeout - the amount of time you are willing to wait for some data to be received from the connected party.
38 39 40 41 42 43 44 |
# File 'lib/expedia/http_service.rb', line 38 def add_timeouts(conn, ) if ![:ignore_timeout] conn..timeout = Expedia.timeout.to_i if Expedia.timeout.present? conn..open_timeout = Expedia.open_timeout.to_i if Expedia.open_timeout.present? end conn end |
.common_parameters ⇒ Hash
Common Parameters required for every Call to Expedia Server.
93 94 95 96 |
# File 'lib/expedia/http_service.rb', line 93 def common_parameters { :cid => Expedia.cid, :sig => signature, :apiKey => Expedia.api_key, :minorRev => Expedia.minor_rev, :_type => 'json', :locale => Expedia.locale, :currencyCode => Expedia.currency_code } end |
.make_request(path, args, verb, options = {}) ⇒ Expedia::HTTPService::Response, Expedia::APIError
You’ll rarely need to call this method directly.
Makes a request directly to Expedia.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/expedia/http_service.rb', line 60 def make_request(path, args, verb, = {}) args = common_parameters.merge(args) # figure out our options for this request = {:params => (verb == :get ? args : {})} # set up our Faraday connection conn = Faraday.new(server(), ) conn = add_timeouts(conn, ) response = conn.send(verb, path, (verb == :post ? args : {})) # 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 response end end |
.server(options = {}) ⇒ Object
The address of the appropriate Expedia server.
21 22 23 24 25 26 27 28 |
# File 'lib/expedia/http_service.rb', line 21 def server( = {}) if Expedia.cid.to_i == 55505 && ![:reservation_api] server = DEVELOPMENT_SERVER else server = [:reservation_api] ? RESERVATION_SERVER : API_SERVER end "#{options[:use_ssl] ? "https" : "http"}://#{server}" end |
.signature ⇒ Object
Creates a Signature for Expedia using MD5 Checksum Auth. Shared and Api keys are required for Signature along with the current utc time.
83 84 85 86 87 88 89 |
# File 'lib/expedia/http_service.rb', line 83 def signature if Expedia.cid && Expedia.api_key && Expedia.shared_secret Digest::MD5.hexdigest(Expedia.api_key + Expedia.shared_secret + Time.now.utc.to_i.to_s) else raise Expedia::AuthCredentialsError, "cid, api_key and shared_secret are required for Expedia Authentication." end end |