ordrin 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ordrin.rb CHANGED
@@ -1,58 +1,358 @@
1
- require_relative 'ordrin/restaurant'
2
- require_relative 'ordrin/user'
3
- require_relative 'ordrin/order'
4
- require_relative 'ordrin/data'
1
+ require_relative 'ordrin/api_helper'
5
2
 
6
3
  module Ordrin
7
4
  class APIs
5
+ def initialize(api_key, servers=:test)
6
+ @helper = APIHelper.new(api_key, servers)
7
+ end
8
+
9
+
10
+ # order endpoints
11
+
12
+ def order_guest(args)
13
+ =begin
14
+ Arguments:
15
+ rid--Ordr.in's unique restaurant identifier for the restaurant.
16
+ em--The customer's email address
17
+ tray--Represents a tray of menu items in the format '[menu item id]/[qty],[option id],...,[option id]'
18
+ tip--Tip amount in dollars and cents
19
+ first_name--The customer's first name
20
+ last_name--The customer's last name
21
+ phone--The customer's phone number
22
+ zip--The zip code part of the address
23
+ addr--The street address
24
+ city--The city part of the address
25
+ state--The state part of the address
26
+ card_number--Credit card number
27
+ card_cvc--3 or 4 digit security code
28
+ card_expiry--The credit card expiration date.
29
+ card_bill_addr--The credit card's billing street address
30
+ card_bill_city--The credit card's billing city
31
+ card_bill_state--The credit card's billing state
32
+ card_bill_zip--The credit card's billing zip code
33
+ card_bill_phone--The credit card's billing phone number
34
+
35
+ Keyword Arguments:
36
+ addr2--The second part of the street address, if needed
37
+ card_name--Full name as it appears on the credit card
38
+ card_bill_addr2--The second part of the credit card's biling street address.
39
+
40
+
41
+ Either
42
+ delivery_date--Delivery date
43
+ delivery_time--Delivery time
44
+ OR
45
+ delivery_date--Delivery date
46
+ =end
47
+ @helper.call_endpoint(:order, "order_guest", ["rid"], args)
48
+ end
49
+
50
+ def order_user(args)
51
+ =begin
52
+ Arguments:
53
+ rid--Ordr.in's unique restaurant identifier for the restaurant.
54
+ tray--Represents a tray of menu items in the format '[menu item id]/[qty],[option id],...,[option id]'
55
+ tip--Tip amount in dollars and cents
56
+ first_name--The customer's first name
57
+ last_name--The customer's last name
58
+ email -- The user's email
59
+ current_password -- The user's current password
60
+
61
+ Keyword Arguments:
62
+
63
+
64
+ Either
65
+ phone--The customer's phone number
66
+ zip--The zip code part of the address
67
+ addr--The street address
68
+ addr2--The second part of the street address, if needed
69
+ city--The city part of the address
70
+ state--The state part of the address
71
+ OR
72
+ nick--The delivery location nickname. (From the user's addresses)
73
+ Either
74
+ card_name--Full name as it appears on the credit card
75
+ card_number--Credit card number
76
+ card_cvc--3 or 4 digit security code
77
+ card_expiry--The credit card expiration date.
78
+ card_bill_addr--The credit card's billing street address
79
+ card_bill_addr2--The second part of the credit card's biling street address.
80
+ card_bill_city--The credit card's billing city
81
+ card_bill_state--The credit card's billing state
82
+ card_bill_zip--The credit card's billing zip code
83
+ card_bill_phone--The credit card's billing phone number
84
+ OR
85
+ card_nick--The credit card nickname. (From the user's credit cards)
86
+ Either
87
+ delivery_date--Delivery date
88
+ delivery_time--Delivery time
89
+ OR
90
+ delivery_date--Delivery date
91
+ =end
92
+ @helper.call_endpoint(:order, "order_user", ["rid"], args)
93
+ end
94
+
95
+
96
+ # restaurant endpoints
97
+
98
+ def delivery_check(args)
99
+ =begin
100
+ Arguments:
101
+ datetime--Delivery date and time
102
+ rid--Ordr.in's unique restaurant identifier for the restaurant.
103
+ addr--Delivery location street address
104
+ city--Delivery location city
105
+ zip--The zip code part of the address
106
+
107
+ Keyword Arguments:
108
+
109
+
110
+ =end
111
+ @helper.call_endpoint(:restaurant, "delivery_check", ["rid", "datetime", "zip", "city", "addr"], args)
112
+ end
113
+
114
+ def delivery_list(args)
115
+ =begin
116
+ Arguments:
117
+ datetime--Delivery date and time
118
+ addr--Delivery location street address
119
+ city--Delivery location city
120
+ zip--The zip code part of the address
121
+
122
+ Keyword Arguments:
123
+
124
+
125
+ =end
126
+ @helper.call_endpoint(:restaurant, "delivery_list", ["datetime", "zip", "city", "addr"], args)
127
+ end
128
+
129
+ def fee(args)
130
+ =begin
131
+ Arguments:
132
+ datetime--Delivery date and time
133
+ rid--Ordr.in's unique restaurant identifier for the restaurant.
134
+ subtotal--The cost of all items in the tray in dollars and cents.
135
+ tip--The tip in dollars and cents.
136
+ addr--Delivery location street address
137
+ city--Delivery location city
138
+ zip--The zip code part of the address
139
+
140
+ Keyword Arguments:
141
+
142
+
143
+ =end
144
+ @helper.call_endpoint(:restaurant, "fee", ["rid", "subtotal", "tip", "datetime", "zip", "city", "addr"], args)
145
+ end
146
+
147
+ def restaurant_details(args)
148
+ =begin
149
+ Arguments:
150
+ rid--Ordr.in's unique restaurant identifier for the restaurant.
151
+
152
+ Keyword Arguments:
153
+
154
+
155
+ =end
156
+ @helper.call_endpoint(:restaurant, "restaurant_details", ["rid"], args)
157
+ end
158
+
159
+
160
+ # user endpoints
161
+
162
+ def change_password(args)
163
+ =begin
164
+ Arguments:
165
+ email--The user's email address
166
+ password--The user's new password
167
+ current_password -- The user's current password
168
+
169
+ Keyword Arguments:
170
+
171
+
172
+ =end
173
+ @helper.call_endpoint(:user, "change_password", ["email"], args)
174
+ end
175
+
176
+ def create_account(args)
177
+ =begin
178
+ Arguments:
179
+ email--The user's email address
180
+ pw--The user's password
181
+ first_name--The user's first name
182
+ last_name--The user's last name
183
+
184
+ Keyword Arguments:
185
+
186
+
187
+ =end
188
+ @helper.call_endpoint(:user, "create_account", ["email"], args)
189
+ end
190
+
191
+ def create_addr(args)
192
+ =begin
193
+ Arguments:
194
+ email--The user's email address
195
+ nick--The nickname of this address
196
+ phone--The customer's phone number
197
+ zip--The zip code part of the address
198
+ addr--The street address
199
+ city--The city part of the address
200
+ state--The state part of the address
201
+ current_password -- The user's current password
202
+
203
+ Keyword Arguments:
204
+ addr2--The second part of the street address, if needed
205
+
206
+
207
+ =end
208
+ @helper.call_endpoint(:user, "create_addr", ["email", "nick"], args)
209
+ end
210
+
211
+ def create_cc(args)
212
+ =begin
213
+ Arguments:
214
+ email--The user's email address
215
+ nick--The nickname of this address
216
+ card_number--Credit card number
217
+ card_cvc--3 or 4 digit security code
218
+ card_expiry--The credit card expiration date.
219
+ bill_addr--The credit card's billing street address
220
+ bill_city--The credit card's billing city
221
+ bill_state--The credit card's billing state
222
+ bill_zip--The credit card's billing zip code
223
+ bill_phone--The credit card's billing phone number
224
+ current_password -- The user's current password
225
+
226
+ Keyword Arguments:
227
+ bill_addr2--The second part of the credit card's biling street address.
228
+
229
+
230
+ =end
231
+ @helper.call_endpoint(:user, "create_cc", ["email", "nick"], args)
232
+ end
233
+
234
+ def delete_addr(args)
235
+ =begin
236
+ Arguments:
237
+ email--The user's email address
238
+ nick--The nickname of this address
239
+ current_password -- The user's current password
240
+
241
+ Keyword Arguments:
242
+
243
+
244
+ =end
245
+ @helper.call_endpoint(:user, "delete_addr", ["email", "nick"], args)
246
+ end
247
+
248
+ def delete_cc(args)
249
+ =begin
250
+ Arguments:
251
+ email--The user's email address
252
+ nick--The nickname of this address
253
+ current_password -- The user's current password
254
+
255
+ Keyword Arguments:
256
+
257
+
258
+ =end
259
+ @helper.call_endpoint(:user, "delete_cc", ["email", "nick"], args)
260
+ end
8
261
 
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}
262
+ def get_account_info(args)
263
+ =begin
264
+ Arguments:
265
+ email--The user's email address
266
+ current_password -- The user's current password
267
+
268
+ Keyword Arguments:
269
+
270
+
271
+ =end
272
+ @helper.call_endpoint(:user, "get_account_info", ["email"], args)
56
273
  end
274
+
275
+ def get_all_saved_addrs(args)
276
+ =begin
277
+ Arguments:
278
+ email--The user's email address
279
+ current_password -- The user's current password
280
+
281
+ Keyword Arguments:
282
+
283
+
284
+ =end
285
+ @helper.call_endpoint(:user, "get_all_saved_addrs", ["email"], args)
286
+ end
287
+
288
+ def get_all_saved_ccs(args)
289
+ =begin
290
+ Arguments:
291
+ email--The user's email address
292
+ current_password -- The user's current password
293
+
294
+ Keyword Arguments:
295
+
296
+
297
+ =end
298
+ @helper.call_endpoint(:user, "get_all_saved_ccs", ["email"], args)
299
+ end
300
+
301
+ def get_order(args)
302
+ =begin
303
+ Arguments:
304
+ email--The user's email address
305
+ oid--Ordr.in's unique order id number.
306
+ current_password -- The user's current password
307
+
308
+ Keyword Arguments:
309
+
310
+
311
+ =end
312
+ @helper.call_endpoint(:user, "get_order", ["email", "oid"], args)
313
+ end
314
+
315
+ def get_order_history(args)
316
+ =begin
317
+ Arguments:
318
+ email--The user's email address
319
+ current_password -- The user's current password
320
+
321
+ Keyword Arguments:
322
+
323
+
324
+ =end
325
+ @helper.call_endpoint(:user, "get_order_history", ["email"], args)
326
+ end
327
+
328
+ def get_saved_addr(args)
329
+ =begin
330
+ Arguments:
331
+ email--The user's email address
332
+ nick--The nickname of this address
333
+ current_password -- The user's current password
334
+
335
+ Keyword Arguments:
336
+
337
+
338
+ =end
339
+ @helper.call_endpoint(:user, "get_saved_addr", ["email", "nick"], args)
340
+ end
341
+
342
+ def get_saved_cc(args)
343
+ =begin
344
+ Arguments:
345
+ email--The user's email address
346
+ nick--The nickname of this address
347
+ current_password -- The user's current password
348
+
349
+ Keyword Arguments:
350
+
351
+
352
+ =end
353
+ @helper.call_endpoint(:user, "get_saved_cc", ["email", "nick"], args)
354
+ end
355
+
356
+
57
357
  end
58
358
  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
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,28 +10,36 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-02-13 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json-schema
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.3
14
30
  description: Ordrin API wrapper. Used to simplify making calls to the Ordr.in API
15
31
  in Ruby
16
32
  email:
17
33
  - hackfood@ordr.in
18
- executables:
19
- - ordrindemo.rb
34
+ executables: []
20
35
  extensions: []
21
36
  extra_rdoc_files: []
22
37
  files:
23
38
  - lib/ordrin.rb
24
- - lib/ordrin/data.rb
25
- - lib/ordrin/errors.rb
26
- - lib/ordrin/normalize.rb
27
- - lib/ordrin/order.rb
28
- - lib/ordrin/ordrinapi.rb
29
- - lib/ordrin/restaurant.rb
30
- - lib/ordrin/user.rb
39
+ - lib/ordrin/api_helper.rb
40
+ - lib/ordrin/mutate.rb
41
+ - lib/ordrin/schemas.json
31
42
  - lib/ordrin/cacert.pem
32
- - bin/ordrindemo.rb
33
- - LICENSE.txt
34
- - README.md
35
43
  homepage: https://github.com/ordrin/api-ruby
36
44
  licenses: []
37
45
  post_install_message:
data/LICENSE.txt DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2012 ordr.in, inc.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,95 +0,0 @@
1
- Ordr.in Ruby API
2
- ==================
3
-
4
- A Ruby wrapper for the Restaurant, User, and Order APIs provided by Ordr.in. Everything mentioned here is described in more detail in the documentation in the ruby files. The main API documentation can be found at http://ordr.in/developers.
5
-
6
- The demo script (`bin/ordrindemo.rb`) has examples of calling every function and initializing all of the data structures.
7
-
8
- Data Structures
9
- ---------------
10
-
11
- ```python
12
- Ordrin::Data::Address(addr, city, state, zip, phone, addr2='')
13
-
14
- Ordrin::Data::CreditCard(name, expiry_month, expiry_year, bill_address, number, cvc)
15
-
16
- Ordrin::Data::UserLogin(email, password)
17
-
18
- Ordrin::Data::TrayItem(item_id, quantity, *options)
19
-
20
- Ordrin::Data::Tray(*items)
21
- ```
22
-
23
- Exceptions
24
- ----------
25
-
26
- ```python
27
- Ordrin::Errors::ApiError(msg, text)
28
-
29
- Ordrin::Errors::ApiInvalidResponseError(msg)
30
- ```
31
-
32
- API Initialization
33
- ------------------
34
-
35
- ```python
36
- api = Ordrin::APIs(developer_key, servers, restaurant_url, user_url, order_url)
37
- ```
38
-
39
- Restaurant API Functions
40
- ------------------------
41
- All of these functions are in the `ordrin.restaurant` module.
42
-
43
- ```python
44
- api.restaurant.get_delivery_list(date_time, address)
45
-
46
- api.restaurant.get_delivery_check(retaurant_id, date_time, address)
47
-
48
- api.restaurant.get_fee(restaurant_id, subtotal, tip, date_time, address)
49
-
50
- api.restaurant.get_details(restaurant_id)
51
- ```
52
-
53
- User API Functions
54
- ------------------
55
- All of these functions are in the `ordrin.user` module.
56
-
57
- ```python
58
- api.user.get(login)
59
-
60
- api.user.create(login, first_name, last_name)
61
-
62
- api.user.update(login, first_name, last_name)
63
-
64
- api.user.get_all_addresses(login)
65
-
66
- api.user.get_address(login, addr_nick)
67
-
68
- api.user.set_address(login, addr_nick, address)
69
-
70
- api.user.remove_address(login, addr_nick)
71
-
72
- api.user.get_all_credit_cards(login)
73
-
74
- api.user.get_credit_card(login, card_nick)
75
-
76
- api.user.set_credit_card(login, card_nick, credit_card)
77
-
78
- api.user.remove_credit_card(login, card_nick)
79
-
80
- api.user.get_order_history(login)
81
-
82
- api.user.get_order_detail(login, order_id)
83
-
84
- api.user.set_password(login, new_password)
85
- ```
86
-
87
- Order API Functions
88
- -------------------
89
- All of these functions are in the `ordrin.order` module.
90
-
91
- ```python
92
- api.order.order(restaurant_id, tray, tip, delivery_date_time, first_name, last_name, address, credit_card, email=None, login=None)
93
-
94
- order_create_user(restaurant_id, tray, tip, delivery_date_time, first_name, last_name, address, credit_card, email, password)
95
- ```