Skip to content

Instantly share code, notes, and snippets.

@phstc
Last active December 19, 2015 16:59
Show Gist options
  • Save phstc/5988238 to your computer and use it in GitHub Desktop.
Save phstc/5988238 to your computer and use it in GitHub Desktop.
module DummyShip
def self.validate_address(address)
## Zipcode must be within a given range.
unless (20170..20179).to_a.include?(address['zipcode'].to_i)
raise "There was a problem with this address."
end
end
end
require 'endpoint_base'
require 'multi_json'
class FulfillmentEndpoint < EndpointBase
post '/drop_ship' do
process_result 200, { 'message_id' => @message[:message_id] }
end
post '/validate_address' do
address = @message[:payload]['order']['shipping_address']
begin
result = DummyShip.validate_address(address)
process_result 200, { 'message_id' => @message[:message_id], 'message' => "notification:info",
"payload" => { "result" => "The address is valid, and the shipment will be sent." } }
rescue Exception => e
# Should it be process_result 406 instead of 200?
process_result 200, { 'message_id' => @message[:message_id], 'message' => "notification:error",
"payload" => { "result" => e.message } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment