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/lib/ordrin/restaurant.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
require_relative 'ordrinapi'
|
2
|
-
require_relative 'normalize'
|
3
|
-
|
4
|
-
module Ordrin
|
5
|
-
# This object's methods access the ordr.in restaurant API. All return values
|
6
|
-
# are documented at http://ordr.in/developers/restaurant
|
7
|
-
class RestaurantApi < OrdrinApi
|
8
|
-
# Get a list of dicts representing restaurants that will deliver to the
|
9
|
-
# given address at the given time.
|
10
|
-
# Arguments:
|
11
|
-
# date_time -- Either 'ASAP' or a datetime object in the future
|
12
|
-
# address -- the address to deliver to. Should be an Ordrin::Data::Address object
|
13
|
-
def get_delivery_list(date_time, address)
|
14
|
-
dt = Normalize.normalize(date_time, :datetime)
|
15
|
-
return call_api(:get, ['dl', dt, address.zip, address.city, address.addr])
|
16
|
-
end
|
17
|
-
|
18
|
-
# Get data about a given restaurant, including whether it will deliver to
|
19
|
-
# the specified address at the specified time
|
20
|
-
# Arguments:
|
21
|
-
# restaurant_id -- Ordr.in's restaurant identifier
|
22
|
-
# date_time -- Either 'ASAP' or a datetime object in the future
|
23
|
-
# address -- the address to deliver to. Should be an Ordrin::Data::Address object
|
24
|
-
def get_delivery_check(restaurant_id, date_time, address)
|
25
|
-
dt = Normalize.normalize(date_time, :datetime)
|
26
|
-
restauant_id = Normalize.normalize(restaurant_id, :number)
|
27
|
-
return call_api(:get, ['dc', restaurant_id, dt, address.zip, address.city, address.addr])
|
28
|
-
end
|
29
|
-
|
30
|
-
# Get data about a given restaurant, including whether it will deliver to
|
31
|
-
# the specified address at the specified time, and what the fee will be on an
|
32
|
-
# order with the given subtotal and tip
|
33
|
-
# Arguments:
|
34
|
-
# restaurant_id -- Ordr.in's restaurant identifier
|
35
|
-
# subtotal -- the subtotal of the order
|
36
|
-
# tip -- the tip on the order
|
37
|
-
# date_time -- Either 'ASAP' or a datetime object in the future
|
38
|
-
# address -- the address to deliver to. Should be an Ordrin::Data::Address object
|
39
|
-
def get_fee(restaurant_id, subtotal, tip, date_time, address)
|
40
|
-
dt = Normalize.normalize(date_time, :datetime)
|
41
|
-
restaurant_id = Normalize.normalize(restaurant_id, :number)
|
42
|
-
subtotal = Normalize.normalize(subtotal, :money)
|
43
|
-
tip = Normalize.normalize(tip, :money)
|
44
|
-
return call_api(:get, ['fee', restaurant_id, subtotal, tip, dt, address.zip, address.city, address.addr])
|
45
|
-
end
|
46
|
-
|
47
|
-
# Get details of the given restaurant, including contact information and
|
48
|
-
# the menu
|
49
|
-
# Arguments:
|
50
|
-
# restaurant_id -- Ordr.in's restaurant identifier
|
51
|
-
def get_details(restaurant_id)
|
52
|
-
restaurant_id = Normalize.normalize(restaurant_id, :number)
|
53
|
-
return call_api(:get, ['rd', restaurant_id])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
require_relative 'ordrinapi'
|
2
|
+
require_relative 'normalize'
|
3
|
+
|
4
|
+
module Ordrin
|
5
|
+
# This object's methods access the ordr.in restaurant API. All return values
|
6
|
+
# are documented at http://ordr.in/developers/restaurant
|
7
|
+
class RestaurantApi < OrdrinApi
|
8
|
+
# Get a list of dicts representing restaurants that will deliver to the
|
9
|
+
# given address at the given time.
|
10
|
+
# Arguments:
|
11
|
+
# date_time -- Either 'ASAP' or a datetime object in the future
|
12
|
+
# address -- the address to deliver to. Should be an Ordrin::Data::Address object
|
13
|
+
def get_delivery_list(date_time, address)
|
14
|
+
dt = Normalize.normalize(date_time, :datetime)
|
15
|
+
return call_api(:get, ['dl', dt, address.zip, address.city, address.addr])
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get data about a given restaurant, including whether it will deliver to
|
19
|
+
# the specified address at the specified time
|
20
|
+
# Arguments:
|
21
|
+
# restaurant_id -- Ordr.in's restaurant identifier
|
22
|
+
# date_time -- Either 'ASAP' or a datetime object in the future
|
23
|
+
# address -- the address to deliver to. Should be an Ordrin::Data::Address object
|
24
|
+
def get_delivery_check(restaurant_id, date_time, address)
|
25
|
+
dt = Normalize.normalize(date_time, :datetime)
|
26
|
+
restauant_id = Normalize.normalize(restaurant_id, :number)
|
27
|
+
return call_api(:get, ['dc', restaurant_id, dt, address.zip, address.city, address.addr])
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get data about a given restaurant, including whether it will deliver to
|
31
|
+
# the specified address at the specified time, and what the fee will be on an
|
32
|
+
# order with the given subtotal and tip
|
33
|
+
# Arguments:
|
34
|
+
# restaurant_id -- Ordr.in's restaurant identifier
|
35
|
+
# subtotal -- the subtotal of the order
|
36
|
+
# tip -- the tip on the order
|
37
|
+
# date_time -- Either 'ASAP' or a datetime object in the future
|
38
|
+
# address -- the address to deliver to. Should be an Ordrin::Data::Address object
|
39
|
+
def get_fee(restaurant_id, subtotal, tip, date_time, address)
|
40
|
+
dt = Normalize.normalize(date_time, :datetime)
|
41
|
+
restaurant_id = Normalize.normalize(restaurant_id, :number)
|
42
|
+
subtotal = Normalize.normalize(subtotal, :money)
|
43
|
+
tip = Normalize.normalize(tip, :money)
|
44
|
+
return call_api(:get, ['fee', restaurant_id, subtotal, tip, dt, address.zip, address.city, address.addr])
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get details of the given restaurant, including contact information and
|
48
|
+
# the menu
|
49
|
+
# Arguments:
|
50
|
+
# restaurant_id -- Ordr.in's restaurant identifier
|
51
|
+
def get_details(restaurant_id)
|
52
|
+
restaurant_id = Normalize.normalize(restaurant_id, :number)
|
53
|
+
return call_api(:get, ['rd', restaurant_id])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ordrin/user.rb
CHANGED
@@ -1,142 +1,142 @@
|
|
1
|
-
require_relative 'ordrinapi'
|
2
|
-
require_relative 'normalize'
|
3
|
-
require_relative 'data'
|
4
|
-
|
5
|
-
module Ordrin
|
6
|
-
# This class will be used to access the user API. All return values
|
7
|
-
# are documented at http://ordr.in/developers/user
|
8
|
-
class UserApi < OrdrinApi
|
9
|
-
# Gets account information for the user associated with login
|
10
|
-
# Arguments:
|
11
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
12
|
-
def get(login)
|
13
|
-
return call_api(:get, ['u', login.email], login)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Creates account for the user associated with login. Throws a relevant exception
|
17
|
-
# on failure.
|
18
|
-
# Arguments:
|
19
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
20
|
-
# first_name -- the user's first name
|
21
|
-
# last_name -- the user's last name
|
22
|
-
def create(login, first_name, last_name)
|
23
|
-
data = {'email' => login.email,
|
24
|
-
'first_name' => Normalize.normalize(first_name, :name),
|
25
|
-
'last_name' => Normalize.normalize(last_name, :name),
|
26
|
-
'pw' => login.password}
|
27
|
-
return call_api(:post, ['u', login.email], nil, data)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Updates account for the user associated with login. Throws a relevant exception
|
31
|
-
# on failure.
|
32
|
-
# Arguments:
|
33
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
34
|
-
# first_name -- the user's first name
|
35
|
-
# last_name -- the user's last name
|
36
|
-
def update(login, first_name, last_name)
|
37
|
-
data = {'email' => login.email,
|
38
|
-
'first_name' => Normalize.normalize(first_name, :name),
|
39
|
-
'last_name' => Normalize.normalize(last_name, :name),
|
40
|
-
'pw' => login.password}
|
41
|
-
return call_api(:post, ['u', login.email], login, data)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Get a list of all saved addresses for the user associated with login.
|
45
|
-
# Arguments:
|
46
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
47
|
-
def get_all_addresses(login)
|
48
|
-
return call_api(:get, ['u', login.email, 'addrs'], login)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Get a saved address belonging to the logged in user by nickname.
|
52
|
-
# Arguments:
|
53
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
54
|
-
# addr_nick -- the nickname of the address to get
|
55
|
-
def get_address(login, addr_nick)
|
56
|
-
return call_api(:get, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Save an address by nickname for the logged in user
|
60
|
-
# Throws a relevant exception on failure
|
61
|
-
# Arguments:
|
62
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
63
|
-
# addr_nick -- the nickname of the address to save
|
64
|
-
# address -- the address to save. Should be an Ordrin::Data::Address object
|
65
|
-
def set_address(login, addr_nick, address)
|
66
|
-
return call_api(:put, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login, address.make_dict)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Remove an address, saved by the logged in user, by nickname
|
70
|
-
# Throws a relevant exception on failure.
|
71
|
-
# Arguments:
|
72
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
73
|
-
# addr_nick -- the nickname of the address to remove
|
74
|
-
def remove_address(login, addr_nick)
|
75
|
-
return call_api(:delete, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Get a list of all saved credit cards for the user associated with login.
|
79
|
-
# Arguments:
|
80
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
81
|
-
def get_all_credit_cards(login)
|
82
|
-
return call_api(:get, ['u', login.email, 'ccs'], login)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Get a saved credit card belonging to the logged in user by nickname.
|
86
|
-
# Arguments:
|
87
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
88
|
-
# card_nick -- the nickname of the credit card to get
|
89
|
-
def get_credit_card(login, card_nick)
|
90
|
-
return call_api(:get, ['u', login.email, 'ccs', Normalize.normalize(card_nick, :nick)], login)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Save an credit card by nickname for the logged in user
|
94
|
-
# Throws a relevant exception on failure
|
95
|
-
# Arguments:
|
96
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
97
|
-
# card_nick -- the nickname of the credit card to save
|
98
|
-
# credit_card -- the credit card to save. Should be an Ordrin::Data::CreditCard object
|
99
|
-
def set_credit_card(login, card_nick, credit_card)
|
100
|
-
card_nick = Normalize.normalize(card_nick, :nick)
|
101
|
-
data = credit_card.make_dict
|
102
|
-
data.merge!(login.make_dict)
|
103
|
-
data['nick'] = card_nick
|
104
|
-
return call_api(:put, ['u', login.email, 'ccs', card_nick], login, data)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Remove an credit card, saved by the logged in user, by nickname
|
108
|
-
# Throws a relevant exception on failure.
|
109
|
-
# Arguments:
|
110
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
111
|
-
# card_nick -- the nickname of the credit card to remove
|
112
|
-
def remove_credit_card(login, card_nick)
|
113
|
-
return call_api(:delete, ['u', login.email, 'ccs', Normalize.normalize(card_nick, :nick)], login)
|
114
|
-
end
|
115
|
-
|
116
|
-
# Get a list of previous orders by the logged in user.
|
117
|
-
# Arguments:
|
118
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
119
|
-
def get_order_history(login)
|
120
|
-
return call_api(:get, ['u', login.email, 'orders'], login)
|
121
|
-
end
|
122
|
-
|
123
|
-
# Get details of a particular previous order by the logged in user.
|
124
|
-
# Arguments:
|
125
|
-
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
126
|
-
# order_id -- The order ID
|
127
|
-
def get_order_detail(login, order_id)
|
128
|
-
return call_api(:get, ['u', login.email, 'orders', Normalize.normalize(order_id, :alphanum)], login)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Change the logged in user's password.
|
132
|
-
# Arguments:
|
133
|
-
# login -- the user's current login information. Should be an Ordrin::Data::UserLogin object
|
134
|
-
# new_password -- the new password (in plain text)
|
135
|
-
def set_password(login, new_password)
|
136
|
-
data = {'email' => login.email,
|
137
|
-
'password' => Data::UserLogin.hash_password(new_password),
|
138
|
-
'previous_password' => login.password}
|
139
|
-
return self.call_api(:put, ['u', login.email, 'password'], login, data)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
1
|
+
require_relative 'ordrinapi'
|
2
|
+
require_relative 'normalize'
|
3
|
+
require_relative 'data'
|
4
|
+
|
5
|
+
module Ordrin
|
6
|
+
# This class will be used to access the user API. All return values
|
7
|
+
# are documented at http://ordr.in/developers/user
|
8
|
+
class UserApi < OrdrinApi
|
9
|
+
# Gets account information for the user associated with login
|
10
|
+
# Arguments:
|
11
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
12
|
+
def get(login)
|
13
|
+
return call_api(:get, ['u', login.email], login)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates account for the user associated with login. Throws a relevant exception
|
17
|
+
# on failure.
|
18
|
+
# Arguments:
|
19
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
20
|
+
# first_name -- the user's first name
|
21
|
+
# last_name -- the user's last name
|
22
|
+
def create(login, first_name, last_name)
|
23
|
+
data = {'email' => login.email,
|
24
|
+
'first_name' => Normalize.normalize(first_name, :name),
|
25
|
+
'last_name' => Normalize.normalize(last_name, :name),
|
26
|
+
'pw' => login.password}
|
27
|
+
return call_api(:post, ['u', login.email], nil, data)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Updates account for the user associated with login. Throws a relevant exception
|
31
|
+
# on failure.
|
32
|
+
# Arguments:
|
33
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
34
|
+
# first_name -- the user's first name
|
35
|
+
# last_name -- the user's last name
|
36
|
+
def update(login, first_name, last_name)
|
37
|
+
data = {'email' => login.email,
|
38
|
+
'first_name' => Normalize.normalize(first_name, :name),
|
39
|
+
'last_name' => Normalize.normalize(last_name, :name),
|
40
|
+
'pw' => login.password}
|
41
|
+
return call_api(:post, ['u', login.email], login, data)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get a list of all saved addresses for the user associated with login.
|
45
|
+
# Arguments:
|
46
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
47
|
+
def get_all_addresses(login)
|
48
|
+
return call_api(:get, ['u', login.email, 'addrs'], login)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get a saved address belonging to the logged in user by nickname.
|
52
|
+
# Arguments:
|
53
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
54
|
+
# addr_nick -- the nickname of the address to get
|
55
|
+
def get_address(login, addr_nick)
|
56
|
+
return call_api(:get, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Save an address by nickname for the logged in user
|
60
|
+
# Throws a relevant exception on failure
|
61
|
+
# Arguments:
|
62
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
63
|
+
# addr_nick -- the nickname of the address to save
|
64
|
+
# address -- the address to save. Should be an Ordrin::Data::Address object
|
65
|
+
def set_address(login, addr_nick, address)
|
66
|
+
return call_api(:put, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login, address.make_dict)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Remove an address, saved by the logged in user, by nickname
|
70
|
+
# Throws a relevant exception on failure.
|
71
|
+
# Arguments:
|
72
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
73
|
+
# addr_nick -- the nickname of the address to remove
|
74
|
+
def remove_address(login, addr_nick)
|
75
|
+
return call_api(:delete, ['u', login.email, 'addrs', Normalize.normalize(addr_nick, :nick)], login)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Get a list of all saved credit cards for the user associated with login.
|
79
|
+
# Arguments:
|
80
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
81
|
+
def get_all_credit_cards(login)
|
82
|
+
return call_api(:get, ['u', login.email, 'ccs'], login)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get a saved credit card belonging to the logged in user by nickname.
|
86
|
+
# Arguments:
|
87
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
88
|
+
# card_nick -- the nickname of the credit card to get
|
89
|
+
def get_credit_card(login, card_nick)
|
90
|
+
return call_api(:get, ['u', login.email, 'ccs', Normalize.normalize(card_nick, :nick)], login)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Save an credit card by nickname for the logged in user
|
94
|
+
# Throws a relevant exception on failure
|
95
|
+
# Arguments:
|
96
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
97
|
+
# card_nick -- the nickname of the credit card to save
|
98
|
+
# credit_card -- the credit card to save. Should be an Ordrin::Data::CreditCard object
|
99
|
+
def set_credit_card(login, card_nick, credit_card)
|
100
|
+
card_nick = Normalize.normalize(card_nick, :nick)
|
101
|
+
data = credit_card.make_dict
|
102
|
+
data.merge!(login.make_dict)
|
103
|
+
data['nick'] = card_nick
|
104
|
+
return call_api(:put, ['u', login.email, 'ccs', card_nick], login, data)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Remove an credit card, saved by the logged in user, by nickname
|
108
|
+
# Throws a relevant exception on failure.
|
109
|
+
# Arguments:
|
110
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
111
|
+
# card_nick -- the nickname of the credit card to remove
|
112
|
+
def remove_credit_card(login, card_nick)
|
113
|
+
return call_api(:delete, ['u', login.email, 'ccs', Normalize.normalize(card_nick, :nick)], login)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Get a list of previous orders by the logged in user.
|
117
|
+
# Arguments:
|
118
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
119
|
+
def get_order_history(login)
|
120
|
+
return call_api(:get, ['u', login.email, 'orders'], login)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Get details of a particular previous order by the logged in user.
|
124
|
+
# Arguments:
|
125
|
+
# login -- the user's login information. Should be an Ordrin::Data::UserLogin object
|
126
|
+
# order_id -- The order ID
|
127
|
+
def get_order_detail(login, order_id)
|
128
|
+
return call_api(:get, ['u', login.email, 'orders', Normalize.normalize(order_id, :alphanum)], login)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Change the logged in user's password.
|
132
|
+
# Arguments:
|
133
|
+
# login -- the user's current login information. Should be an Ordrin::Data::UserLogin object
|
134
|
+
# new_password -- the new password (in plain text)
|
135
|
+
def set_password(login, new_password)
|
136
|
+
data = {'email' => login.email,
|
137
|
+
'password' => Data::UserLogin.hash_password(new_password),
|
138
|
+
'previous_password' => login.password}
|
139
|
+
return self.call_api(:put, ['u', login.email, 'password'], login, data)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/lib/ordrin.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require_relative 'ordrin/restaurant'
|
2
|
-
require_relative 'ordrin/user'
|
3
|
-
require_relative 'ordrin/order'
|
4
|
-
require_relative 'ordrin/data'
|
5
|
-
|
6
|
-
module Ordrin
|
7
|
-
class APIs
|
8
|
-
|
9
|
-
attr_reader :restaurant, :user, :order
|
10
|
-
|
11
|
-
# Sets up this module to make API calls. The first argument is the developer's
|
12
|
-
# API key. The other three are the URLs corresponding to the three parts of the api.
|
13
|
-
# No API calls will work until this function is called. API objects will only be
|
14
|
-
# instantiated for URLs that are passed in.
|
15
|
-
|
16
|
-
# Arguments:
|
17
|
-
# api_key -- The developer's API key
|
18
|
-
# servers -- How the server URLs should be set. Must be :production, :test, or :custom
|
19
|
-
# restaurant_url -- The base url for the restaurant API. Can only be set if servers==:custom.
|
20
|
-
# user_url -- The base url for the user API. Can only be set if servers==:custom.
|
21
|
-
# order_url -- The base url for the order API. Can only be set if servers==:custom.
|
22
|
-
def initialize(api_key, servers, restaurant_url=nil, user_url=nil, order_url=nil)
|
23
|
-
@api_key = api_key
|
24
|
-
if servers!=:custom
|
25
|
-
unless restaurant_url.nil? and user_url.nil? and order_url.nil?
|
26
|
-
raise ArgumentError.new("Individual URL parameters can only be set if servers is set to :custom")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
if servers==:production
|
30
|
-
restaurant_url = "https://r.ordr.in/"
|
31
|
-
user_url = "https://u.ordr.in/"
|
32
|
-
order_url = "https://o.ordr.in/"
|
33
|
-
elsif servers==:test
|
34
|
-
restaurant_url = "https://r-test.ordr.in/"
|
35
|
-
user_url = "https://u-test.ordr.in/"
|
36
|
-
order_url = "https://o-test.ordr.in/"
|
37
|
-
elsif servers!=:custom
|
38
|
-
raise ArgumentError.new("servers must be set to :production, :test, or :custom")
|
39
|
-
end
|
40
|
-
unless restaurant_url.nil?
|
41
|
-
@restaurant = RestaurantApi.new(api_key, restaurant_url)
|
42
|
-
end
|
43
|
-
unless user_url.nil?
|
44
|
-
@user = UserApi.new(api_key, user_url)
|
45
|
-
end
|
46
|
-
unless order_url.nil?
|
47
|
-
@order = OrderApi.new(api_key, order_url)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def config
|
52
|
-
return {"API key" => api_key,
|
53
|
-
"Restaurant URL" => @restaurant.base_url,
|
54
|
-
"User URL" => @user.base_url,
|
55
|
-
"Order URL" => @order.base_url}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
1
|
+
require_relative 'ordrin/restaurant'
|
2
|
+
require_relative 'ordrin/user'
|
3
|
+
require_relative 'ordrin/order'
|
4
|
+
require_relative 'ordrin/data'
|
5
|
+
|
6
|
+
module Ordrin
|
7
|
+
class APIs
|
8
|
+
|
9
|
+
attr_reader :restaurant, :user, :order
|
10
|
+
|
11
|
+
# Sets up this module to make API calls. The first argument is the developer's
|
12
|
+
# API key. The other three are the URLs corresponding to the three parts of the api.
|
13
|
+
# No API calls will work until this function is called. API objects will only be
|
14
|
+
# instantiated for URLs that are passed in.
|
15
|
+
|
16
|
+
# Arguments:
|
17
|
+
# api_key -- The developer's API key
|
18
|
+
# servers -- How the server URLs should be set. Must be :production, :test, or :custom
|
19
|
+
# restaurant_url -- The base url for the restaurant API. Can only be set if servers==:custom.
|
20
|
+
# user_url -- The base url for the user API. Can only be set if servers==:custom.
|
21
|
+
# order_url -- The base url for the order API. Can only be set if servers==:custom.
|
22
|
+
def initialize(api_key, servers, restaurant_url=nil, user_url=nil, order_url=nil)
|
23
|
+
@api_key = api_key
|
24
|
+
if servers!=:custom
|
25
|
+
unless restaurant_url.nil? and user_url.nil? and order_url.nil?
|
26
|
+
raise ArgumentError.new("Individual URL parameters can only be set if servers is set to :custom")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if servers==:production
|
30
|
+
restaurant_url = "https://r.ordr.in/"
|
31
|
+
user_url = "https://u.ordr.in/"
|
32
|
+
order_url = "https://o.ordr.in/"
|
33
|
+
elsif servers==:test
|
34
|
+
restaurant_url = "https://r-test.ordr.in/"
|
35
|
+
user_url = "https://u-test.ordr.in/"
|
36
|
+
order_url = "https://o-test.ordr.in/"
|
37
|
+
elsif servers!=:custom
|
38
|
+
raise ArgumentError.new("servers must be set to :production, :test, or :custom")
|
39
|
+
end
|
40
|
+
unless restaurant_url.nil?
|
41
|
+
@restaurant = RestaurantApi.new(api_key, restaurant_url)
|
42
|
+
end
|
43
|
+
unless user_url.nil?
|
44
|
+
@user = UserApi.new(api_key, user_url)
|
45
|
+
end
|
46
|
+
unless order_url.nil?
|
47
|
+
@order = OrderApi.new(api_key, order_url)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def config
|
52
|
+
return {"API key" => api_key,
|
53
|
+
"Restaurant URL" => @restaurant.base_url,
|
54
|
+
"User URL" => @user.base_url,
|
55
|
+
"Order URL" => @order.base_url}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ordrin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
description: Ordrin API wrapper. Used to simplify making calls to the Ordr.in API
|
31
31
|
in Ruby
|
32
32
|
email:
|
33
|
-
-
|
33
|
+
- hackfood@ordr.in
|
34
34
|
executables:
|
35
35
|
- ordrindemo.rb
|
36
36
|
extensions: []
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/ordrin/ordrinapi.rb
|
45
45
|
- lib/ordrin/restaurant.rb
|
46
46
|
- lib/ordrin/user.rb
|
47
|
+
- lib/ordrin/cacert.pem
|
47
48
|
- bin/ordrindemo.rb
|
48
49
|
- LICENSE.txt
|
49
50
|
- README.md
|
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
68
|
version: '0'
|
68
69
|
requirements: []
|
69
70
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.24
|
71
72
|
signing_key:
|
72
73
|
specification_version: 3
|
73
74
|
summary: Ordrin API wrapper
|