Class: Ordrin::UserApi
Overview
This class will be used to access the user API. All return values are documented at ordr.in/developers/user
Instance Attribute Summary
Attributes inherited from OrdrinApi
Instance Method Summary collapse
-
#create(login, first_name, last_name) ⇒ Object
Creates account for the user associated with login.
-
#get(login) ⇒ Object
Gets account information for the user associated with login Arguments: login – the user’s login information.
-
#get_address(login, addr_nick) ⇒ Object
Get a saved address belonging to the logged in user by nickname.
-
#get_all_addresses(login) ⇒ Object
Get a list of all saved addresses for the user associated with login.
-
#get_all_credit_cards(login) ⇒ Object
Get a list of all saved credit cards for the user associated with login.
-
#get_credit_card(login, card_nick) ⇒ Object
Get a saved credit card belonging to the logged in user by nickname.
-
#get_order_detail(login, order_id) ⇒ Object
Get details of a particular previous order by the logged in user.
-
#get_order_history(login) ⇒ Object
Get a list of previous orders by the logged in user.
-
#remove_address(login, addr_nick) ⇒ Object
Remove an address, saved by the logged in user, by nickname Throws a relevant exception on failure.
-
#remove_credit_card(login, card_nick) ⇒ Object
Remove an credit card, saved by the logged in user, by nickname Throws a relevant exception on failure.
-
#set_address(login, addr_nick, address) ⇒ Object
Save an address by nickname for the logged in user Throws a relevant exception on failure Arguments: login – the user’s login information.
-
#set_credit_card(login, card_nick, credit_card) ⇒ Object
Save an credit card by nickname for the logged in user Throws a relevant exception on failure Arguments: login – the user’s login information.
-
#set_password(login, new_password) ⇒ Object
Change the logged in user’s password.
-
#update(login, first_name, last_name) ⇒ Object
Updates account for the user associated with login.
Methods inherited from OrdrinApi
Constructor Details
This class inherits a constructor from Ordrin::OrdrinApi
Instance Method Details
#create(login, first_name, last_name) ⇒ Object
Creates account for the user associated with login. Throws a relevant exception on failure. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object first_name – the user’s first name last_name – the user’s last name
22 23 24 25 26 27 28 |
# File 'lib/ordrin/user.rb', line 22 def create(login, first_name, last_name) data = {'email' => login.email, 'first_name' => Normalize.normalize(first_name, :name), 'last_name' => Normalize.normalize(last_name, :name), 'pw' => login.password} return call_api(:post, ['u', login.email], nil, data) end |
#get(login) ⇒ Object
Gets account information for the user associated with login Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object
12 13 14 |
# File 'lib/ordrin/user.rb', line 12 def get(login) return call_api(:get, ['u', login.email], login) end |
#get_address(login, addr_nick) ⇒ Object
Get a saved address belonging to the logged in user by nickname. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object addr_nick – the nickname of the address to get
55 56 57 |
# File 'lib/ordrin/user.rb', line 55 def get_address(login, addr_nick) return call_api(:get, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login) end |
#get_all_addresses(login) ⇒ Object
Get a list of all saved addresses for the user associated with login. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object
47 48 49 |
# File 'lib/ordrin/user.rb', line 47 def get_all_addresses(login) return call_api(:get, ['u', login.email, 'addrs'], login) end |
#get_all_credit_cards(login) ⇒ Object
Get a list of all saved credit cards for the user associated with login. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object
81 82 83 |
# File 'lib/ordrin/user.rb', line 81 def get_all_credit_cards(login) return call_api(:get, ['u', login.email, 'ccs'], login) end |
#get_credit_card(login, card_nick) ⇒ Object
Get a saved credit card belonging to the logged in user by nickname. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object card_nick – the nickname of the credit card to get
89 90 91 |
# File 'lib/ordrin/user.rb', line 89 def get_credit_card(login, card_nick) return call_api(:get, ['u', login.email, 'ccs', Normalize.normalize(card_nick, :nick)], login) end |
#get_order_detail(login, order_id) ⇒ Object
Get details of a particular previous order by the logged in user. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object order_id – The order ID
127 128 129 |
# File 'lib/ordrin/user.rb', line 127 def get_order_detail(login, order_id) return call_api(:get, ['u', login.email, 'orders', Normalize.normalize(order_id, :alphanum)], login) end |
#get_order_history(login) ⇒ Object
Get a list of previous orders by the logged in user. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object
119 120 121 |
# File 'lib/ordrin/user.rb', line 119 def get_order_history(login) return call_api(:get, ['u', login.email, 'orders'], login) end |
#remove_address(login, addr_nick) ⇒ Object
Remove an address, saved by the logged in user, by nickname Throws a relevant exception on failure. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object addr_nick – the nickname of the address to remove
74 75 76 |
# File 'lib/ordrin/user.rb', line 74 def remove_address(login, addr_nick) return call_api(:delete, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login) end |
#remove_credit_card(login, card_nick) ⇒ Object
Remove an credit card, saved by the logged in user, by nickname Throws a relevant exception on failure. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object card_nick – the nickname of the credit card to remove
112 113 114 |
# File 'lib/ordrin/user.rb', line 112 def remove_credit_card(login, card_nick) return call_api(:delete, ['u', login.email, 'ccs', Normalize.normalize(card_nick, :nick)], login) end |
#set_address(login, addr_nick, address) ⇒ Object
Save an address by nickname for the logged in user Throws a relevant exception on failure Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object addr_nick – the nickname of the address to save address – the address to save. Should be an Ordrin::Data::Address object
65 66 67 |
# File 'lib/ordrin/user.rb', line 65 def set_address(login, addr_nick, address) return call_api(:put, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login, address.make_dict) end |
#set_credit_card(login, card_nick, credit_card) ⇒ Object
Save an credit card by nickname for the logged in user Throws a relevant exception on failure Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object card_nick – the nickname of the credit card to save credit_card – the credit card to save. Should be an Ordrin::Data::CreditCard object
99 100 101 102 103 104 105 |
# File 'lib/ordrin/user.rb', line 99 def set_credit_card(login, card_nick, credit_card) card_nick = Normalize.normalize(card_nick, :nick) data = credit_card.make_dict data.merge!(login.make_dict) data['nick'] = card_nick return call_api(:put, ['u', login.email, 'ccs', card_nick], login, data) end |
#set_password(login, new_password) ⇒ Object
Change the logged in user’s password. Arguments: login – the user’s current login information. Should be an Ordrin::Data::UserLogin object new_password – the new password (in plain text)
135 136 137 138 139 140 |
# File 'lib/ordrin/user.rb', line 135 def set_password(login, new_password) data = {'email' => login.email, 'password' => Data::UserLogin.hash_password(new_password), 'previous_password' => login.password} return self.call_api(:put, ['u', login.email, 'password'], login, data) end |
#update(login, first_name, last_name) ⇒ Object
Updates account for the user associated with login. Throws a relevant exception on failure. Arguments: login – the user’s login information. Should be an Ordrin::Data::UserLogin object first_name – the user’s first name last_name – the user’s last name
36 37 38 39 40 41 42 |
# File 'lib/ordrin/user.rb', line 36 def update(login, first_name, last_name) data = {'email' => login.email, 'first_name' => Normalize.normalize(first_name, :name), 'last_name' => Normalize.normalize(last_name, :name), 'pw' => login.password} return call_api(:post, ['u', login.email], login, data) end |