hungry 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.rspec +1 -1
- data/.ruby-version +1 -0
- data/.travis.yml +19 -0
- data/Gemfile +7 -1
- data/Gemfile.lock +104 -0
- data/Rakefile +14 -0
- data/hungry.gemspec +0 -5
- data/lib/hungry.rb +20 -8
- data/lib/hungry/collection.rb +43 -9
- data/lib/hungry/collection/pagination.rb +17 -0
- data/lib/hungry/geolocation.rb +22 -2
- data/lib/hungry/location.rb +13 -8
- data/lib/hungry/menu.rb +53 -0
- data/lib/hungry/menu/category.rb +22 -0
- data/lib/hungry/menu/dish.rb +22 -0
- data/lib/hungry/menu/option.rb +9 -0
- data/lib/hungry/resource.rb +80 -12
- data/lib/hungry/response.rb +17 -0
- data/lib/hungry/review.rb +6 -6
- data/lib/hungry/site.rb +20 -6
- data/lib/hungry/tag.rb +6 -7
- data/lib/hungry/user.rb +77 -0
- data/lib/hungry/util.rb +44 -4
- data/lib/hungry/venue.rb +39 -18
- data/lib/hungry/venue/collection.rb +9 -0
- data/spec/hungry/geolocation_spec.rb +43 -43
- data/spec/hungry/util_spec.rb +18 -18
- data/spec/spec_helper.rb +0 -1
- metadata +20 -63
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f382ff7047bd18e021c8c7320fb9a95542cf0ac
|
4
|
+
data.tar.gz: a9bd20ca16e736a776b557b32d789987486e71c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72012a98730db3ab4c92c5bb72994f0eca7cb25009e27ceb0e3be395cbc86d91d7d860b0719394fee02661cd3ab141c0760456e173caf0e62ad66e5c68fb8830
|
7
|
+
data.tar.gz: ca2815e04c8a495f0f168826d49db1d4b9150fc2a0f4864e2568898c9f9ff28ec43a45d0381c6331dcc9cf578ab43c4fe14e09b15e5581b839948a8b799f6cc2
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format
|
2
|
+
--format documentation
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# SSH Key to pull private repositories:
|
2
|
+
source_key: "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBM0MySG13YUFIOTQrOW9pb1NSU2I4enk3OHlQemxuL0hxcEdEVjhWREllR1NseTFPCi9VUmVpRnpkcEY2eEN1Y3RRWFkvVHA3QTBxKzMrMWd5cnBuZW00SWNVYUZTZ1kxelYxZ2JQY0VWVzJlWDIxVlEKN1pDdVBIYzFkbDI1K2gvbzQ3Z0l6aWwrT3dyUTNvdFVjdE9KNzk1ckxYZlp3SVAxMDZGcU9UTEhiWVluRGJjZgptYnZzSlllQmJtcEs3YlZndGs1cTdSUW5qWHlzRE0rWndObTZmamlOZWh5QTFCdlZrVWlpM2VQN3N1Q0g0ZHVUCkNVa3hKcFg2S3RKMzRxcHhvMDhlSDBvUUdSRDkrSEZjcDdYTEdJQmhCSzZhMzJTUURJci9KRy9CSWZnSTBYVkcKL1BsbU1wUmZpdlZkaGNXQUVNQmgzVzA4VkFLbmVpTUFXVUZYMFFJREFRQUJBb0lCQUJwVzJBSVRwUUFxOWgxSAorOW5DUFdXN3ZrQTM3TXYwUFU2S1djd0dMU0hBZW1qYllyZXBsaVY1OW9uVFNocWp6U1lubnlzb2txaWhuTURVCnJEdDI3TXB0cGpXZHR1RUlxdU9vQnBvOG52RndVeHBKK29SdzZtY1JXN1B0UW5KSm52S2U4VzY0U0FHSUtiUjEKdG9TR0NkcElJVW92TEQxN2k4emxZbSsxUTJZMmpXVVRoQ1VUMDh3WE1GWlZqd3BZaWdWeGNxYXQ1NWtNcUw0RwpRZGJXam1Ldm9UMkZMbDVWVCtqOERuRStlbEFhL2plamJVbURVNkRFVVZpYzdMNTM5ZG1ZNjBZVzhxSnkvajNUCkJlbHREK252RUhQTmZEY01UMkoxQks2TVpZQjBSNXpxVmdyY0d4dkJNV3pxeUNTRTczODdpYm1Lb054OTlyV3MKT1dPTlBvRUNnWUVBOGhhbjdoWkxvalpyT3Z3UGtVOTUvckI3YWZHcFdCbkFQcUtLdUFwNTgwd3M1SmJLeXZEdwo2bWlhVFJrcW5SWU93c081ZTV4aU5teXZqVlpoZ245Wml5VGxvZWI4Y3ZkeWFPeGhqMjYxKzI4TXltYkxGcnN3CmptMEJucCswUVdKNERzbHRtT255WG1MTUdjQ2xGTDROWkRFZWZDVmJiNVlhRGNRYTdUN0lIbDhDZ1lFQTZOU00KUjdLNG5wTE0rc1hBOHhjeFVGTkxiTjBZMTVXT1pMVUREcnprVDBDOUtnYWkwd2VlYitxa0tuNUxSeVlNM0lxLwp0ZFBOL3NXb0wwZjFmRlNJcVZEL3lwNmhjWFlTaXhnSmFRZEUvZTV5dWd5M0c0RHJzc1lOMkpDMnFpdFQwOXFECloxL0IzMU9QYXZJa3dYMGF1SGpmUVB0U3hDWnZ6MmVSZ21SeDE4OENnWUJ1YUZqRUk5VHdzUUxzanNLRzBnbGcKVjVxaGNiNTYySnV0dFRHd3g4NWdZSkJrM0VTMmszWThZZUpsWVNIbkxJVWszR0MrZUU3dVpWa1hDNXREQ2RPTAp1eE1qYUpZZjFLeVFINlpLNVFJSUh0aGxnc1lDb3ZKOU1rZTMwVHhEU2FaWmtCSDAyRlZhS0pMTzkrWVI5SzlrCnoyWUkxbnpDQW1IMWYwZU1oY0o4M3dLQmdRQzkvRG9mZ3psY3c4TVpXZVpSTmZxYVplMWsvcUQzd1dTNHptK1oKUmc4eWtFd0xEL0VySzh0ZjNXSnAvallrNzJxTlIzYVp3eVFUSVd4VWNHNWpMb041VGN2N3BTZHRjd0E4bWJlTQpDVStGdVYzS2JQZTVMS0NuZHk3ektWcTBUcmlQWlgzV0MzQWljSWZWcDVMUWcrb2EzeDZsWXE2dHVnT0FoUzFaCjdlWnJSd0tCZ0F0eUdBTlkrektRa285R2lNOU9ISCtIc1ErMCtwRE5PZE5lOE4va3RLR25XSDI0bzJzTzNXWjkKMS84amtKR3MyNnhnUUg1TitQKzZXZXk4dDA5MFhyRHFFSHA1bEUyd0d4eGJSN3kwSTk5NUV2enYyU3d0c2ViUwo2STRLYXpVTTJMblJBbG5IOWdMWDhWaGJBZWIvN2xhQk9KODloQjROZGF2Y1gxZkRjcFd0Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg=="
|
3
|
+
|
4
|
+
# Project settings:
|
5
|
+
language: ruby
|
6
|
+
rvm:
|
7
|
+
- "2.3.0"
|
8
|
+
|
9
|
+
# CI process:
|
10
|
+
script: bundle exec rspec spec
|
11
|
+
|
12
|
+
# Notification settings:
|
13
|
+
notifications:
|
14
|
+
webhooks: https://eetnu.slack.com/services/hooks/travis?token=YC3xwKe1gu65ikh1XOaLrUEh
|
15
|
+
campfire:
|
16
|
+
on_success: change
|
17
|
+
on_failure: always
|
18
|
+
rooms:
|
19
|
+
- "eetnu:bb17e8d4e843938b4b32ee4c1809f2f90b8456ae@316993"
|
data/Gemfile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
source '
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in eet.nu.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
gem 'rake'
|
7
|
+
|
6
8
|
# Support for guard:
|
7
9
|
gem 'guard'
|
8
10
|
gem 'guard-bundler'
|
@@ -10,4 +12,8 @@ gem 'guard-rspec'
|
|
10
12
|
gem 'guard-spork'
|
11
13
|
gem 'rb-fsevent'
|
12
14
|
gem 'rb-readline'
|
15
|
+
|
16
|
+
# RSpec:
|
17
|
+
gem 'rspec'
|
13
18
|
gem 'fuubar'
|
19
|
+
gem 'fakeweb'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hungry (0.0.1)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
childprocess (0.5.9)
|
11
|
+
ffi (~> 1.0, >= 1.0.11)
|
12
|
+
coderay (1.1.1)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
fakeweb (1.3.0)
|
15
|
+
ffi (1.9.10)
|
16
|
+
formatador (0.2.5)
|
17
|
+
fuubar (2.0.0)
|
18
|
+
rspec (~> 3.0)
|
19
|
+
ruby-progressbar (~> 1.4)
|
20
|
+
guard (2.14.0)
|
21
|
+
formatador (>= 0.2.4)
|
22
|
+
listen (>= 2.7, < 4.0)
|
23
|
+
lumberjack (~> 1.0)
|
24
|
+
nenv (~> 0.1)
|
25
|
+
notiffany (~> 0.0)
|
26
|
+
pry (>= 0.9.12)
|
27
|
+
shellany (~> 0.0)
|
28
|
+
thor (>= 0.18.1)
|
29
|
+
guard-bundler (2.1.0)
|
30
|
+
bundler (~> 1.0)
|
31
|
+
guard (~> 2.2)
|
32
|
+
guard-compat (~> 1.1)
|
33
|
+
guard-compat (1.2.1)
|
34
|
+
guard-rspec (4.7.2)
|
35
|
+
guard (~> 2.1)
|
36
|
+
guard-compat (~> 1.1)
|
37
|
+
rspec (>= 2.99.0, < 4.0)
|
38
|
+
guard-spork (2.1.0)
|
39
|
+
childprocess (>= 0.2.3)
|
40
|
+
guard (~> 2.0)
|
41
|
+
guard-compat (~> 1.0)
|
42
|
+
spork (>= 0.8.4)
|
43
|
+
httparty (0.13.7)
|
44
|
+
json (~> 1.8)
|
45
|
+
multi_xml (>= 0.5.2)
|
46
|
+
json (1.8.3)
|
47
|
+
listen (3.1.5)
|
48
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
49
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
50
|
+
ruby_dep (~> 1.2)
|
51
|
+
lumberjack (1.0.10)
|
52
|
+
method_source (0.8.2)
|
53
|
+
multi_xml (0.5.5)
|
54
|
+
nenv (0.3.0)
|
55
|
+
notiffany (0.1.0)
|
56
|
+
nenv (~> 0.1)
|
57
|
+
shellany (~> 0.0)
|
58
|
+
pry (0.10.3)
|
59
|
+
coderay (~> 1.1.0)
|
60
|
+
method_source (~> 0.8.1)
|
61
|
+
slop (~> 3.4)
|
62
|
+
rake (11.2.2)
|
63
|
+
rb-fsevent (0.9.7)
|
64
|
+
rb-inotify (0.9.7)
|
65
|
+
ffi (>= 0.5.0)
|
66
|
+
rb-readline (0.5.3)
|
67
|
+
rspec (3.4.0)
|
68
|
+
rspec-core (~> 3.4.0)
|
69
|
+
rspec-expectations (~> 3.4.0)
|
70
|
+
rspec-mocks (~> 3.4.0)
|
71
|
+
rspec-core (3.4.4)
|
72
|
+
rspec-support (~> 3.4.0)
|
73
|
+
rspec-expectations (3.4.0)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.4.0)
|
76
|
+
rspec-mocks (3.4.1)
|
77
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
+
rspec-support (~> 3.4.0)
|
79
|
+
rspec-support (3.4.1)
|
80
|
+
ruby-progressbar (1.8.1)
|
81
|
+
ruby_dep (1.3.1)
|
82
|
+
shellany (0.0.1)
|
83
|
+
slop (3.6.0)
|
84
|
+
spork (0.9.2)
|
85
|
+
thor (0.19.1)
|
86
|
+
|
87
|
+
PLATFORMS
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
fakeweb
|
92
|
+
fuubar
|
93
|
+
guard
|
94
|
+
guard-bundler
|
95
|
+
guard-rspec
|
96
|
+
guard-spork
|
97
|
+
hungry!
|
98
|
+
rake
|
99
|
+
rb-fsevent
|
100
|
+
rb-readline
|
101
|
+
rspec
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
1.12.5
|
data/Rakefile
CHANGED
@@ -1 +1,15 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
task :console do
|
4
|
+
require 'logger'
|
5
|
+
require 'irb'
|
6
|
+
require 'irb/completion'
|
7
|
+
require_relative './lib/hungry'
|
8
|
+
|
9
|
+
Hungry.logger = Logger.new(STDOUT).tap do |logger|
|
10
|
+
logger.level = Logger::DEBUG
|
11
|
+
end
|
12
|
+
|
13
|
+
ARGV.clear
|
14
|
+
IRB.start
|
15
|
+
end
|
data/hungry.gemspec
CHANGED
@@ -18,9 +18,4 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
# specify any dependencies here:
|
20
20
|
s.add_dependency 'httparty'
|
21
|
-
s.add_dependency 'rack'
|
22
|
-
|
23
|
-
# specify any development dependencies here:
|
24
|
-
s.add_development_dependency 'rspec'
|
25
|
-
s.add_development_dependency 'fakeweb'
|
26
21
|
end
|
data/lib/hungry.rb
CHANGED
@@ -1,30 +1,42 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('..', __FILE__)
|
2
|
-
|
2
|
+
|
3
3
|
require 'support/presence'
|
4
4
|
require 'support/symbolize_keys'
|
5
5
|
|
6
6
|
module Hungry
|
7
|
-
VERSION = '0.0
|
7
|
+
VERSION = '0.1.0'
|
8
8
|
|
9
9
|
class << self
|
10
|
-
attr_accessor :api_url
|
10
|
+
attr_accessor :api_url, :json_parser, :logger
|
11
11
|
end
|
12
12
|
|
13
|
-
self.api_url
|
13
|
+
self.api_url = 'https://api.eet.nu/'
|
14
|
+
self.json_parser = lambda do |json|
|
15
|
+
require 'json'
|
16
|
+
JSON.parse(json)
|
17
|
+
end
|
14
18
|
|
15
19
|
### LIBRARY:
|
16
20
|
|
17
|
-
|
21
|
+
# Utility:
|
18
22
|
autoload :Collection, 'hungry/collection'
|
19
|
-
autoload :
|
23
|
+
autoload :Resource, 'hungry/resource'
|
24
|
+
autoload :Util, 'hungry/util'
|
25
|
+
|
26
|
+
# Helpers:
|
20
27
|
autoload :Geolocation, 'hungry/geolocation'
|
21
28
|
autoload :Location, 'hungry/location'
|
29
|
+
|
30
|
+
# Models:
|
31
|
+
autoload :City, 'hungry/city'
|
32
|
+
autoload :Country, 'hungry/country'
|
33
|
+
autoload :Menu, 'hungry/menu'
|
22
34
|
autoload :Region, 'hungry/region'
|
23
|
-
autoload :Resource, 'hungry/resource'
|
24
35
|
autoload :Review, 'hungry/review'
|
36
|
+
autoload :Response, 'hungry/response'
|
25
37
|
autoload :Site, 'hungry/site'
|
26
38
|
autoload :Tag, 'hungry/tag'
|
27
|
-
autoload :
|
39
|
+
autoload :User, 'hungry/user'
|
28
40
|
autoload :Venue, 'hungry/venue'
|
29
41
|
|
30
42
|
### EXCEPTIONS:
|
data/lib/hungry/collection.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'cgi'
|
1
|
+
require 'httparty' unless defined? HTTParty
|
3
2
|
|
4
3
|
module Hungry
|
5
4
|
class Collection
|
@@ -13,7 +12,6 @@ module Hungry
|
|
13
12
|
### CLASS METHODS:
|
14
13
|
|
15
14
|
def self.get(*args)
|
16
|
-
puts "[Collection]: GET #{args.map(&:inspect).join(', ')}"
|
17
15
|
self.base_uri Hungry.api_url
|
18
16
|
super
|
19
17
|
end
|
@@ -37,28 +35,64 @@ module Hungry
|
|
37
35
|
self.class.new(klass, endpoint, criteria.merge(new_criteria))
|
38
36
|
end
|
39
37
|
|
38
|
+
def [](index)
|
39
|
+
build_resource results[index]
|
40
|
+
end
|
41
|
+
|
42
|
+
def first(n = 1)
|
43
|
+
if n == 1 && (value = results.first)
|
44
|
+
build_resource value
|
45
|
+
elsif n > 1
|
46
|
+
results.first(n).map do |result|
|
47
|
+
build_resource result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
def count(*args)
|
41
53
|
if args.present?
|
42
54
|
super
|
43
55
|
else
|
44
|
-
|
56
|
+
results.count
|
45
57
|
end
|
46
58
|
end
|
47
59
|
|
48
60
|
def each(&block)
|
49
|
-
|
50
|
-
yield
|
61
|
+
results.each do |result|
|
62
|
+
yield build_resource(result)
|
51
63
|
end
|
52
64
|
end
|
53
65
|
|
54
|
-
|
66
|
+
def results
|
67
|
+
@results ||= json['results']
|
68
|
+
end
|
69
|
+
|
70
|
+
def results=(results)
|
71
|
+
@results = results
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def build_resource(result)
|
77
|
+
resource = klass.new(result)
|
78
|
+
resource.data_source = data_source
|
79
|
+
resource
|
80
|
+
end
|
81
|
+
|
82
|
+
def data_source
|
83
|
+
Util.uri_with_params(endpoint, criteria)
|
84
|
+
end
|
85
|
+
|
86
|
+
def json
|
87
|
+
@json ||= Util.parse_json(response.body)
|
88
|
+
end
|
55
89
|
|
56
90
|
def response
|
57
91
|
raise NoEndpointSpecified unless endpoint
|
58
92
|
|
59
93
|
@response ||= begin
|
60
|
-
|
61
|
-
self.class.get
|
94
|
+
Util.log "GET: #{data_source}"
|
95
|
+
self.class.get data_source
|
62
96
|
end
|
63
97
|
end
|
64
98
|
end
|
@@ -7,6 +7,23 @@ module Hungry
|
|
7
7
|
all options.merge(page: page)
|
8
8
|
end
|
9
9
|
|
10
|
+
def first(n = 1)
|
11
|
+
scope = all(per_page: n, page: 1)
|
12
|
+
results = scope.results
|
13
|
+
|
14
|
+
if n == 1 && (value = results.first)
|
15
|
+
resource = klass.new results.first
|
16
|
+
resource.data_source = scope.data_source
|
17
|
+
resource
|
18
|
+
elsif n > 1
|
19
|
+
results.first(n).map do |result|
|
20
|
+
resource = klass.new result
|
21
|
+
resource.data_source = scope.data_source
|
22
|
+
resource
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
10
27
|
def paginated?
|
11
28
|
pagination.present?
|
12
29
|
end
|
data/lib/hungry/geolocation.rb
CHANGED
@@ -27,8 +27,8 @@ module Hungry
|
|
27
27
|
#
|
28
28
|
# input is a String, so we can use a regular expression to extract
|
29
29
|
# latitude and longitude:
|
30
|
-
if match = input.match(/^(
|
31
|
-
coordinates = [match[
|
30
|
+
if match = input.match(/^([0-9\.]+),\s?([0-9\.]+)$/)
|
31
|
+
coordinates = [match[1], match[2]]
|
32
32
|
end
|
33
33
|
|
34
34
|
elsif input.respond_to?(:keys)
|
@@ -59,5 +59,25 @@ module Hungry
|
|
59
59
|
def to_s
|
60
60
|
[latitude, longitude].join(',')
|
61
61
|
end
|
62
|
+
|
63
|
+
def [](key)
|
64
|
+
to_h.send(:[], key)
|
65
|
+
end
|
66
|
+
|
67
|
+
def []=(key, value)
|
68
|
+
case key.to_sym
|
69
|
+
when :latitude
|
70
|
+
self.latitude = value.to_f
|
71
|
+
when :longitude
|
72
|
+
self.longitude = value.to_f
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_h
|
77
|
+
{
|
78
|
+
latitude: latitude,
|
79
|
+
longitude: longitude
|
80
|
+
}
|
81
|
+
end
|
62
82
|
end
|
63
83
|
end
|
data/lib/hungry/location.rb
CHANGED
@@ -3,6 +3,14 @@ module Hungry
|
|
3
3
|
|
4
4
|
self.endpoint = '/locations'
|
5
5
|
|
6
|
+
### RESOURCES:
|
7
|
+
|
8
|
+
has_many :venues, 'Hungry::Venue'
|
9
|
+
|
10
|
+
has_many :nearby_venues, 'Hungry::Venue'
|
11
|
+
|
12
|
+
has_many :tags, 'Hungry::Tag'
|
13
|
+
|
6
14
|
### ATTRIBUTES:
|
7
15
|
|
8
16
|
### Location:
|
@@ -11,13 +19,10 @@ module Hungry
|
|
11
19
|
### Utility:
|
12
20
|
:resources, :counters
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
has_many :tags, Tag
|
21
|
-
|
22
|
+
def geolocation=(new_coordinates)
|
23
|
+
@geolocation = Geolocation.parse(new_coordinates).tap do |geo|
|
24
|
+
attributes[:geolocation] = geo
|
25
|
+
end
|
26
|
+
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/hungry/menu.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Hungry
|
2
|
+
class Menu < Resource
|
3
|
+
autoload :Category, 'hungry/menu/category'
|
4
|
+
autoload :Dish, 'hungry/menu/dish'
|
5
|
+
autoload :Option, 'hungry/menu/option'
|
6
|
+
|
7
|
+
self.endpoint = '/menus'
|
8
|
+
|
9
|
+
### RESOURCES:
|
10
|
+
|
11
|
+
belongs_to :venue, 'Hungry::Venue'
|
12
|
+
|
13
|
+
### ATTRIBUTES:
|
14
|
+
|
15
|
+
### Menu:
|
16
|
+
attr_accessor :id, :name, :type, :attachment,
|
17
|
+
|
18
|
+
### Associations:
|
19
|
+
:categories, :venue,
|
20
|
+
|
21
|
+
### Utility:
|
22
|
+
:created_at, :updated_at
|
23
|
+
|
24
|
+
lazy_load :venue
|
25
|
+
|
26
|
+
def managed?
|
27
|
+
type == 'managed' || categories.present?
|
28
|
+
end
|
29
|
+
|
30
|
+
def download?
|
31
|
+
type == 'download'
|
32
|
+
end
|
33
|
+
|
34
|
+
def venue=(venue_attributes)
|
35
|
+
@venue = Hungry::Venue.new(venue_attributes)
|
36
|
+
end
|
37
|
+
|
38
|
+
def categories
|
39
|
+
@categories ||= []
|
40
|
+
end
|
41
|
+
lazy_load :categories
|
42
|
+
|
43
|
+
def categories=(new_categories)
|
44
|
+
@categories = new_categories.map do |attributes|
|
45
|
+
category = Menu::Category.new(attributes)
|
46
|
+
category.menu = self
|
47
|
+
category.data_source = data_source
|
48
|
+
category
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|