ordr.in-cli 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/ordr.in +174 -0
  2. metadata +54 -0
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # the ordr.in CLI
4
+ # made by: artem titoulenko
5
+ # made at: HackNY F2011 Hackathon
6
+
7
+ require 'json'
8
+ require 'ordrin'
9
+
10
+ def help
11
+ puts "the ordr.in CLI tool\nfinally, nourishment in a terminal"
12
+ puts "usage:"
13
+ puts "`ordr.in` to display the help
14
+ `ordr.in [cuisine] from <zip>` show restaurants and their id's serving [cuisine] in <zip>
15
+ `ordr.in categories <id>` show menu categories from restaurant with <id>
16
+ `ordr.in menu <id> [for <category>]` show the menu for the specified restaurant <id>, trimmed to the specific <category>
17
+ `ordr.in compile_tray <id> <quantity> <id> <quantity>,...` compile a collection of food <id>s and their <quantities>.`ordr.in order
18
+ `ordr.in order <restaurant id> <tray> <tip> <email> <first name> <last name> <street address> <town> <state> <zip> <phone number> <cc number> <cc security code> <expiration month><expiration year (2 digits)>` The motherload of all commands.
19
+ This grabs your compiled <tray>, cc information and assumes that your billing address is the same as the ordering address. You're not leaving your house anyway, why should that change?"
20
+ exit(0)
21
+ end
22
+
23
+ #help if ARGV.empty?
24
+
25
+ if(ARGV[0] == 'help')
26
+ help
27
+ end
28
+
29
+ def print_place place
30
+ puts "name: " + place['na']
31
+ puts "cuisine: " + place['cu'].join(', ')
32
+ puts "address: " + place['ad']
33
+ end
34
+
35
+ def print_places rest, cu = nil
36
+ for i in 0..(rest.size-1) do
37
+ if cu == nil
38
+ puts "\nid: " + rest[i]['id'].to_s
39
+ print_place rest[i]
40
+ else
41
+ if rest[i]['cu'].include? cu
42
+ puts "\nid: " + rest[i]['id'].to_s
43
+ print_place rest[i]
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def print_categories details
50
+ for i in 0..(details['menu'].size-1) do
51
+ puts i.to_s + ": " + details['menu'][i]['name']
52
+ end
53
+ end
54
+
55
+ OrdrIn::API.new("zOPVxYXs4BGZHfuKu8bTaA","https://r-test.ordr.in")
56
+
57
+ dt = OrdrIn::DT.new
58
+ dt.asap = true
59
+
60
+ help if ARGV.empty?
61
+
62
+ if ARGV[0] == 'around' || ARGV[1] == 'around'
63
+ # we're looking for restaurants
64
+ cu = nil
65
+ if(ARGV[0] == 'around')
66
+ address = OrdrIn::Address.new("1 Main St", "College Station", ARGV[1], "", "TX", "9082173824", "hacker")
67
+ else
68
+ address = OrdrIn::Address.new("1 Main St", "College Station", ARGV[2], "", "TX", "9082173824", "hacker")
69
+ cu = ARGV[0]
70
+ end
71
+
72
+ r = OrdrIn::Restaurant.new
73
+ r.delivery_list(dt, address)
74
+ rest = JSON.parse r.delivery_list(dt, address)
75
+ print_places rest, cu
76
+ end
77
+
78
+ case ARGV[0]
79
+ when 'categories'
80
+ # print categories from restaurants menu
81
+ r = OrdrIn::Restaurant.new
82
+ print_categories JSON.parse r.details(rest[ARGV[1]]['id'])
83
+ when 'menu'
84
+ r = OrdrIn::Restaurant.new
85
+ details = JSON.parse r.details(ARGV[1])
86
+ if(ARGV[2] == "for" && ARGV[3])
87
+ details['menu'].each do |k|
88
+ if(k['name'] == ARGV[3])
89
+ puts k['name'] + ":"
90
+ k['children'].each do |c|
91
+ puts "\t" + c['name'] + " - " + c['price']
92
+ puts "\tid: " + c['id']
93
+ puts "\t" + c['descrip'] if c['descrip']
94
+ puts ""
95
+ end
96
+ end
97
+ end
98
+ else
99
+ details['menu'].each do |k|
100
+ puts k['name'] + ":"
101
+ k['children'].each do |c|
102
+ puts "\t" + c['name'] + " - " + c['price']
103
+ puts "\tid: " + c['id']
104
+ puts "\t" + c['descrip'] if c['descrip']
105
+ puts ""
106
+ end
107
+ end
108
+ end
109
+ when 'compile_tray'
110
+ if(ARGV[1] && ARGV[2])
111
+ k = ARGV[1..-1]
112
+ str = ""
113
+ while !k.empty?
114
+ str += "[#{k[0]}][#{k[1]}]"
115
+ k = k[2..-1]
116
+ if k.size >= 2
117
+ str += "-"
118
+ end
119
+ end
120
+ puts str
121
+ end
122
+ when 'order'
123
+ if ARGV.size == 13
124
+ address = OrdrIn::Address.new ARGV[7], ARGV[8], ARGV[10], "", ARGV[9], ARGV[11], "hacker"
125
+ o = OrdrIn::Order.new
126
+ o.submit ARGV[1], ARGV[2], ARGV[3], dt, ARGV[4], ARGV[5], ARGV[6], address, ARGV[5..6].join(' '), ARGV[12], ARGV[13], ARGV[14]
127
+ else
128
+ puts "not enough parameters, add more parameters"
129
+ end
130
+ end
131
+
132
+ if ARGV[0] == 'user'
133
+ api = OrdrIn::API.new "zOPVxYXs4BGZHfuKu8bTaA", "https://u-test.ordr.in"
134
+ user = nil
135
+ address = nil
136
+ if File.exist? File.expand_path("~/.ordr.in.acct")
137
+ data = File.open(File.expand_path("~/.ordr.in.acct"), "r").gets.unpack("A32A32A32A32A32A32A32A32A32")
138
+ api.set_curr_acct data[0].chomp, data[1].chomp
139
+ address = data[4..-1]
140
+ user = OrdrIn::User.new
141
+ puts address
142
+ exit 0
143
+ end
144
+
145
+ case ARGV[1]
146
+ when 'make_account'
147
+ help if ARGV.length != 5
148
+
149
+ u = OrdrIn::User.new
150
+ u.make_acct ARGV[1], ARGV[2], ARGV[3], ARGV[4]
151
+
152
+ File.open(File.expand_path("~/.ordr.in.acct"), "w+") do |file|
153
+ file.puts ARGV[1..-1].pack("A32A32A32A32")
154
+ end
155
+ when 'update_address'
156
+ "log in first" unless $_email
157
+ #"street" "town" "zip" "state" "phone"
158
+ address=OrdrIn::Address.new ARGV[2], ARGV[3], ARGV[4], ARGV[5], ARGV[6]
159
+ api.set_curr_account user[0], user[1]
160
+ user.update_address(address)
161
+
162
+ d = File.open(File.expand_path("~/.ordr.in.acct", "a+"))
163
+ f.seek(128)
164
+ f.write address.pack("A32A32A32A32A32")
165
+ f.close
166
+ when 'order'
167
+ if user and address
168
+ o = OrderIn::Order.new
169
+ o.submit(ARGV[2], ARGV[3], ARGV[4], ARGV[5], dt, user[0], user[2], user[3], address, user[2..3].join(', '), ARGV[6], ARGV[7], ARGV[8], address)
170
+ else
171
+ help
172
+ end
173
+ end
174
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ordr.in-cli
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.2"
6
+ platform: ruby
7
+ authors:
8
+ - Artem Titoulenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-02 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: use ordr.in web services to find restaurants that deliver near your. You can search, compile a tray, and order it.
17
+ email: artem.titoulenko@gmail.com
18
+ executables:
19
+ - ordr.in
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/ordr.in
26
+ homepage: https://github.com/ArtemTitoulenko/ordr.in-cli
27
+ licenses: []
28
+
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.8
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: nourishment through the command line
53
+ test_files: []
54
+