Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting stamps gem for v55 of Stamps.com #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified Gemfile
100644 → 100755
Empty file.
Empty file modified LICENSE.md
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified Rakefile
100644 → 100755
Empty file.
Empty file modified lib/stamps.rb
100644 → 100755
Empty file.
Empty file modified lib/stamps/api.rb
100644 → 100755
Empty file.
Empty file modified lib/stamps/client.rb
100644 → 100755
Empty file.
8 changes: 4 additions & 4 deletions lib/stamps/client/account.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ module Account
def account(params = {})
params[:authenticator] = authenticator_token
response = request('GetAccountInfo', Stamps::Mapping::Account.new(params) )
response[:errors].empty? ? response[:get_account_info_response][:account_info] : response
response[:errors].empty? ? response[:envelope][:body][:get_account_info_response][:account_info] : response[:envelope][:body]
end

# Add funds to postage account
#
def purchase_postage(params = {})
params[:authenticator] = authenticator_token
response = request('PurchasePostage', Stamps::Mapping::PurchasePostage.new(params))
response[:errors].empty? ? response[:purchase_postage_response] : response
response[:errors].empty? ? response[:envelope][:body][:purchase_postage_response] : response[:envelope][:body]
end

# Check the payment of purchase_postage
#
def get_purchase_status(params = {})
params[:authenticator] = authenticator_token
response = request('GetPurchaseStatus', Stamps::Mapping::GetPurchaseStatus.new(params))
response[:errors].empty? ? response[:get_purchase_status_response] : response
response[:errors].empty? ? response[:envelope][:body][:get_purchase_status_response] : response[:envelope][:body]
end

# Request carrier pickup
Expand All @@ -35,7 +35,7 @@ def get_purchase_status(params = {})
def carrier_pickup(params = {})
params[:authenticator] = authenticator_token
response = request('CarrierPickup', Stamps::Mapping::CarrierPickup.new(params))
response[:errors].empty? ? response[:carrier_pickup_response] : response
response[:errors].empty? ? response[:envelope][:body][:carrier_pickup_response] : response[:envelope][:body]
end

end
Expand Down
3 changes: 2 additions & 1 deletion lib/stamps/client/address.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Address
def clean_address(params = {})
params[:authenticator] = authenticator_token
response = request('CleanseAddress', Stamps::Mapping::CleanseAddress.new(params))
response[:errors].empty? ? response[:cleanse_address_response] : response
#response[:errors].empty? ? response[:cleanse_address_response] : response
response[:errors].empty? ? response[:envelope][:body][:cleanse_address_response] : response[:envelope][:body]
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/stamps/client/rate.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def get_rates(params = {})
:rate => Stamps::Mapping::Rate.new(params)
})
response = request('GetRates', rates)
if response[:get_rates_response].nil?
response
if response[:envelope][:body][:get_rates_response].nil?
response[:envelope][:body]
else
response[:get_rates_response][:rates].nil? ? [] : [response[:get_rates_response][:rates][:rate]].flatten
response[:envelope][:body][:get_rates_response][:rates].nil? ? [] : [response[:envelope][:body][:get_rates_response][:rates][:rate]].flatten
end
end

Expand Down
16 changes: 10 additions & 6 deletions lib/stamps/client/stamp.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Stamp
# In order to successfully create postage labels, the following steps
# must happen:
#
# 1. Authentiation - identify the user and ensure that the user is
# 1. Authentication - identify the user and ensure that the user is
# authorized to perform the operation.
#
# 2. CleanseAddress - Ship-to addresses must be standardized based on
Expand All @@ -28,9 +28,13 @@ module Stamp
#
def create!(params = {})
params[:authenticator] = authenticator_token unless params[:authenticator]
params[:from] ||= Hash.new
response = request('CreateIndicium', Stamps::Mapping::Stamp.new(params))
response[:errors].empty? ? response[:create_indicium_response] : response
params[:from] ||= {}
#params[:rate].delete(:add_ons)
#params[:rate][:cubic_pricing] = true
params[:rate].delete(:delivery_date)
stamp = Stamps::Mapping::Stamp.new(params)
response = request('CreateIndicium', stamp)
response[:errors].empty? ? response[:envelope][:body][:create_indicium_response] : response[:envelope][:body]
end

# Refunds postage and voids the shipping label
Expand All @@ -40,7 +44,7 @@ def create!(params = {})
def cancel!(params = {})
params[:authenticator] = authenticator_token unless params[:authenticator]
response = request('CancelIndicium', Stamps::Mapping::CancelStamp.new(params))
response[:errors].empty? ? response[:cancel_indicium_response] : response
response[:errors].empty? ? response[:envelope][:body][:cancel_indicium_response] : response[:envelope][:body]
end

# Returns an array of tracking events
Expand All @@ -53,7 +57,7 @@ def track(stamps_transaction_id)
:stamps_transaction_id => stamps_transaction_id
}
response = request('TrackShipment', Stamps::Mapping::TrackShipment.new(params))
response[:errors].empty? ? response[:track_shipment_response] : response
response[:errors].empty? ? response[:envelope][:body][:track_shipment_response] : response[:envelope][:body]
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/stamps/configuration.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ module Configuration
:endpoint].freeze

# The endpoint that will be used to connect if none is set
DEFAULT_ENDPOINT = 'https://swsim.stamps.com/swsim/swsimv29.asmx'.freeze
DEFAULT_ENDPOINT = 'https://swsim.stamps.com/swsim/swsimv55.asmx'.freeze

# The default namespace used on Stamps.com wsdl
DEFAULT_NAMESPACE = 'http://stamps.com/xml/namespace/2010/11/swsim/swsimv29'
DEFAULT_NAMESPACE = 'http://stamps.com/xml/namespace/2016/09/swsim/swsimv55'

# @note JSON is preferred over XML because it is more concise and faster to parse.
DEFAULT_FORMAT = :hash
Expand Down
Empty file modified lib/stamps/errors.rb
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions lib/stamps/mapping.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Rate < Hashie::Trash
property :RateCategory, :from => :rate_category
property :ToState, :from => :to_state
property :CubicPricing, :from => :cubic_pricing
property :DeliveryDate, :from => :delivery_date

# Maps :rate to AddOns map
def add_ons=(addons)
Expand Down
14 changes: 8 additions & 6 deletions lib/stamps/request.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ def request(web_method, params, raw=false)
client = Savon.client do |globals|
globals.endpoint self.endpoint
globals.namespace self.namespace
globals.namespaces("xmlns:tns" => self.namespace)
globals.log false
#globals.namespaces("xmlns:tns" => self.namespace)
globals.log self.log_messages
globals.logger Logger.new(STDOUT)
globals.raise_errors false
globals.raise_errors self.raise_errors
globals.headers({ "SoapAction" => formatted_soap_action(web_method) })
globals.element_form_default :qualified
globals.namespace_identifier :tns
globals.namespace_identifier nil
globals.env_namespace :soap
globals.open_timeout self.open_timeout
globals.read_timeout self.read_timeout
end
Expand Down Expand Up @@ -47,8 +48,9 @@ def get_authenticator_token
:password => self.password
})
)
if response_hash[:authenticate_user_response] != nil
response_hash[:authenticate_user_response][:authenticator]

if response_hash[:envelope][:body][:authenticate_user_response] != nil # response_hash[:authenticate_user_response]
response_hash[:envelope][:body][:authenticate_user_response][:authenticator]
else
raise Stamps::InvalidIntegrationID.new(response_hash[:errors][0])
end
Expand Down
4 changes: 2 additions & 2 deletions lib/stamps/response.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(response)
self.valid = true
self.savon = response
self.http = response.http
self.hash = self.savon.to_hash
self.hash = response.hash
raise_errors
end

Expand Down Expand Up @@ -63,7 +63,7 @@ def raise_errors
# Include any errors in the response
#
def format_soap_faults
fault = self.hash.delete("soap:Fault") || self.hash.delete(:fault)
fault = self.hash[:envelope][:body].delete("soap:Fault") || self.hash[:envelope][:body].delete(:fault)
self.errors << (fault[:faultstring] || fault["faultstring"])
self.valid = false
end
Expand Down
Empty file modified lib/stamps/trash.rb
100644 → 100755
Empty file.
Empty file modified lib/stamps/types.rb
100644 → 100755
Empty file.
Empty file modified lib/stamps/version.rb
100644 → 100755
Empty file.
22 changes: 11 additions & 11 deletions stamps.gemspec
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_development_dependency('simplecov', '~> 0.4.0')
s.add_development_dependency('shoulda', '~> 2.11.3')
s.add_development_dependency 'shoulda', '~> 2.11', '>= 2.11.3'
s.add_development_dependency('mocha', '~> 0.9.11')
s.add_development_dependency('webmock', '~> 1.6.2')
s.add_development_dependency('awesome_print')
s.add_development_dependency('yard')
s.add_development_dependency('bluecloth')
s.add_development_dependency('rake')
s.add_development_dependency('pry')
s.add_development_dependency 'webmock', '~> 1.6', '>= 1.6.2'
s.add_development_dependency 'awesome_print', '~> 0'
s.add_development_dependency 'yard', '~> 0'
s.add_development_dependency 'bluecloth', '>= 0', '~> 0'
s.add_development_dependency 'rake', '~> 0'
s.add_development_dependency 'pry', '~> 0'

# We have to use savon 0.8.6 for now since newer versions of savon don't
# convert booleans, dates, or decimals consistently.
# See: https://github.com/rubiii/savon/issues/301
s.add_runtime_dependency('savon', '~> 2.3.0')
s.add_runtime_dependency('httpi', '~> 2.1.0')
#
s.add_runtime_dependency 'savon', '~> 2.3', '>= 2.3.0'
s.add_runtime_dependency 'httpi', '~> 2.1', '>= 2.1.0'
s.add_runtime_dependency('json', '~> 1.0')
s.add_runtime_dependency('multi_json', '~> 1.0')
s.add_runtime_dependency('hashie', '~> 1.0.0')

s.add_runtime_dependency 'hashie', '~> 1.2', '>= 1.2.0'
end
Empty file modified test/client/account_test.rb
100644 → 100755
Empty file.
Empty file modified test/client/address_test.rb
100644 → 100755
Empty file.
Empty file modified test/client/rate_test.rb
100644 → 100755
Empty file.
Empty file modified test/client/stamp_test.rb
100644 → 100755
Empty file.
Empty file modified test/fixtures/AuthenticateUser.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/CancelIndicium.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/CarrierPickup.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/CleanseAddress.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/CreateIndicium.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/GetAccountInfo.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/GetRate.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/GetRates.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/GetRatesEmpty.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/InsufficientPostage.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/InvalidSoap.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/PurchasePostage.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/TrackShipment.xml
100644 → 100755
Empty file.
Empty file modified test/fixtures/failed_auth.xml
100644 → 100755
Empty file.
Empty file modified test/helper.rb
100644 → 100755
Empty file.
Empty file modified test/mapping_test.rb
100644 → 100755
Empty file.
Empty file modified test/request_test.rb
100644 → 100755
Empty file.
Empty file modified test/response_test.rb
100644 → 100755
Empty file.
Empty file modified test/stamps_test.rb
100644 → 100755
Empty file.
Empty file modified test/types_test.rb
100644 → 100755
Empty file.