From 1a0cf5b6c68e5672ec1a23a7f42390019a3ea4fc Mon Sep 17 00:00:00 2001 From: Kelly Mahan Date: Thu, 30 Jul 2015 10:29:09 -0500 Subject: [PATCH] Ran into an issue where the signature wasn't required since I used IP whitelisting. Talked with a tech at expedia and they mentioned a change on their end that if a signature is provided the ip whitelisting is ignored. This change will allow users to disable passing along the signature. --- README.textile | 1 + lib/expedia.rb | 3 ++- lib/expedia/http_service.rb | 5 +++-- lib/expedia/version.rb | 2 +- lib/generators/templates/expedia.txt | 1 + spec/http_service_spec.rb | 6 ++++++ 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.textile b/README.textile index 9dd0920..4bcc198 100644 --- a/README.textile +++ b/README.textile @@ -37,6 +37,7 @@ Expedia.shared_secret = 'your_shared_secret' Expedia.locale = 'en_US' Expedia.currency_code = 'USD' Expedia.minor_rev = 13 +Expedia.use_signature = true # must be false if using ip whitelisting instead of signature # Optional configuration... Expedia.timeout = 1 # read timeout in sec Expedia.open_timeout = 1 # connection timeout in sec diff --git a/lib/expedia.rb b/lib/expedia.rb index 9211df9..a6c8737 100644 --- a/lib/expedia.rb +++ b/lib/expedia.rb @@ -23,11 +23,12 @@ module Expedia class << self attr_accessor :cid, :api_key, :shared_secret, :format, :locale, - :currency_code, :minor_rev, :timeout, :open_timeout + :currency_code, :minor_rev, :timeout, :open_timeout, :use_signature # Default way to setup Expedia. Run generator to create # a fresh initializer with all configuration values. def setup + Expedia.use_signature = true #default yield self end diff --git a/lib/expedia/http_service.rb b/lib/expedia/http_service.rb index 8ff0d9b..98ba036 100644 --- a/lib/expedia/http_service.rb +++ b/lib/expedia/http_service.rb @@ -93,8 +93,9 @@ def signature # Common Parameters required for every Call to Expedia Server. # @return [Hash] of all common parameters. 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 } + params = { :cid => Expedia.cid, :apiKey => Expedia.api_key, :minorRev => Expedia.minor_rev, :_type => 'json', :locale => Expedia.locale, :currencyCode => Expedia.currency_code } + params.merge!(:sig => signature) if Expedia.use_signature + return params end end diff --git a/lib/expedia/version.rb b/lib/expedia/version.rb index 1cb8018..25153c1 100644 --- a/lib/expedia/version.rb +++ b/lib/expedia/version.rb @@ -1,3 +1,3 @@ module Expedia - VERSION = "0.0.6" + VERSION = "0.0.7" end diff --git a/lib/generators/templates/expedia.txt b/lib/generators/templates/expedia.txt index 16a6a00..67598c7 100644 --- a/lib/generators/templates/expedia.txt +++ b/lib/generators/templates/expedia.txt @@ -5,6 +5,7 @@ Expedia.setup do |config| config.locale = 'en_US' # For Example 'de_DE'. Default is 'en_US' config.currency_code = 'USD' # For Example 'EUR'. Default is 'USD' config.minor_rev = 28 # between 4-28 as of Jan 2015. If not set, 4 is used by EAN. + config.use_signature = true # An encoded signature is not required if ip whitelisting is used # optional configurations... config.timeout = 1 # read timeout in sec config.open_timeout = 1 # connection timeout in sec diff --git a/spec/http_service_spec.rb b/spec/http_service_spec.rb index 230bc0c..582cfc5 100644 --- a/spec/http_service_spec.rb +++ b/spec/http_service_spec.rb @@ -48,6 +48,7 @@ Expedia.cid = '' Expedia.api_key ='' Expedia.shared_secret = '' + Expedia.use_signature = true end @@ -63,6 +64,11 @@ Expedia::HTTPService.common_parameters.keys.should include(:sig) Expedia::HTTPService.common_parameters.keys.should include(:_type) end + + it "checks to see if sig is removed from parameters" do + Expedia.use_signature = false + Expedia::HTTPService.common_parameters.keys.should_not include(:sig) + end end end