Created
October 2, 2012 15:39
-
-
Save mjallday/3820242 to your computer and use it in GitHub Desktop.
Account conflict example
This file contains hidden or 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
import balanced | |
key = balanced.APIKey().save() | |
balanced.configure(key.secret) | |
balanced.Marketplace().save() | |
account = balanced.Account(email_address='[email protected]').save() | |
try: | |
account = balanced.Account(email_address='[email protected]').save() | |
except balanced.exc.HTTPError as ex: | |
print 'oh no, account already exists' | |
account = balanced.Account.find(ex.extras['account_uri']) | |
print account.email_address |
This file contains hidden or 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 'balanced' | |
key = Balanced::ApiKey.new.save | |
Balanced.configure(key.secret) | |
Balanced::Marketplace.new.save | |
account = Balanced::Account.new(:email_address => '[email protected]').save | |
begin | |
account = Balanced::Account.new(:email_address => '[email protected]').save | |
rescue Balanced::Conflict => ex | |
if ex.category_code == 'duplicate-email-address' | |
puts 'we got a conflict' | |
account = Balanced::Account.find(ex.extras['account_uri']) | |
else # handle other exceptions as you like... | |
raise ex | |
end | |
rescue Balanced::Error => ex | |
print ex.description | |
print ex.message | |
print ex.extras | |
print ex.category_code | |
end | |
puts account.email_address |
This file contains hidden or 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
% curl -u 548b44560cae11e2b5e2026ba7d31e6f: https://api.balancedpayments.com/v1/marketplaces/TEST-MP2zM4sLitt3HBnz2zcPjN6o/accounts -d email_address="[email protected]" | |
{ | |
"status": "Conflict", | |
"category_code": "duplicate-email-address", | |
"additional": null, | |
"status_code": 409, | |
"category_type": "logical", | |
"extras": { | |
"account_uri": "/v1/marketplaces/TEST-MP2zM4sLitt3HBnz2zcPjN6o/accounts/AC2B3UFgTREbGEccodGvDqFq" | |
}, | |
"request_id": "OHM94d6a47e0cae11e2986d026ba7cd33d0", | |
"description": "Account with email address \"[email protected]\" already exists. Your request id is OHM94d6a47e0cae11e2986d026ba7cd33d0." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment