Last active
December 19, 2015 16:59
-
-
Save phstc/5988238 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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