zomato2 0.2.0
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.
- checksums.yaml +7 -0
- data/.gitignore +26 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +68 -0
- data/Guardfile +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +67 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/zomato2.rb +12 -0
- data/lib/zomato2/category.rb +23 -0
- data/lib/zomato2/city.rb +57 -0
- data/lib/zomato2/collection.rb +28 -0
- data/lib/zomato2/cuisine.rb +22 -0
- data/lib/zomato2/entity_base.rb +26 -0
- data/lib/zomato2/establishment.rb +28 -0
- data/lib/zomato2/location.rb +27 -0
- data/lib/zomato2/menu.rb +21 -0
- data/lib/zomato2/restaurant.rb +88 -0
- data/lib/zomato2/review.rb +24 -0
- data/lib/zomato2/user.rb +21 -0
- data/lib/zomato2/version.rb +3 -0
- data/lib/zomato2/zomato.rb +96 -0
- data/rubyscopes.rb +24 -0
- data/zomato2.gemspec +38 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5aea62bca87eca373c1508f15052675dbdd2dcf
|
4
|
+
data.tar.gz: bad8c3b61df6676c4b4c6a1352c59d108f75a89d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 992914bbea8db022075cbf6a9d490830faa5cf2d91228b75566938b4c0b245b7a40a50b2a051a95763fbf958a3e127347275ef99494016473b2d2050bdea4a21
|
7
|
+
data.tar.gz: d650d28c0536ca728d77f0b5a9ba38dbdbf102dedf3d60e92d02516da8b7f1ef036b8fc095b56fb4bc7ee43dd5d6c1f9c0babf63bca6fafd3ffdf2944224fdc9
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/lib/ttt.rb
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/spec/examples.txt
|
10
|
+
/test/tmp/
|
11
|
+
/test/version_tmp/
|
12
|
+
/tmp/
|
13
|
+
|
14
|
+
## Documentation cache and generated files:
|
15
|
+
/.yardoc/
|
16
|
+
/_yardoc/
|
17
|
+
/doc/
|
18
|
+
/rdoc/
|
19
|
+
|
20
|
+
## Environment normalization:
|
21
|
+
/.bundle/
|
22
|
+
/vendor/bundle
|
23
|
+
/lib/bundler/man/
|
24
|
+
|
25
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
26
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zomato2 (0.1.0)
|
5
|
+
faraday
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.0)
|
11
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
dotenv (2.1.1)
|
16
|
+
faraday (0.11.0)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
ffi (1.9.17)
|
19
|
+
growl (1.0.3)
|
20
|
+
hashdiff (0.3.2)
|
21
|
+
libnotify (0.9.1)
|
22
|
+
ffi (>= 1.0.11)
|
23
|
+
multipart-post (2.0.0)
|
24
|
+
public_suffix (2.0.5)
|
25
|
+
rake (10.5.0)
|
26
|
+
rb-inotify (0.9.7)
|
27
|
+
ffi (>= 0.5.0)
|
28
|
+
rspec (3.5.0)
|
29
|
+
rspec-core (~> 3.5.0)
|
30
|
+
rspec-expectations (~> 3.5.0)
|
31
|
+
rspec-mocks (~> 3.5.0)
|
32
|
+
rspec-core (3.5.4)
|
33
|
+
rspec-support (~> 3.5.0)
|
34
|
+
rspec-expectations (3.5.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.5.0)
|
37
|
+
rspec-mocks (3.5.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.5.0)
|
40
|
+
rspec-support (3.5.0)
|
41
|
+
safe_yaml (1.0.4)
|
42
|
+
terminal-notifier (1.7.1)
|
43
|
+
terminal-notifier-guard (1.7.0)
|
44
|
+
vcr (3.0.3)
|
45
|
+
webmock (2.3.2)
|
46
|
+
addressable (>= 2.3.6)
|
47
|
+
crack (>= 0.3.2)
|
48
|
+
hashdiff
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler
|
55
|
+
dotenv
|
56
|
+
growl
|
57
|
+
libnotify
|
58
|
+
rake (~> 10.0)
|
59
|
+
rb-inotify (~> 0.9)
|
60
|
+
rspec
|
61
|
+
terminal-notifier
|
62
|
+
terminal-notifier-guard
|
63
|
+
vcr
|
64
|
+
webmock
|
65
|
+
zomato2!
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.13.1
|
data/Guardfile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Rails files
|
44
|
+
end
|
45
|
+
|
46
|
+
guard :spork, :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
|
47
|
+
watch('Gemfile.lock')
|
48
|
+
watch('spec/spec_helper.rb') { :rspec }
|
49
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Rony Varghese
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Zomato2
|
2
|
+
|
3
|
+
This is a simple and clean wrapper for the API version 2.1 of Zomato / Urbanspoon.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this gem to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'zomato2'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install directly with:
|
18
|
+
|
19
|
+
$ gem install zomato2
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```Ruby
|
24
|
+
require 'zomato2'
|
25
|
+
|
26
|
+
apikey='cc7e50701a25647e613ce48642ec0159'
|
27
|
+
zomato = Zomato2::Zomato.new(apikey)
|
28
|
+
|
29
|
+
puts zomato.restaurants #.each { |r| puts r.details.reviews }
|
30
|
+
|
31
|
+
zomato.cities({q: 'new'}).each do |c|
|
32
|
+
c.restaurants.each { |r| puts r.details }
|
33
|
+
end
|
34
|
+
|
35
|
+
nyc = zomato.cities(q: "New York City, NY")[0]
|
36
|
+
|
37
|
+
american_nyc = nyc.cuisines.find {|c| c.name == 'American'}
|
38
|
+
|
39
|
+
top_trending_nyc = nyc.collections[0]
|
40
|
+
|
41
|
+
fine_dining_nyc = nyc.establishments.find {|e| e.name == 'Fine Dining' }
|
42
|
+
|
43
|
+
american_rests_in_nyc = american_nyc.restaurants
|
44
|
+
|
45
|
+
american_rests_in_nyc.find_all {|r| r.name =~ /Joe/ } .each { |r| puts r.menu }
|
46
|
+
|
47
|
+
some_rests1 = zomato.restaurants establishment_type: fine_dining_nyc.id, start:10, count: 5
|
48
|
+
|
49
|
+
some_rests2 = zomato.restaurants q: 'Lisboa'
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
67
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zomato2"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/zomato2.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/version.rb')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/entity_base.rb')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/zomato.rb')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/city.rb')
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/collection.rb')
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/category.rb')
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/cuisine.rb')
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/establishment.rb')
|
9
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/location.rb')
|
10
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/menu.rb')
|
11
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/restaurant.rb')
|
12
|
+
require File.expand_path(File.dirname(__FILE__) + '/zomato2/review.rb')
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Category < EntityBase
|
3
|
+
|
4
|
+
attr_reader :id, :name
|
5
|
+
|
6
|
+
def initialize(zom_conn, attributes)
|
7
|
+
super(zom_conn)
|
8
|
+
@id = attributes['id']
|
9
|
+
@name = attributes['name']
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s; super; end
|
13
|
+
|
14
|
+
def restaurants(start: nil, count: nil)
|
15
|
+
q = {category_id: @id }
|
16
|
+
q[:start] = start if start
|
17
|
+
q[:count] = count if count
|
18
|
+
results = get('search', q)
|
19
|
+
results['restaurants'].map { |e| Restaurant.new(@zom_conn, e['restaurant']) }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/zomato2/city.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class City < EntityBase
|
3
|
+
|
4
|
+
attr_reader :id, :name, :country_id, :country_name, :is_state, :state_id,
|
5
|
+
:state_name, :state_code, :discovery_enabled, :has_new_ad_format
|
6
|
+
|
7
|
+
def initialize(zom_conn, attributes)
|
8
|
+
super(zom_conn)
|
9
|
+
@id = attributes['id']
|
10
|
+
@name = attributes['name']
|
11
|
+
@country_id = attributes['country_id']
|
12
|
+
@country_name = attributes['country_name']
|
13
|
+
@is_state = attributes['is_state'] != 0
|
14
|
+
@state_id = attributes['state_id']
|
15
|
+
@state_name = attributes['state_name']
|
16
|
+
@state_code = attributes['state_code']
|
17
|
+
@discovery_enabled = attributes['discovery_enabled']
|
18
|
+
@has_new_ad_format = attributes['has_new_ad_format']
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s; super; end
|
22
|
+
|
23
|
+
def collections(start: nil, count: nil)
|
24
|
+
q = {city_id: @id }
|
25
|
+
q[:start] = start if start
|
26
|
+
q[:count] = count if count
|
27
|
+
results = get('collections', q)
|
28
|
+
results['collections'].map { |c| Collection.new(@zom_conn, @id, c['collection']) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def establishments(start: nil, count: nil)
|
32
|
+
q = {city_id: @id }
|
33
|
+
q[:start] = start if start
|
34
|
+
q[:count] = count if count
|
35
|
+
results = get('establishments', q)
|
36
|
+
results['establishments'].map { |e| Establishment.new(@zom_conn, @id, e['establishment']) }
|
37
|
+
end
|
38
|
+
|
39
|
+
# alias :super_get :get
|
40
|
+
def cuisines(start: nil, count: nil)
|
41
|
+
q = {city_id: @id }
|
42
|
+
q[:start] = start if start
|
43
|
+
q[:count] = count if count
|
44
|
+
results = get('cuisines', q)
|
45
|
+
results['cuisines'].map { |c| Cuisine.new(@zom_conn, @id, c['cuisine']) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def restaurants(start: nil, count: nil)
|
49
|
+
q = {entity_type: 'city', entity_id: @id } # entity_id == city_id
|
50
|
+
q[:start] = start if start
|
51
|
+
q[:count] = count if count
|
52
|
+
results = get('search', q)
|
53
|
+
results['restaurants'].map { |e| Restaurant.new(@zom_conn, e['restaurant']) }
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Collection < EntityBase
|
3
|
+
|
4
|
+
attr_reader :city_id, :id, :title, :url, :description, :image_url, :res_count, :share_url
|
5
|
+
|
6
|
+
def initialize(zom_conn, cityid, attributes)
|
7
|
+
super(zom_conn)
|
8
|
+
@city_id = cityid
|
9
|
+
@id = attributes['collection_id']
|
10
|
+
@url = attributes['url']
|
11
|
+
@title = attributes['title']
|
12
|
+
@description = attributes['description']
|
13
|
+
@image_url = attributes['image_url']
|
14
|
+
@res_count = attributes['res_count']
|
15
|
+
@share_url = attributes['share_url']
|
16
|
+
end
|
17
|
+
|
18
|
+
def restaurants(start: nil, count: nil)
|
19
|
+
q = {collection_id: @id, entity_type: 'city', entity_id: @city_id }
|
20
|
+
q[:start] = start if start
|
21
|
+
q[:count] = count if count
|
22
|
+
results = get('search', q)
|
23
|
+
results['restaurants'].map { |e| Restaurant.new(@zom_conn, e['restaurant']) }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Cuisine < EntityBase
|
3
|
+
|
4
|
+
attr_reader :city_id, :id, :name
|
5
|
+
|
6
|
+
def initialize(zom_conn, cityid, attributes)
|
7
|
+
super(zom_conn)
|
8
|
+
@city_id = cityid
|
9
|
+
@id = attributes['cuisine_id']
|
10
|
+
@name = attributes['cuisine_name']
|
11
|
+
end
|
12
|
+
|
13
|
+
def restaurants(start: nil, count: nil)
|
14
|
+
q = {cuisines: @id, entity_type: 'city', entity_id: @city_id }
|
15
|
+
q[:start] = start if start
|
16
|
+
q[:count] = count if count
|
17
|
+
results = get('search', q)
|
18
|
+
results['restaurants'].map { |e| Restaurant.new(@zom_conn, e['restaurant']) }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class EntityBase
|
3
|
+
|
4
|
+
def initialize(zomato_conn)
|
5
|
+
@zom_conn = zomato_conn
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(endpoint, params)
|
9
|
+
@zom_conn.get(endpoint, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
#self.inspect
|
14
|
+
vals = self.instance_variables.map do |att|
|
15
|
+
next nil if att === :@zom_conn
|
16
|
+
attstr = att.to_s.sub('@','')
|
17
|
+
attstr+": #{self.instance_variable_get(att)}"
|
18
|
+
end
|
19
|
+
|
20
|
+
classname = self.class.name.sub(/.*:/,'')
|
21
|
+
fields = vals.compact.join ', '
|
22
|
+
"#{classname}: { #{fields} }"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Zomato2
|
2
|
+
|
3
|
+
# Restaurant types
|
4
|
+
class Establishment < EntityBase
|
5
|
+
attr_reader :city_id, :id, :name
|
6
|
+
|
7
|
+
def initialize(zom_conn, cityid, attributes)
|
8
|
+
super(zom_conn)
|
9
|
+
@city_id = cityid
|
10
|
+
@id = attributes['id']
|
11
|
+
@name = attributes['name']
|
12
|
+
end
|
13
|
+
|
14
|
+
def restaurants(start: nil, count: nil)
|
15
|
+
q = {establishment_id: @id, entity_type: 'city', entity_id: @city_id }
|
16
|
+
q[:start] = start if start
|
17
|
+
q[:count] = count if count
|
18
|
+
results = get('search', q)
|
19
|
+
results['restaurants'].map do |e|
|
20
|
+
r = Restaurant.new(@zom_conn, e['restaurant'])
|
21
|
+
r.establishments = Array.new
|
22
|
+
r.establishments << self
|
23
|
+
r
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Location < EntityBase
|
3
|
+
|
4
|
+
attr_reader :address, :locality, :city_name, :latitude, :longitude, :zipcode, :country_id, # basic attrs
|
5
|
+
:country_name, :city_id, :title, :entity_type, :entity_id # detailed
|
6
|
+
|
7
|
+
# Zomato uses different names for the same field depending on the request..
|
8
|
+
def initialize(zom_conn, attributes)
|
9
|
+
super(zom_conn)
|
10
|
+
@address = attributes['address']
|
11
|
+
@locality = attributes['locality']
|
12
|
+
@city_name = attributes['city'] || attributes['city_name']
|
13
|
+
@city_id = attributes['city_id']
|
14
|
+
@latitude = attributes['latitude'] || attributes['lat']
|
15
|
+
@longitude = attributes['longitude'] || attributes['lon']
|
16
|
+
@zipcode = attributes['zipcode']
|
17
|
+
@country_id = attributes['country_id']
|
18
|
+
@country_name = attributes['country_name']
|
19
|
+
@title = attributes['title']
|
20
|
+
@entity_type = attributes['entity_type']
|
21
|
+
@entity_id = attributes['entity_id']
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s; super; end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/zomato2/menu.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Menu < EntityBase
|
3
|
+
|
4
|
+
attr_reader :daily_menu_id, :name, :start_date, :end_date, :dishes
|
5
|
+
|
6
|
+
def initialize(zom_conn, attributes)
|
7
|
+
super(zom_conn)
|
8
|
+
self.instance_variables.each do |att|
|
9
|
+
if att === :@zom_conn
|
10
|
+
next
|
11
|
+
else
|
12
|
+
self.instance_variable_set attributes[att]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s; super; end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Restaurant < EntityBase
|
3
|
+
|
4
|
+
attr_reader :id, :name, :location, :average_cost_for_two, :price_range, :currency, :thumb, :featured_image,
|
5
|
+
:photos_url, :menu_url, :events_url, :user_rating, :has_online_delivery, :is_delivering_now,
|
6
|
+
:has_table_booking, :deeplink, :cuisines, :all_reviews_count, :photo_count,
|
7
|
+
:phone_numbers, :photos, :city_id
|
8
|
+
attr_accessor :reviews, :establishments
|
9
|
+
|
10
|
+
def initialize(zom_conn, attributes)
|
11
|
+
super(zom_conn)
|
12
|
+
@location = Location.new zom_conn, attributes["location"]
|
13
|
+
@city_id = @location.city_id
|
14
|
+
|
15
|
+
attributes.each do |k,v|
|
16
|
+
if k == 'apikey'
|
17
|
+
next
|
18
|
+
elsif k == 'R'
|
19
|
+
@id = v['res_id']
|
20
|
+
# Zomato never returns this?? bad API doc!
|
21
|
+
elsif k == 'location'
|
22
|
+
next
|
23
|
+
elsif k == 'all_reviews'
|
24
|
+
@reviews = v.map{ |r| Review.new(zom_conn, r) }
|
25
|
+
elsif k == 'establishment_types'
|
26
|
+
@establishments = v.map{ |e,ev| Establishment.new(zom_conn, @city_id, ev) }
|
27
|
+
# elsif k == 'cuisines' the returned cuisines here are just a string..
|
28
|
+
else
|
29
|
+
#puts "ATTR @#{k} val #{v}"
|
30
|
+
self.instance_variable_set("@#{k}", v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s; super; end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
@id == other.id and @name == other.name and @city_id == other.city_id # ...
|
39
|
+
end
|
40
|
+
|
41
|
+
def <=>(other)
|
42
|
+
@id <=> other.id
|
43
|
+
end
|
44
|
+
|
45
|
+
def menu(start: nil, count: nil)
|
46
|
+
q = {res_id: @id }
|
47
|
+
q[:start] = start if start
|
48
|
+
q[:count] = count if count
|
49
|
+
results = get('dailymenu', q)
|
50
|
+
return nil if results['message'] == "No Daily Menu Available"
|
51
|
+
results['daily_menu'].map { |e| Menu.new(@zom_conn, @id, e['daily_menu']) }
|
52
|
+
end
|
53
|
+
|
54
|
+
# this doesn't actually give any more detailed info..
|
55
|
+
def details(start: nil, count: nil)
|
56
|
+
# warn "\tRestaurant#details: This method is currently useless, since, " +
|
57
|
+
# "as of January 2017, Zomato's API doesn't give any additional info here."
|
58
|
+
|
59
|
+
q = {res_id: @id }
|
60
|
+
q[:start] = start if start
|
61
|
+
q[:count] = count if count
|
62
|
+
results = get('restaurant', q)
|
63
|
+
|
64
|
+
@location ||= Location.new zom_conn, attributes["location"]
|
65
|
+
@city_id ||= @location.city_id
|
66
|
+
|
67
|
+
results.each do |k,v|
|
68
|
+
if k == 'apikey'
|
69
|
+
next
|
70
|
+
elsif k == 'R'
|
71
|
+
@id = v['res_id']
|
72
|
+
# Zomato never returns this?? bad API doc!
|
73
|
+
elsif k == 'location'
|
74
|
+
next
|
75
|
+
elsif k == 'all_reviews'
|
76
|
+
@reviews ||= v.map{ |r| Review.new(zom_conn, r) }
|
77
|
+
elsif k == 'establishment_types'
|
78
|
+
@establishments ||= v.map{ |e,ev| Establishment.new(zom_conn, @city_id, ev) }
|
79
|
+
# elsif k == 'cuisines' the returned cuisines here are just a string..
|
80
|
+
else
|
81
|
+
#puts "ATTR @#{k} val #{v}"
|
82
|
+
self.instance_variable_set("@#{k}", v)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
self
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class Review < EntityBase
|
3
|
+
|
4
|
+
attr_reader :id, :rating, :review_text, :rating_color, :review_time_friendly,
|
5
|
+
:rating_text, :timestamp, :likes, :comments_count, :user
|
6
|
+
|
7
|
+
def initialize(zom_conn, attributes)
|
8
|
+
super(zom_conn)
|
9
|
+
|
10
|
+
self.instance_variables.each do |att|
|
11
|
+
if att === :@zom_conn
|
12
|
+
next
|
13
|
+
elsif att === :@user
|
14
|
+
@user = User.new zom_conn, attributes['user']
|
15
|
+
else
|
16
|
+
self.instance_variable_set attributes[att]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s; super; end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/zomato2/user.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Zomato2
|
2
|
+
class User < EntityBase
|
3
|
+
|
4
|
+
attr_reader :zomato_handle, :foodie_level, :foodie_level_num, :foodie_color,
|
5
|
+
:name, :profile_url, :profile_deeplink, :profile_image
|
6
|
+
|
7
|
+
def initialize(zom_conn, attributes)
|
8
|
+
super(zom_conn)
|
9
|
+
self.instance_variables.each do |att|
|
10
|
+
if att === :@zom_conn
|
11
|
+
next
|
12
|
+
else
|
13
|
+
self.instance_variable_set attributes[att]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s; super; end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Zomato2
|
5
|
+
|
6
|
+
class Zomato
|
7
|
+
|
8
|
+
def initialize(z_api_key)
|
9
|
+
@api_key = z_api_key
|
10
|
+
@headers = {'Accept' => 'application/json', 'user-key' => @api_key}
|
11
|
+
@base_uri = 'https://developers.zomato.com/api/v2.1/'
|
12
|
+
@conn = Faraday.new url: "#{@base_uri}", headers: @headers
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(endpoint, params)
|
16
|
+
query = params.map{ |k,v| "&#{k}=#{v}" }.join ''
|
17
|
+
requrl = "#{endpoint}?#{query}"
|
18
|
+
resp = @conn.get(requrl)
|
19
|
+
results = JSON.parse(resp.body)
|
20
|
+
results
|
21
|
+
end
|
22
|
+
|
23
|
+
def cities(params)
|
24
|
+
if params.class != Hash or params.keys.length == 0
|
25
|
+
warn 'This endpoint requires at least 1 param: "q" search, "lat"/"lot" or "city_id"'
|
26
|
+
end
|
27
|
+
|
28
|
+
results = get('cities', params)
|
29
|
+
|
30
|
+
# {"location_suggestions" => Array, "status"=>"success", "has_more"=>0, "has_total"=>0}
|
31
|
+
if results.key?("location_suggestions")
|
32
|
+
results["location_suggestions"].map { |c| City.new(self, c) }
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def categories()
|
39
|
+
results = get('categories', {})
|
40
|
+
results['categories'].map { |e| Category.new(self, e['categories']) }
|
41
|
+
end
|
42
|
+
|
43
|
+
# search for locations
|
44
|
+
def locations(params={})
|
45
|
+
args = [ :query, :lat, :lon, :count ]
|
46
|
+
params.each do |k,v|
|
47
|
+
if !args.include?(k)
|
48
|
+
raise ArgumentError.new 'Search term not allowed: ' + k.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if !params.include?(:query)
|
53
|
+
raise ArgumentError.new '"query" term with location name is required'
|
54
|
+
end
|
55
|
+
|
56
|
+
results = get('locations', params)
|
57
|
+
if results.key?("location_suggestions")
|
58
|
+
results["location_suggestions"].map { |l| Location.new(self, l) }
|
59
|
+
else
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# general search for restaurants
|
65
|
+
def restaurants(params={})
|
66
|
+
args = [ :entity_id, :entity_type, # location
|
67
|
+
:q, :start, :count, :lat, :lon,
|
68
|
+
:radius, :cuisines, :establishment_type,
|
69
|
+
:collection_id, :category, :sort, :order,
|
70
|
+
:start, :count ]
|
71
|
+
|
72
|
+
params.each do |k,v|
|
73
|
+
if !args.include?(k)
|
74
|
+
raise ArgumentError.new 'Search term not allowed: ' + k.to_s
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if params[:count] && params[:count].to_i > 20
|
79
|
+
warn 'Count maxes out at 20'
|
80
|
+
end
|
81
|
+
|
82
|
+
# these filters are already city-specific
|
83
|
+
has_sub_city = params[:establishment_type] || params[:collection_id] || params[:cuisines]
|
84
|
+
|
85
|
+
if (has_sub_city && params[:q]) ||
|
86
|
+
(has_sub_city && params[:entity_type] == 'city') ||
|
87
|
+
(params[:q] && params[:entity_type] == 'city')
|
88
|
+
warn 'More than 2 different kinds of City searches cannot be combined'
|
89
|
+
end
|
90
|
+
|
91
|
+
results = get('search', params)
|
92
|
+
results['restaurants'].map { |e| Restaurant.new(self, e['restaurant']) }
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
data/rubyscopes.rb
ADDED
data/zomato2.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zomato2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'zomato2'
|
8
|
+
spec.version = Zomato2::VERSION
|
9
|
+
spec.authors = ['Miguel Ferreira']
|
10
|
+
spec.email = ['eligmu@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Access the latest Zomato API 2.1}
|
13
|
+
spec.description = %q{Client library for Zomato API 2.1}
|
14
|
+
spec.homepage = "https://github.com/miguelzf/zomato2"
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'faraday', '~> 0.11.0'
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
34
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
35
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
36
|
+
spec.add_development_dependency 'dotenv', '~> 2.1'
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zomato2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miguel Ferreira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.11.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.11.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.1'
|
111
|
+
description: Client library for Zomato API 2.1
|
112
|
+
email:
|
113
|
+
- eligmu@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- Guardfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- lib/zomato2.rb
|
128
|
+
- lib/zomato2/category.rb
|
129
|
+
- lib/zomato2/city.rb
|
130
|
+
- lib/zomato2/collection.rb
|
131
|
+
- lib/zomato2/cuisine.rb
|
132
|
+
- lib/zomato2/entity_base.rb
|
133
|
+
- lib/zomato2/establishment.rb
|
134
|
+
- lib/zomato2/location.rb
|
135
|
+
- lib/zomato2/menu.rb
|
136
|
+
- lib/zomato2/restaurant.rb
|
137
|
+
- lib/zomato2/review.rb
|
138
|
+
- lib/zomato2/user.rb
|
139
|
+
- lib/zomato2/version.rb
|
140
|
+
- lib/zomato2/zomato.rb
|
141
|
+
- rubyscopes.rb
|
142
|
+
- zomato2.gemspec
|
143
|
+
homepage: https://github.com/miguelzf/zomato2
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.6.6
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Access the latest Zomato API 2.1
|
167
|
+
test_files: []
|