ordrin 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE.txt +6 -6
- data/README.md +94 -94
- data/bin/ordrindemo.rb +323 -323
- data/lib/ordrin/cacert.pem +3334 -0
- data/lib/ordrin/data.rb +148 -148
- data/lib/ordrin/errors.rb +147 -147
- data/lib/ordrin/normalize.rb +186 -186
- data/lib/ordrin/order.rb +79 -79
- data/lib/ordrin/ordrinapi.rb +66 -66
- data/lib/ordrin/restaurant.rb +56 -56
- data/lib/ordrin/user.rb +142 -142
- data/lib/ordrin.rb +58 -58
- metadata +5 -4
data/bin/ordrindemo.rb
CHANGED
@@ -1,323 +1,323 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
require 'date'
|
3
|
-
require 'securerandom'
|
4
|
-
require 'pp'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'ordrin'
|
8
|
-
rescue LoadError
|
9
|
-
require 'rubygems'
|
10
|
-
begin
|
11
|
-
require 'ordrin'
|
12
|
-
rescue LoadError
|
13
|
-
require_relative '../lib/ordrin'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module OrdrinDemo
|
18
|
-
#
|
19
|
-
# Global Variables
|
20
|
-
#
|
21
|
-
print "Please input your API key: "
|
22
|
-
STDOUT.flush
|
23
|
-
api_key = gets.chomp
|
24
|
-
|
25
|
-
@@api = Ordrin::APIs.new(api_key, :test)
|
26
|
-
|
27
|
-
# Create an Address object
|
28
|
-
@@address = Ordrin::Data::Address.new('1 Main Street', 'College Station', 'TX', '77840', '(555) 555-5555')
|
29
|
-
@@address_nick = 'addr1'
|
30
|
-
|
31
|
-
# Create a CreditCard object
|
32
|
-
@@first_name = 'Test'
|
33
|
-
@@last_name = 'User'
|
34
|
-
@@credit_card = Ordrin::Data::CreditCard.new("#{@@first_name} #{@@last_name}", '01', (Date.today.year+2).to_s, @@address, '4111111111111111', '123')
|
35
|
-
@@credit_card_nick = 'cc1'
|
36
|
-
|
37
|
-
unique_id = SecureRandom.uuid.to_s.gsub(/-/, '')
|
38
|
-
@@email = "demo+#{unique_id}ruby@ordr.in"
|
39
|
-
@@password = 'password'
|
40
|
-
@@login = Ordrin::Data::UserLogin.new(@@email, @@password)
|
41
|
-
@@alt_first_name = 'Example'
|
42
|
-
@@alt_email = "demo+#{unique_id}rubyalt@ordr.in"
|
43
|
-
@@alt_login = Ordrin::Data::UserLogin.new(@@alt_email, @@password)
|
44
|
-
@@new_password = 'password1'
|
45
|
-
|
46
|
-
#
|
47
|
-
# Restaurant demo functions
|
48
|
-
#
|
49
|
-
|
50
|
-
def OrdrinDemo.delivery_list_immediate_demo()
|
51
|
-
puts "Get a list of restaurants that will deliver if you order now"
|
52
|
-
print "Press enter to execute and see the response"
|
53
|
-
gets
|
54
|
-
delivery_list_immediate = @@api.restaurant.get_delivery_list('ASAP', @@address)
|
55
|
-
PP.pp(delivery_list_immediate)
|
56
|
-
return delivery_list_immediate
|
57
|
-
end
|
58
|
-
|
59
|
-
def OrdrinDemo.delivery_list_future_demo()
|
60
|
-
puts "Get a list of restaurants that will deliver if you order for 12 hours from now"
|
61
|
-
print "Press enter to execute and see the response"
|
62
|
-
gets
|
63
|
-
future_datetime = DateTime.now + 0.5 #A timestamp twelve hours in the future
|
64
|
-
delivery_list_later = @@api.restaurant.get_delivery_list(future_datetime, @@address)
|
65
|
-
PP.pp(delivery_list_later)
|
66
|
-
end
|
67
|
-
|
68
|
-
def OrdrinDemo.delivery_check_demo(restaurant_id)
|
69
|
-
puts "Get whether a particular restaurant will deliver if you order now"
|
70
|
-
print "Press enter to execute and see the response"
|
71
|
-
gets
|
72
|
-
delivery_check = @@api.restaurant.get_delivery_check(restaurant_id, 'ASAP', @@address)
|
73
|
-
PP.pp(delivery_check)
|
74
|
-
end
|
75
|
-
|
76
|
-
def OrdrinDemo.fee_demo(restaurant_id)
|
77
|
-
puts "Get fee and other info for ordering a given amount with a given tip"
|
78
|
-
print "Press enter to execute and see the response"
|
79
|
-
gets
|
80
|
-
subtotal = "$30.00"
|
81
|
-
tip = "$5.00"
|
82
|
-
fee_info = @@api.restaurant.get_fee(restaurant_id, subtotal, tip, 'ASAP', @@address)
|
83
|
-
PP.pp(fee_info)
|
84
|
-
end
|
85
|
-
|
86
|
-
def OrdrinDemo.detail_demo(restaurant_id)
|
87
|
-
puts "Get detailed information about a single restaurant"
|
88
|
-
print "Press enter to execute and see the response"
|
89
|
-
gets
|
90
|
-
restaurant_detail = @@api.restaurant.get_details(restaurant_id)
|
91
|
-
PP.pp(restaurant_detail)
|
92
|
-
return restaurant_detail
|
93
|
-
end
|
94
|
-
|
95
|
-
def OrdrinDemo.find_deliverable_time(restaurant_id)
|
96
|
-
puts "Find a time when this restaurant will deliver"
|
97
|
-
print "Press enter to execute and see the response"
|
98
|
-
gets
|
99
|
-
delivery_check = @@api.restaurant.get_delivery_check(restaurant_id, 'ASAP', @@address)
|
100
|
-
delivery = delivery_check['delivery']
|
101
|
-
if delivery
|
102
|
-
return 'ASAP'
|
103
|
-
end
|
104
|
-
dt = DateTime.now + 1/24.0
|
105
|
-
while not delivery
|
106
|
-
delivery_check = @@api.restaurant.get_delivery_check(restaurant_id, dt, @@address)
|
107
|
-
delivery = delivery_check['delivery']
|
108
|
-
dt += 1/24.0
|
109
|
-
end
|
110
|
-
return dt
|
111
|
-
end
|
112
|
-
#
|
113
|
-
# User demo functions
|
114
|
-
#
|
115
|
-
|
116
|
-
def OrdrinDemo.get_user_demo()
|
117
|
-
puts "Get information about a user"
|
118
|
-
print "Press enter to execute and see the response"
|
119
|
-
gets
|
120
|
-
user_info = @@api.user.get(@@login)
|
121
|
-
PP.pp(user_info)
|
122
|
-
end
|
123
|
-
|
124
|
-
def OrdrinDemo.create_user_demo()
|
125
|
-
puts "Create a user"
|
126
|
-
print "Press enter to execute and see the response"
|
127
|
-
gets
|
128
|
-
response = @@api.user.create(@@login, @@first_name, @@last_name)
|
129
|
-
PP.pp(response)
|
130
|
-
end
|
131
|
-
|
132
|
-
def OrdrinDemo.update_user_demo()
|
133
|
-
puts "Update a user"
|
134
|
-
print "Press enter to execute and see the response"
|
135
|
-
gets
|
136
|
-
response = @@api.user.update(@@login, @@alt_first_name, @@last_name)
|
137
|
-
PP.pp(response)
|
138
|
-
end
|
139
|
-
|
140
|
-
def OrdrinDemo.get_all_addresses_demo()
|
141
|
-
puts "Get a list of all saved addresses"
|
142
|
-
print "Press enter to execute and see the response"
|
143
|
-
gets
|
144
|
-
address_list = @@api.user.get_all_addresses(@@login)
|
145
|
-
PP.pp(address_list)
|
146
|
-
end
|
147
|
-
|
148
|
-
def OrdrinDemo.get_address_demo()
|
149
|
-
puts "Get an address by nickname"
|
150
|
-
print "Press enter to execute and see the response"
|
151
|
-
gets
|
152
|
-
addr = @@api.user.get_address(@@login, @@address_nick)
|
153
|
-
PP.pp(addr)
|
154
|
-
end
|
155
|
-
|
156
|
-
def OrdrinDemo.set_address_demo()
|
157
|
-
puts "Save an address with a nickname"
|
158
|
-
response = @@api.user.set_address(@@login, @@address_nick, @@address)
|
159
|
-
PP.pp(response)
|
160
|
-
end
|
161
|
-
|
162
|
-
def OrdrinDemo.remove_address_demo()
|
163
|
-
puts "Remove a saved address by nickname"
|
164
|
-
print "Press enter to execute and see the response"
|
165
|
-
gets
|
166
|
-
response = @@api.user.remove_address(@@login, @@address_nick)
|
167
|
-
PP.pp(response)
|
168
|
-
end
|
169
|
-
|
170
|
-
def OrdrinDemo.get_all_credit_cards_demo()
|
171
|
-
puts "Get a list of all saved credit cards"
|
172
|
-
credit_card_list = @@api.user.get_all_credit_cards(@@login)
|
173
|
-
PP.pp(credit_card_list)
|
174
|
-
end
|
175
|
-
|
176
|
-
def OrdrinDemo.get_credit_card_demo()
|
177
|
-
puts "Get a saved credit card by nickname"
|
178
|
-
print "Press enter to execute and see the response"
|
179
|
-
gets
|
180
|
-
credit_card = @@api.user.get_credit_card(@@login, @@credit_card_nick)
|
181
|
-
PP.pp(credit_card)
|
182
|
-
end
|
183
|
-
|
184
|
-
def OrdrinDemo.set_credit_card_demo()
|
185
|
-
puts "Save a credit card with a nickname"
|
186
|
-
print "Press enter to execute and see the response"
|
187
|
-
gets
|
188
|
-
response = @@api.user.set_credit_card(@@login, @@credit_card_nick, @@credit_card)
|
189
|
-
PP.pp(response)
|
190
|
-
end
|
191
|
-
|
192
|
-
def OrdrinDemo.remove_credit_card_demo()
|
193
|
-
puts "Remove a saved credit card by nickname"
|
194
|
-
print "Press enter to execute and see the response"
|
195
|
-
gets
|
196
|
-
response = @@api.user.remove_credit_card(@@login, @@credit_card_nick)
|
197
|
-
PP.pp(response)
|
198
|
-
end
|
199
|
-
|
200
|
-
def OrdrinDemo.get_order_history_demo(login)
|
201
|
-
puts "Get a list of all orders made by this user"
|
202
|
-
print "Press enter to execute and see the response"
|
203
|
-
gets
|
204
|
-
order_list = @@api.user.get_order_history(@@login)
|
205
|
-
PP.pp(order_list)
|
206
|
-
end
|
207
|
-
|
208
|
-
def OrdrinDemo.get_order_detail_demo(oid)
|
209
|
-
puts "Get the details of a particular order made by this user"
|
210
|
-
print "Press enter to execute and see the response"
|
211
|
-
gets
|
212
|
-
order_detail = @@api.user.get_order_detail(@@login, oid)
|
213
|
-
PP.pp(order_detail)
|
214
|
-
end
|
215
|
-
|
216
|
-
def OrdrinDemo.set_password_demo()
|
217
|
-
puts "Set a new password for a user"
|
218
|
-
print "Press enter to execute and see the response"
|
219
|
-
gets
|
220
|
-
response = @@api.user.set_password(@@login, @@new_password)
|
221
|
-
PP.pp(response)
|
222
|
-
end
|
223
|
-
|
224
|
-
#
|
225
|
-
# Order demo functions
|
226
|
-
#
|
227
|
-
|
228
|
-
def OrdrinDemo.anonymous_order_demo(restaurant_id, tray, date_time)
|
229
|
-
puts "Order food as someone without a user account"
|
230
|
-
print "Press enter to execute and see the response"
|
231
|
-
gets
|
232
|
-
tip = Random.rand(500)/100.0
|
233
|
-
response = @@api.order.order(restaurant_id, tray, tip, date_time, @@first_name, @@last_name, @@address, @@credit_card, @@email)
|
234
|
-
PP.pp(response)
|
235
|
-
end
|
236
|
-
|
237
|
-
def OrdrinDemo.create_user_and_order_demo(restaurant_id, tray, date_time)
|
238
|
-
puts "Order food and create an account"
|
239
|
-
print "Press enter to execute and see the response"
|
240
|
-
gets
|
241
|
-
tip = Random.rand(500)/100.0
|
242
|
-
response = @@api.order.order_create_user(restaurant_id, tray, tip, date_time, @@first_name, @@last_name, @@address, @@credit_card, @@alt_email, @@password)
|
243
|
-
PP.pp(response)
|
244
|
-
end
|
245
|
-
|
246
|
-
def OrdrinDemo.order_with_nicks_demo(restaurant_id, tray, date_time)
|
247
|
-
puts "Order food as a logged in user using previously stored address and credit card"
|
248
|
-
print "Press enter to execute and see the response"
|
249
|
-
gets
|
250
|
-
tip = Random.rand(500)/100.0
|
251
|
-
response = @@api.order.order(restaurant_id, tray, tip, date_time, @@first_name, @@last_name, @@address_nick, @@credit_card_nick, nil, @@login)
|
252
|
-
PP.pp(response)
|
253
|
-
return response
|
254
|
-
end
|
255
|
-
|
256
|
-
def OrdrinDemo.find_item_to_order(item_list)
|
257
|
-
for item in item_list
|
258
|
-
if item['is_orderable']=='1'
|
259
|
-
if item['price'].to_f>=5.00
|
260
|
-
return item['id']
|
261
|
-
end
|
262
|
-
else
|
263
|
-
if item.has_key?('children')
|
264
|
-
item_id = find_item_to_order(item['children'])
|
265
|
-
unless item_id.nil?
|
266
|
-
return item_id
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
nil
|
272
|
-
end
|
273
|
-
|
274
|
-
|
275
|
-
#
|
276
|
-
# Main
|
277
|
-
#
|
278
|
-
def OrdrinDemo.run_demo()
|
279
|
-
puts "Run through the entire demo sequence"
|
280
|
-
# Restaurant functions
|
281
|
-
delivery_list = delivery_list_immediate_demo()
|
282
|
-
delivery_list_future_demo()
|
283
|
-
restaurant_id = delivery_list[0]['id']
|
284
|
-
delivery_check_demo(restaurant_id)
|
285
|
-
fee_demo(restaurant_id)
|
286
|
-
detail = detail_demo(restaurant_id)
|
287
|
-
|
288
|
-
# User functions
|
289
|
-
create_user_demo()
|
290
|
-
get_user_demo()
|
291
|
-
update_user_demo()
|
292
|
-
get_user_demo()
|
293
|
-
set_address_demo()
|
294
|
-
get_address_demo()
|
295
|
-
set_credit_card_demo()
|
296
|
-
get_credit_card_demo()
|
297
|
-
|
298
|
-
# Order functions
|
299
|
-
order_date_time = find_deliverable_time(restaurant_id)
|
300
|
-
puts "Ordering food at #{order_date_time}"
|
301
|
-
item_id = find_item_to_order(detail['menu'])
|
302
|
-
item = Ordrin::Data::TrayItem.new(item_id, 10)
|
303
|
-
tray = Ordrin::Data::Tray.new(item)
|
304
|
-
anonymous_order_demo(restaurant_id, tray, order_date_time)
|
305
|
-
order = order_with_nicks_demo(restaurant_id, tray, order_date_time)
|
306
|
-
unless order.nil?
|
307
|
-
get_order_detail_demo(order['refnum'])
|
308
|
-
end
|
309
|
-
|
310
|
-
create_user_and_order_demo(restaurant_id, tray, order_date_time)
|
311
|
-
get_order_history_demo(@@alt_login)
|
312
|
-
|
313
|
-
# Clean up/removing stuff
|
314
|
-
remove_address_demo()
|
315
|
-
get_all_addresses_demo()
|
316
|
-
remove_credit_card_demo()
|
317
|
-
get_all_credit_cards_demo()
|
318
|
-
set_password_demo()
|
319
|
-
#After changing the password I must change the login object to continue to access user info
|
320
|
-
end
|
321
|
-
|
322
|
-
run_demo()
|
323
|
-
end
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'date'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'ordrin'
|
8
|
+
rescue LoadError
|
9
|
+
require 'rubygems'
|
10
|
+
begin
|
11
|
+
require 'ordrin'
|
12
|
+
rescue LoadError
|
13
|
+
require_relative '../lib/ordrin'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module OrdrinDemo
|
18
|
+
#
|
19
|
+
# Global Variables
|
20
|
+
#
|
21
|
+
print "Please input your API key: "
|
22
|
+
STDOUT.flush
|
23
|
+
api_key = gets.chomp
|
24
|
+
|
25
|
+
@@api = Ordrin::APIs.new(api_key, :test)
|
26
|
+
|
27
|
+
# Create an Address object
|
28
|
+
@@address = Ordrin::Data::Address.new('1 Main Street', 'College Station', 'TX', '77840', '(555) 555-5555')
|
29
|
+
@@address_nick = 'addr1'
|
30
|
+
|
31
|
+
# Create a CreditCard object
|
32
|
+
@@first_name = 'Test'
|
33
|
+
@@last_name = 'User'
|
34
|
+
@@credit_card = Ordrin::Data::CreditCard.new("#{@@first_name} #{@@last_name}", '01', (Date.today.year+2).to_s, @@address, '4111111111111111', '123')
|
35
|
+
@@credit_card_nick = 'cc1'
|
36
|
+
|
37
|
+
unique_id = SecureRandom.uuid.to_s.gsub(/-/, '')
|
38
|
+
@@email = "demo+#{unique_id}ruby@ordr.in"
|
39
|
+
@@password = 'password'
|
40
|
+
@@login = Ordrin::Data::UserLogin.new(@@email, @@password)
|
41
|
+
@@alt_first_name = 'Example'
|
42
|
+
@@alt_email = "demo+#{unique_id}rubyalt@ordr.in"
|
43
|
+
@@alt_login = Ordrin::Data::UserLogin.new(@@alt_email, @@password)
|
44
|
+
@@new_password = 'password1'
|
45
|
+
|
46
|
+
#
|
47
|
+
# Restaurant demo functions
|
48
|
+
#
|
49
|
+
|
50
|
+
def OrdrinDemo.delivery_list_immediate_demo()
|
51
|
+
puts "Get a list of restaurants that will deliver if you order now"
|
52
|
+
print "Press enter to execute and see the response"
|
53
|
+
gets
|
54
|
+
delivery_list_immediate = @@api.restaurant.get_delivery_list('ASAP', @@address)
|
55
|
+
PP.pp(delivery_list_immediate)
|
56
|
+
return delivery_list_immediate
|
57
|
+
end
|
58
|
+
|
59
|
+
def OrdrinDemo.delivery_list_future_demo()
|
60
|
+
puts "Get a list of restaurants that will deliver if you order for 12 hours from now"
|
61
|
+
print "Press enter to execute and see the response"
|
62
|
+
gets
|
63
|
+
future_datetime = DateTime.now + 0.5 #A timestamp twelve hours in the future
|
64
|
+
delivery_list_later = @@api.restaurant.get_delivery_list(future_datetime, @@address)
|
65
|
+
PP.pp(delivery_list_later)
|
66
|
+
end
|
67
|
+
|
68
|
+
def OrdrinDemo.delivery_check_demo(restaurant_id)
|
69
|
+
puts "Get whether a particular restaurant will deliver if you order now"
|
70
|
+
print "Press enter to execute and see the response"
|
71
|
+
gets
|
72
|
+
delivery_check = @@api.restaurant.get_delivery_check(restaurant_id, 'ASAP', @@address)
|
73
|
+
PP.pp(delivery_check)
|
74
|
+
end
|
75
|
+
|
76
|
+
def OrdrinDemo.fee_demo(restaurant_id)
|
77
|
+
puts "Get fee and other info for ordering a given amount with a given tip"
|
78
|
+
print "Press enter to execute and see the response"
|
79
|
+
gets
|
80
|
+
subtotal = "$30.00"
|
81
|
+
tip = "$5.00"
|
82
|
+
fee_info = @@api.restaurant.get_fee(restaurant_id, subtotal, tip, 'ASAP', @@address)
|
83
|
+
PP.pp(fee_info)
|
84
|
+
end
|
85
|
+
|
86
|
+
def OrdrinDemo.detail_demo(restaurant_id)
|
87
|
+
puts "Get detailed information about a single restaurant"
|
88
|
+
print "Press enter to execute and see the response"
|
89
|
+
gets
|
90
|
+
restaurant_detail = @@api.restaurant.get_details(restaurant_id)
|
91
|
+
PP.pp(restaurant_detail)
|
92
|
+
return restaurant_detail
|
93
|
+
end
|
94
|
+
|
95
|
+
def OrdrinDemo.find_deliverable_time(restaurant_id)
|
96
|
+
puts "Find a time when this restaurant will deliver"
|
97
|
+
print "Press enter to execute and see the response"
|
98
|
+
gets
|
99
|
+
delivery_check = @@api.restaurant.get_delivery_check(restaurant_id, 'ASAP', @@address)
|
100
|
+
delivery = delivery_check['delivery']
|
101
|
+
if delivery
|
102
|
+
return 'ASAP'
|
103
|
+
end
|
104
|
+
dt = DateTime.now + 1/24.0
|
105
|
+
while not delivery
|
106
|
+
delivery_check = @@api.restaurant.get_delivery_check(restaurant_id, dt, @@address)
|
107
|
+
delivery = delivery_check['delivery']
|
108
|
+
dt += 1/24.0
|
109
|
+
end
|
110
|
+
return dt
|
111
|
+
end
|
112
|
+
#
|
113
|
+
# User demo functions
|
114
|
+
#
|
115
|
+
|
116
|
+
def OrdrinDemo.get_user_demo()
|
117
|
+
puts "Get information about a user"
|
118
|
+
print "Press enter to execute and see the response"
|
119
|
+
gets
|
120
|
+
user_info = @@api.user.get(@@login)
|
121
|
+
PP.pp(user_info)
|
122
|
+
end
|
123
|
+
|
124
|
+
def OrdrinDemo.create_user_demo()
|
125
|
+
puts "Create a user"
|
126
|
+
print "Press enter to execute and see the response"
|
127
|
+
gets
|
128
|
+
response = @@api.user.create(@@login, @@first_name, @@last_name)
|
129
|
+
PP.pp(response)
|
130
|
+
end
|
131
|
+
|
132
|
+
def OrdrinDemo.update_user_demo()
|
133
|
+
puts "Update a user"
|
134
|
+
print "Press enter to execute and see the response"
|
135
|
+
gets
|
136
|
+
response = @@api.user.update(@@login, @@alt_first_name, @@last_name)
|
137
|
+
PP.pp(response)
|
138
|
+
end
|
139
|
+
|
140
|
+
def OrdrinDemo.get_all_addresses_demo()
|
141
|
+
puts "Get a list of all saved addresses"
|
142
|
+
print "Press enter to execute and see the response"
|
143
|
+
gets
|
144
|
+
address_list = @@api.user.get_all_addresses(@@login)
|
145
|
+
PP.pp(address_list)
|
146
|
+
end
|
147
|
+
|
148
|
+
def OrdrinDemo.get_address_demo()
|
149
|
+
puts "Get an address by nickname"
|
150
|
+
print "Press enter to execute and see the response"
|
151
|
+
gets
|
152
|
+
addr = @@api.user.get_address(@@login, @@address_nick)
|
153
|
+
PP.pp(addr)
|
154
|
+
end
|
155
|
+
|
156
|
+
def OrdrinDemo.set_address_demo()
|
157
|
+
puts "Save an address with a nickname"
|
158
|
+
response = @@api.user.set_address(@@login, @@address_nick, @@address)
|
159
|
+
PP.pp(response)
|
160
|
+
end
|
161
|
+
|
162
|
+
def OrdrinDemo.remove_address_demo()
|
163
|
+
puts "Remove a saved address by nickname"
|
164
|
+
print "Press enter to execute and see the response"
|
165
|
+
gets
|
166
|
+
response = @@api.user.remove_address(@@login, @@address_nick)
|
167
|
+
PP.pp(response)
|
168
|
+
end
|
169
|
+
|
170
|
+
def OrdrinDemo.get_all_credit_cards_demo()
|
171
|
+
puts "Get a list of all saved credit cards"
|
172
|
+
credit_card_list = @@api.user.get_all_credit_cards(@@login)
|
173
|
+
PP.pp(credit_card_list)
|
174
|
+
end
|
175
|
+
|
176
|
+
def OrdrinDemo.get_credit_card_demo()
|
177
|
+
puts "Get a saved credit card by nickname"
|
178
|
+
print "Press enter to execute and see the response"
|
179
|
+
gets
|
180
|
+
credit_card = @@api.user.get_credit_card(@@login, @@credit_card_nick)
|
181
|
+
PP.pp(credit_card)
|
182
|
+
end
|
183
|
+
|
184
|
+
def OrdrinDemo.set_credit_card_demo()
|
185
|
+
puts "Save a credit card with a nickname"
|
186
|
+
print "Press enter to execute and see the response"
|
187
|
+
gets
|
188
|
+
response = @@api.user.set_credit_card(@@login, @@credit_card_nick, @@credit_card)
|
189
|
+
PP.pp(response)
|
190
|
+
end
|
191
|
+
|
192
|
+
def OrdrinDemo.remove_credit_card_demo()
|
193
|
+
puts "Remove a saved credit card by nickname"
|
194
|
+
print "Press enter to execute and see the response"
|
195
|
+
gets
|
196
|
+
response = @@api.user.remove_credit_card(@@login, @@credit_card_nick)
|
197
|
+
PP.pp(response)
|
198
|
+
end
|
199
|
+
|
200
|
+
def OrdrinDemo.get_order_history_demo(login)
|
201
|
+
puts "Get a list of all orders made by this user"
|
202
|
+
print "Press enter to execute and see the response"
|
203
|
+
gets
|
204
|
+
order_list = @@api.user.get_order_history(@@login)
|
205
|
+
PP.pp(order_list)
|
206
|
+
end
|
207
|
+
|
208
|
+
def OrdrinDemo.get_order_detail_demo(oid)
|
209
|
+
puts "Get the details of a particular order made by this user"
|
210
|
+
print "Press enter to execute and see the response"
|
211
|
+
gets
|
212
|
+
order_detail = @@api.user.get_order_detail(@@login, oid)
|
213
|
+
PP.pp(order_detail)
|
214
|
+
end
|
215
|
+
|
216
|
+
def OrdrinDemo.set_password_demo()
|
217
|
+
puts "Set a new password for a user"
|
218
|
+
print "Press enter to execute and see the response"
|
219
|
+
gets
|
220
|
+
response = @@api.user.set_password(@@login, @@new_password)
|
221
|
+
PP.pp(response)
|
222
|
+
end
|
223
|
+
|
224
|
+
#
|
225
|
+
# Order demo functions
|
226
|
+
#
|
227
|
+
|
228
|
+
def OrdrinDemo.anonymous_order_demo(restaurant_id, tray, date_time)
|
229
|
+
puts "Order food as someone without a user account"
|
230
|
+
print "Press enter to execute and see the response"
|
231
|
+
gets
|
232
|
+
tip = Random.rand(500)/100.0
|
233
|
+
response = @@api.order.order(restaurant_id, tray, tip, date_time, @@first_name, @@last_name, @@address, @@credit_card, @@email)
|
234
|
+
PP.pp(response)
|
235
|
+
end
|
236
|
+
|
237
|
+
def OrdrinDemo.create_user_and_order_demo(restaurant_id, tray, date_time)
|
238
|
+
puts "Order food and create an account"
|
239
|
+
print "Press enter to execute and see the response"
|
240
|
+
gets
|
241
|
+
tip = Random.rand(500)/100.0
|
242
|
+
response = @@api.order.order_create_user(restaurant_id, tray, tip, date_time, @@first_name, @@last_name, @@address, @@credit_card, @@alt_email, @@password)
|
243
|
+
PP.pp(response)
|
244
|
+
end
|
245
|
+
|
246
|
+
def OrdrinDemo.order_with_nicks_demo(restaurant_id, tray, date_time)
|
247
|
+
puts "Order food as a logged in user using previously stored address and credit card"
|
248
|
+
print "Press enter to execute and see the response"
|
249
|
+
gets
|
250
|
+
tip = Random.rand(500)/100.0
|
251
|
+
response = @@api.order.order(restaurant_id, tray, tip, date_time, @@first_name, @@last_name, @@address_nick, @@credit_card_nick, nil, @@login)
|
252
|
+
PP.pp(response)
|
253
|
+
return response
|
254
|
+
end
|
255
|
+
|
256
|
+
def OrdrinDemo.find_item_to_order(item_list)
|
257
|
+
for item in item_list
|
258
|
+
if item['is_orderable']=='1'
|
259
|
+
if item['price'].to_f>=5.00
|
260
|
+
return item['id']
|
261
|
+
end
|
262
|
+
else
|
263
|
+
if item.has_key?('children')
|
264
|
+
item_id = find_item_to_order(item['children'])
|
265
|
+
unless item_id.nil?
|
266
|
+
return item_id
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
nil
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
#
|
276
|
+
# Main
|
277
|
+
#
|
278
|
+
def OrdrinDemo.run_demo()
|
279
|
+
puts "Run through the entire demo sequence"
|
280
|
+
# Restaurant functions
|
281
|
+
delivery_list = delivery_list_immediate_demo()
|
282
|
+
delivery_list_future_demo()
|
283
|
+
restaurant_id = delivery_list[0]['id']
|
284
|
+
delivery_check_demo(restaurant_id)
|
285
|
+
fee_demo(restaurant_id)
|
286
|
+
detail = detail_demo(restaurant_id)
|
287
|
+
|
288
|
+
# User functions
|
289
|
+
create_user_demo()
|
290
|
+
get_user_demo()
|
291
|
+
update_user_demo()
|
292
|
+
get_user_demo()
|
293
|
+
set_address_demo()
|
294
|
+
get_address_demo()
|
295
|
+
set_credit_card_demo()
|
296
|
+
get_credit_card_demo()
|
297
|
+
|
298
|
+
# Order functions
|
299
|
+
order_date_time = find_deliverable_time(restaurant_id)
|
300
|
+
puts "Ordering food at #{order_date_time}"
|
301
|
+
item_id = find_item_to_order(detail['menu'])
|
302
|
+
item = Ordrin::Data::TrayItem.new(item_id, 10)
|
303
|
+
tray = Ordrin::Data::Tray.new(item)
|
304
|
+
anonymous_order_demo(restaurant_id, tray, order_date_time)
|
305
|
+
order = order_with_nicks_demo(restaurant_id, tray, order_date_time)
|
306
|
+
unless order.nil?
|
307
|
+
get_order_detail_demo(order['refnum'])
|
308
|
+
end
|
309
|
+
|
310
|
+
create_user_and_order_demo(restaurant_id, tray, order_date_time)
|
311
|
+
get_order_history_demo(@@alt_login)
|
312
|
+
|
313
|
+
# Clean up/removing stuff
|
314
|
+
remove_address_demo()
|
315
|
+
get_all_addresses_demo()
|
316
|
+
remove_credit_card_demo()
|
317
|
+
get_all_credit_cards_demo()
|
318
|
+
set_password_demo()
|
319
|
+
#After changing the password I must change the login object to continue to access user info
|
320
|
+
end
|
321
|
+
|
322
|
+
run_demo()
|
323
|
+
end
|