Class: Ordrin::UserApi

Inherits:
OrdrinApi show all
Defined in:
lib/ordrin/user.rb

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

#base_url

Instance Method Summary collapse

Methods inherited from OrdrinApi

#initialize

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(, first_name, last_name)
  data = {'email' => .email,
    'first_name' => Normalize.normalize(first_name, :name),
    'last_name' => Normalize.normalize(last_name, :name),
    'pw' => .password}
  return call_api(:post, ['u', .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()
  return call_api(:get, ['u', .email], )
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(, addr_nick)
  return call_api(:get, ['u', .email, 'addrs', Normalize.normalize(addr_nick, :nick)], )
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()
  return call_api(:get, ['u', .email, 'addrs'], )
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()
  return call_api(:get, ['u', .email, 'ccs'], )
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(, card_nick)
  return call_api(:get, ['u', .email, 'ccs', Normalize.normalize(card_nick, :nick)], )
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(, order_id)
  return call_api(:get, ['u', .email, 'orders', Normalize.normalize(order_id, :alphanum)], )
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()
  return call_api(:get, ['u', .email, 'orders'], )
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(, addr_nick)
  return call_api(:delete, ['u', .email, 'addrs', Normalize.normalize(addr_nick, :nick)], )
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(, card_nick)
  return call_api(:delete, ['u', .email, 'ccs', Normalize.normalize(card_nick, :nick)], )
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(, addr_nick, address)
  return call_api(:put, ['u', .email, 'addrs', Normalize.normalize(addr_nick, :nick)], , 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(, card_nick, credit_card)
  card_nick = Normalize.normalize(card_nick, :nick)
  data = credit_card.make_dict
  data.merge!(.make_dict)
  data['nick'] = card_nick
  return call_api(:put, ['u', .email, 'ccs', card_nick], , 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(, new_password)
  data = {'email' => .email,
    'password' => Data::UserLogin.hash_password(new_password),
    'previous_password' => .password}
  return self.call_api(:put, ['u', .email, 'password'], , 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(, first_name, last_name)
  data = {'email' => .email,
    'first_name' => Normalize.normalize(first_name, :name),
    'last_name' => Normalize.normalize(last_name, :name),
    'pw' => .password}
  return call_api(:post, ['u', .email], , data)
end