balanced / balanced-ruby

Balanced API library in ruby.
MIT License
111 stars 47 forks source link

balanced-ruby does not enforce the type returned when doing a find #25

Open mjallday opened 12 years ago

mjallday commented 12 years ago

When I ask for a Debit I should get a Debit, if it's another type of object I should get an error

require 'balanced'

key = Balanced::ApiKey.new.save
Balanced.configure(key.secret)
marketplace = Balanced::Marketplace.new.save

# this should throw an error, instead, it returns an Account object
Balanced::Debit.find(marketplace.owner_account.uri)
mahmoudimus commented 12 years ago

This is a fair request - it should be expected that the find class method of a Resource child only apply to its class types. The only coercion should happen if you use the super class, in this case Resource, find method, which coerce it into the appropriate type.

mjallday commented 12 years ago

This can also happen in this scenario:

balanced_params = {'name' => params[:name], 'email_address' => params[:email_address], 'uri' => params[:balanced_card_uri]} 
balanced_customer = Balanced::Account.new(balanced_params).save

Note that card_uri was accidentally input as uri which produces the confusing error message "Not permitted to perform update on marketplace_cards"