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

Freeze constants and hash in services #70

Merged
merged 1 commit into from Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/active_fulfillment/services/amazon_mws.rb
Expand Up @@ -6,15 +6,15 @@
module ActiveFulfillment
class AmazonMarketplaceWebService < Service

APPLICATION_IDENTIFIER = "active_merchant_mws/0.01 (Language=ruby)"
APPLICATION_IDENTIFIER = 'active_merchant_mws/0.01 (Language=ruby)'.freeze

REGISTRATION_URI = URI.parse("https://sellercentral.amazon.com/gp/mws/registration/register.html")
REGISTRATION_URI = URI.parse('https://sellercentral.amazon.com/gp/mws/registration/register.html').freeze

SIGNATURE_VERSION = 2
SIGNATURE_METHOD = "SHA256"
VERSION = "2010-10-01"
SIGNATURE_METHOD = 'SHA256'.freeze
VERSION = '2010-10-01'.freeze

SUCCESS, FAILURE, ERROR = 'Accepted', 'Failure', 'Error'
SUCCESS, FAILURE, ERROR = 'Accepted'.freeze, 'Failure'.freeze, 'Error'.freeze

ENDPOINTS = {
:ca => 'mws.amazonservices.ca',
Expand All @@ -26,7 +26,7 @@ class AmazonMarketplaceWebService < Service
:jp => 'mws.amazonservices.jp',
:uk => 'mws-eu.amazonservices.ca',
:us => 'mws.amazonservices.com'
}
}.freeze

LOOKUPS = {
:destination_address => {
Expand All @@ -53,18 +53,20 @@ class AmazonMarketplaceWebService < Service
:list_inventory => {
:sku => "SellerSkus.member.%d"
}
}
}.freeze

SHIPPING_METHODS = {
'Standard Shipping' => 'Standard',
'Expedited Shipping' => 'Expedited',
'Priority Shipping' => 'Priority'
}.freeze

# The first is the label, and the last is the code
# Standard: 3-5 business days
# Expedited: 2 business days
# Priority: 1 business day
def self.shipping_methods
[
[ 'Standard Shipping', 'Standard' ],
[ 'Expedited Shipping', 'Expedited' ],
[ 'Priority Shipping', 'Priority' ]
].inject({}){|h, (k,v)| h[k] = v; h}
SHIPPING_METHODS
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garethson do we use this method? Thoughts on putting a note in the change log and making this a bigger version bump to just use the constant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinhughes27 We do use this method, and a couple of the providers actually do run code to generate it. So maybe leave that change for later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, definitely leave the method then!


def initialize(options = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fulfillment/services/james_and_james.rb
Expand Up @@ -6,7 +6,7 @@ class JamesAndJamesService < Service
SERVICE_URLS = {
fulfillment: 'https://%{subdomain}.sixworks.co.uk/api/1/',
inventory: 'https://%{subdomain}.sixworks.co.uk/api/1/stock'
}
}.freeze

def initialize(options = {})
requires!(options, :subdomain, :key)
Expand Down
23 changes: 13 additions & 10 deletions lib/active_fulfillment/services/shipwire.rb
Expand Up @@ -6,38 +6,41 @@ class ShipwireService < Service
SERVICE_URLS = { :fulfillment => 'https://api.shipwire.com/exec/FulfillmentServices.php',
:inventory => 'https://api.shipwire.com/exec/InventoryServices.php',
:tracking => 'https://api.shipwire.com/exec/TrackingServices.php'
}
}.freeze

SCHEMA_URLS = { :fulfillment => 'http://www.shipwire.com/exec/download/OrderList.dtd',
:inventory => 'http://www.shipwire.com/exec/download/InventoryUpdate.dtd',
:tracking => 'http://www.shipwire.com/exec/download/TrackingUpdate.dtd'
}
}.freeze

POST_VARS = { :fulfillment => 'OrderListXML',
:inventory => 'InventoryUpdateXML',
:tracking => 'TrackingUpdateXML'
}
}.freeze

WAREHOUSES = { 'CHI' => 'Chicago',
'LAX' => 'Los Angeles',
'REN' => 'Reno',
'VAN' => 'Vancouver',
'TOR' => 'Toronto',
'UK' => 'United Kingdom'
}
}.freeze

SHIPPING_METHODS = {
'1 Day Service' => '1D',
'2 Day Service' => '2D',
'Ground Service' => 'GD',
'Freight Service' => 'FT',
'International' => 'INTL'
}.freeze

INVALID_LOGIN = /(Error with Valid Username\/EmailAddress and Password Required)|(Could not verify Username\/EmailAddress and Password combination)/

class_attribute :affiliate_id

# The first is the label, and the last is the code
def self.shipping_methods
[ ['1 Day Service', '1D'],
['2 Day Service', '2D'],
['Ground Service', 'GD'],
['Freight Service', 'FT'],
['International', 'INTL']
].inject({}){|h, (k,v)| h[k] = v; h}
SHIPPING_METHODS
end

# Pass in the login and password for the shipwire account.
Expand Down
12 changes: 6 additions & 6 deletions lib/active_fulfillment/services/shopify_api.rb
Expand Up @@ -3,7 +3,7 @@
module ActiveFulfillment
class ShopifyAPIService < Service

OrderIdCutoffDate = Date.iso8601("2015-03-01")
OrderIdCutoffDate = Date.iso8601('2015-03-01').freeze

RESCUABLE_CONNECTION_ERRORS = [
Net::ReadTimeout,
Expand All @@ -28,7 +28,7 @@ class ShopifyAPIService < Service
ActiveUtils::ConnectionError,
ActiveUtils::ResponseError,
ActiveUtils::InvalidResponseError
]
].freeze

def initialize(options = {})
@name = options[:name]
Expand Down Expand Up @@ -94,11 +94,11 @@ def send_app_request(action, headers, data)

def parse_response(response, root, type, key, value)
case @format
when 'json'
when 'json'.freeze
response_data = ActiveSupport::JSON.decode(response)
return {} unless response_data.is_a?(Hash)
response_data[root.underscore] || response_data
when 'xml'
when 'xml'.freeze
response_data = {}
document = REXML::Document.new(response)
document.elements[root].each do |node|
Expand All @@ -115,9 +115,9 @@ def parse_response(response, root, type, key, value)

def encode_payload(payload, root)
case @format
when 'json'
when 'json'.freeze
{root => payload}.to_json
when 'xml'
when 'xml'.freeze
payload.to_xml(:root => root)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be over doing the constants, @garethson ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, see my comments in #71. We should really only be creating constants if they're used in more than one place, otherwise just freezing strings inline is my preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for those 2. JSON_DATATYPE and XML_DATATYPE.

end
end
Expand Down
104 changes: 54 additions & 50 deletions lib/active_fulfillment/services/webgistix.rb
@@ -1,24 +1,63 @@
module ActiveFulfillment
class WebgistixService < Service

SERVICE_URLS = {
:fulfillment => 'https://www.webgistix.com/XML/CreateOrder.asp',
:inventory => 'https://www.webgistix.com/XML/GetInventory.asp',
:tracking => 'https://www.webgistix.com/XML/GetTracking.asp'
}
TEST_URLS = SERVICE_URLS.merge({
}.freeze

TEST_URLS = SERVICE_URLS.dup.merge({
:fulfillment => 'https://www.webgistix.com/XML/CreateOrderTest.asp'
})

SUCCESS, DUPLICATE, FAILURE = 'True', 'Duplicate', 'False'

SUCCESS_MESSAGE = 'Successfully submitted the order'
FAILURE_MESSAGE = 'Failed to submit the order'
DUPLICATE_MESSAGE = 'This order has already been successfully submitted'

INVALID_LOGIN = 'Invalid Credentials'
NOT_SHIPPED = 'Not Shipped'

TRACKING_COMPANIES = %w(UPS FedEx USPS)
}).freeze

SUCCESS, DUPLICATE, FAILURE = 'True'.freeze, 'Duplicate'.freeze, 'False'.freeze

SUCCESS_MESSAGE = 'Successfully submitted the order'.freeze
FAILURE_MESSAGE = 'Failed to submit the order'.freeze
DUPLICATE_MESSAGE = 'This order has already been successfully submitted'.freeze

INVALID_LOGIN = 'Invalid Credentials'.freeze
NOT_SHIPPED = 'Not Shipped'.freeze

TRACKING_COMPANIES = %w(UPS FedEx USPS).freeze

SHIPPING_PROVIDERS = {
'UPS Ground Shipping' => 'Ground',
'UPS Ground' => 'Ground',
'UPS Standard Shipping (Canada Only)' => 'Standard',
'UPS Standard Shipping (CA & MX Only)' => 'Standard',
'UPS 3-Business Day' => '3-Day Select',
'UPS 2-Business Day' => '2nd Day Air',
'UPS 2-Business Day AM' => '2nd Day Air AM',
'UPS Next Day' => 'Next Day Air',
'UPS Next Day Saver' => 'Next Day Air Saver',
'UPS Next Day Early AM' => 'Next Day Air Early AM',
'UPS Worldwide Express (Next Day)' => 'Worldwide Express',
'UPS Worldwide Expedited (2nd Day)' => 'Worldwide Expedited',
'UPS Worldwide Express Saver' => 'Worldwide Express Saver',
'FedEx Priority Overnight' => 'FedEx Priority Overnight',
'FedEx Standard Overnight' => 'FedEx Standard Overnight',
'FedEx First Overnight' => 'FedEx First Overnight',
'FedEx 2nd Day' => 'FedEx 2nd Day',
'FedEx Express Saver' => 'FedEx Express Saver',
'FedEx International Priority' => 'FedEx International Priority',
'FedEx International Economy' => 'FedEx International Economy',
'FedEx International First' => 'FedEx International First',
'FedEx Ground' => 'FedEx Ground',
'USPS Priority Mail' => 'Priority Mail',
'USPS Priority Mail International' => 'Priority Mail International',
'USPS Priority Mail Small Flat Rate Box' => 'Priority Mail Small Flat Rate Box',
'USPS Priority Mail Medium Flat Rate Box' => 'Priority Mail Medium Flat Rate Box',
'USPS Priority Mail Large Flat Rate Box' => "Priority Mail Large Flat Rate Box",
'USPS Priority Mail Flat Rate Envelope' => 'Priority Mail Flat Rate Envelope',
'USPS First Class Mail' => 'First Class',
'USPS First Class International' => 'First Class International',
'USPS Express Mail' => 'Express',
'USPS Express Mail International' => 'Express Mail International',
'USPS Parcel Post' => 'Parcel',
'USPS Media Mail' => 'Media Mail'
}.freeze

# If a request is detected as a duplicate only the original data will be
# used by Webgistix, and the subsequent responses will have a
Expand All @@ -27,42 +66,7 @@ class WebgistixService < Service

# The first is the label, and the last is the code
def self.shipping_methods
[
["UPS Ground Shipping", "Ground"],
["UPS Ground", "Ground"],
["UPS Standard Shipping (Canada Only)", "Standard"],
["UPS Standard Shipping (CA & MX Only)", "Standard"],
["UPS 3-Business Day", "3-Day Select"],
["UPS 2-Business Day", "2nd Day Air"],
["UPS 2-Business Day AM", "2nd Day Air AM"],
["UPS Next Day", "Next Day Air"],
["UPS Next Day Saver", "Next Day Air Saver"],
["UPS Next Day Early AM", "Next Day Air Early AM"],
["UPS Worldwide Express (Next Day)", "Worldwide Express"],
["UPS Worldwide Expedited (2nd Day)", "Worldwide Expedited"],
["UPS Worldwide Express Saver", "Worldwide Express Saver"],
["FedEx Priority Overnight", "FedEx Priority Overnight"],
["FedEx Standard Overnight", "FedEx Standard Overnight"],
["FedEx First Overnight", "FedEx First Overnight"],
["FedEx 2nd Day", "FedEx 2nd Day"],
["FedEx Express Saver", "FedEx Express Saver"],
["FedEx International Priority", "FedEx International Priority"],
["FedEx International Economy", "FedEx International Economy"],
["FedEx International First", "FedEx International First"],
["FedEx Ground", "FedEx Ground"],
["USPS Priority Mail", "Priority Mail"],
["USPS Priority Mail International", "Priority Mail International"],
["USPS Priority Mail Small Flat Rate Box", "Priority Mail Small Flat Rate Box"],
["USPS Priority Mail Medium Flat Rate Box", "Priority Mail Medium Flat Rate Box"],
["USPS Priority Mail Large Flat Rate Box", "Priority Mail Large Flat Rate Box"],
["USPS Priority Mail Flat Rate Envelope", "Priority Mail Flat Rate Envelope"],
["USPS First Class Mail", "First Class"],
["USPS First Class International", "First Class International"],
["USPS Express Mail", "Express"],
["USPS Express Mail International", "Express Mail International"],
["USPS Parcel Post", "Parcel"],
["USPS Media Mail", "Media Mail"]
].inject({}){|h, (k,v)| h[k] = v; h}
SHIPPING_PROVIDERS
end

# Pass in the login and password for the shipwire account.
Expand Down