class Romato::Zomato

Attributes

categories[RW]

assign the variable to be accessed through dot notation

cities[RW]

assign the variable to be accessed through dot notation

collections[RW]

assign the variable to be accessed through dot notation

cuisines[RW]

assign the variable to be accessed through dot notation

daily_menu[RW]

assign the variable to be accessed through dot notation

establishments[RW]

assign the variable to be accessed through dot notation

geocode[RW]

assign the variable to be accessed through dot notation

location_details[RW]

assign the variable to be accessed through dot notation

locations[RW]

assign the variable to be accessed through dot notation

restaurant[RW]

assign the variable to be accessed through dot notation

reviews[RW]

assign the variable to be accessed through dot notation

Public Class Methods

new(api_key) click to toggle source

initializes provided api_key headers and base uri should not change

# File lib/romato.rb, line 14
def initialize(api_key)
        @api_key = api_key
        @headers = {"Accept" => "application/JSON", "user-key" => @api_key}
        @base_uri = "https://developers.zomato.com/api/v2.1/"
end

Public Instance Methods

get_categories() click to toggle source

COMMON Category returns a list of categories (food categories) developers.zomato.com/documentation#!/common/categories

# File lib/romato.rb, line 23
def get_categories()
        zomoato_categories_url = @base_uri + "categories"
        response = HTTParty.get(zomoato_categories_url, headers: @headers)
        if response.success?
                @categories = response.parsed_response
        else
                raise response.response
        end
        return @categories
end
get_cities(options) click to toggle source

pass hash to get cities, valid key / value pairs below q = “”seattle, lat = “”, lon = “” , city_ids =“”, count=50 {q: “seattle”, lat: “”, lon: “”, city_ids: “”, count=50 }

# File lib/romato.rb, line 37
def get_cities(options)
        url_base = @base_uri + "cities?" 
        a = options.key?(:q) ? "&q=#{options[:q]}" : ""
        b = options.key?(:lat) ? "&lat=#{options[:lat]}" : ""
        c = options.key?(:lon) ? "&lon=#{options[:lon]}" : ""
        d = options.key?(:city_ids) ? "&city_ids=#{options[:city_ids]}" : ""
        e = options.key?(:count) ? "&count=#{options[:count]}" : ""
        zomato_cities_url = url_base + a + b + c + d + e

        response = HTTParty.get(zomato_cities_url, headers: @headers)
        if response.success?
                @cities = response.parsed_response
        else
                raise response.response
        end
end
get_collections(options) click to toggle source
# File lib/romato.rb, line 54
def get_collections(options)
        url_base = @base_uri + "collections?"
        a = options.key?(:city_id) ? "&city_id=#{options[:city_id]}" : ""
        b = options.key?(:lat) ? "&lat=#{options[:lat]}" : ""
        c = options.key?(:lon) ? "&lon=#{options[:lon]}" : ""
        d = options.key?(:count) ? "&count=#{options[:count]}" : ""
        zomato_collections_url = url_base + a + b + c + d

        response = HTTParty.get(zomato_collections_url, headers: @headers)
        if response.success?
                @collections = response.parsed_response
        else
                raise response.response
        end
end
get_cuisines(options) click to toggle source

returns a hash of cuisines in a particular city or geographic location accepts a hash: options. Required values either {city_id: “279”} or {lat: 32.342, lon: 12.234} utilizes string interpolation, any value will be interpolated to string and passed to the api endpoint as an html argument

# File lib/romato.rb, line 77
def get_cuisines(options)
        url_base = @base_uri + "cuisines?"
        a = options.key?(:city_id) ? "&city_id=#{options[:city_id]}" : ""
        b = options.key?(:lat) ? "&lat=#{options[:lat]}" : ""
        c = options.key?(:lon) ? "&lon=#{options[:lon]}" : ""
        zomato_cuisines_url = url_base + a + b + c

        response = HTTParty.get(zomato_cuisines_url, headers: @headers)
        if response.success?
                @cuisines = response.parsed_response
        else
                raise response.response
        end
end
get_daily_menu(options) click to toggle source

RESTAURANT

accepts options hash as parameters
options example: {res_id: "279"}
# File lib/romato.rb, line 181
def get_daily_menu(options)
        zomato_daily_menu_url = @base_uri +
                "restaurant?res_id=#{options[:res_id]}"
        response = HTTParty.get(zomato_daily_menu_url, headers: @headers)
        if response.success?
                @daily_menu = response.parsed_response
        else
                raise response.response
        end
end
get_establishments(options) click to toggle source

returns a hash of establishment categories in a particular city or geographic location accepts a hash: options. Required values either {city_id: “279”} or {lat: 32.342, lon: 12.234} utilizes string interpolation, any value will be interpolated to string and passed to the api endpoint as an html argument

# File lib/romato.rb, line 100
def get_establishments(options)
        url_base = @base_uri + "establishments?"
        a = options.key?(:city_id) ? "&city_id=#{options[:city_id]}" : ""
        b = options.key?(:lat) ? "&lat=#{options[:lat]}" : ""
        c = options.key?(:lon) ? "&lon=#{options[:lon]}" : ""
        zomato_establishments_url = url_base + a + b + c

        response = HTTParty.get(zomato_establishments_url, headers: @headers)
        if response.success?
                @establishments = response.parsed_response
        else
                raise response.response
        end
end
get_geocode(options) click to toggle source

returns the information to a cooresponding geographical coordinate accepts options hash hash example options: {lat: 24.5344, lon: -12.3423}

# File lib/romato.rb, line 119
def get_geocode(options)
        url_base = @base_uri + "geocode?"
        a = options.key?(:lat) ? "&lat=#{options[:lat]}" : ""
        b = options.key?(:lon) ? "&lon=#{options[:lon]}" : ""
        zomato_geocode_url = url_base + a + b

        response = HTTParty.get(zomato_geocode_url, headers: @headers)
        if response.success?
                @geocode = response.parsed_response
        else
                raise response.response
        end
end
get_location_details(options) click to toggle source

Sets the locations details to @location_details developers.zomato.com/documentation#!/location/location_details options passed as hash, both entity_id and entity_type are required options hash example: {entity_id: “279”, entity_type: “seattle”}

# File lib/romato.rb, line 139
def get_location_details(options)
        zomato_location_details_url = @base_uri + 
                "/location_details?entity_id=#{options[:entity_id]}&entity_type=#{options[:entity_type]}"
        response = HTTParty.get(zomato_location_details_url, headers: @headers)
        if response.success?
                @location_details = response.parsed_response
        else
                raise response.response
        end
end
get_locations(options) click to toggle source

sets location guesses based on the query to @locations query and latitude/longitude are required hash returned can be viewed in Zomato documentation developers.zomato.com/documentation#!/location/locations options passed as a hash options hash example: {query: “seattle”, lat: “47.6906021”, lon}

# File lib/romato.rb, line 156
def get_locations(options)    
        url_base = @base_uri + "locations?"
        a = options.has_key?(:query) ? "&query=#{options[:query]}" : ""
        b = options.has_key?(:lat) ? "&lat=#{options[:lat]}" : ""
        c = options.has_key?(:lon) ? "&lon=#{options[:lon]}" : ""
        d = options.has_key?(:count) ? "&count=#{options[:count]}" : ""
        zomato_locations_url = url_base + a + b + c + d

        response = HTTParty.get(zomato_locations_url, headers: @headers)
        if response.success?
                @locations = []
                #for result in response.parsed_response.location_suggestions
                        @locations = response.parsed_response
                #end
        else
                raise response.response
        end
end
get_restaurant(options) click to toggle source

get the details from the restaurant developers.zomato.com/documentation#!/restaurant/restaurant_0 # accepts options hash as parameters options example: {res_id: “279”}

# File lib/romato.rb, line 197
def get_restaurant(options)

        zomato_restaurant_details_url = @base_uri +
                "restaurant?res_id=#{options[:res_id]}"
        response = HTTParty.get(zomato_restaurant_details_url, headers: @headers)
        if response.success?
                @restaurant = response.parsed_response
        else
                raise response.response
        end
end
get_reviews(options) click to toggle source
# File lib/romato.rb, line 211
def get_reviews(options)
        url_base = @base_uri + "reviews?" 
        a = options.key?(:res_id) ? "&res_id=#{options[:res_id]}" : ""
        b = options.key?(:start) ? "&start=#{options[:start]}" : ""
        c = options.key?(:count) ? "&count=#{options[:count]}" : ""
        zomato_reviews_url = url_base + a + b + c

        response = HTTParty.get(zomato_reviews_url, headers: @headers)

        if response.success?
                @reviews = response.parsed_response
        else
                raise response.response
        end
end