Class: Zomato::Restaurant
- Inherits:
-
Object
- Object
- Zomato::Restaurant
- Defined in:
- lib/zomato/restaurant.rb
Defined Under Namespace
Classes: Collection
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#cost_for_two ⇒ Object
readonly
Returns the value of attribute cost_for_two.
-
#cuisines ⇒ Object
readonly
Returns the value of attribute cuisines.
-
#has_citibank_discount ⇒ Object
readonly
Returns the value of attribute has_citibank_discount.
-
#has_discount ⇒ Object
readonly
Returns the value of attribute has_discount.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#locality ⇒ Object
readonly
Returns the value of attribute locality.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rating_editor_overall ⇒ Object
readonly
Returns the value of attribute rating_editor_overall.
Class Method Summary collapse
- .build(response, query) ⇒ Object
- .create_by_details(details) ⇒ Object
- .near(lat, lon, query = {}) ⇒ Object
- .search(city_id, search_term, query = {}) ⇒ Object
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(attributes) ⇒ Restaurant
constructor
A new instance of Restaurant.
- #report_error(data, name = nil) ⇒ Object
- #reviews(query = {}) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Restaurant
Returns a new instance of Restaurant.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/zomato/restaurant.rb', line 76 def initialize(attributes) @id = attributes['id'].to_i @name = attributes['name'] @address = attributes['address'] @locality = attributes['locality'] @city = attributes['city'] @cuisines = attributes['cuisines'] @rating_editor_overall = attributes['rating_editor_overall'] @cost_for_two = attributes['cost_for_two'] @has_discount = attributes['has_discount'] == 1 @has_citibank_discount = attributes['has_citibank_discount'] == 1 @details = attributes['details'] if attributes['details'] end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def address @address end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def city @city end |
#cost_for_two ⇒ Object (readonly)
Returns the value of attribute cost_for_two.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def cost_for_two @cost_for_two end |
#cuisines ⇒ Object (readonly)
Returns the value of attribute cuisines.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def cuisines @cuisines end |
#has_citibank_discount ⇒ Object (readonly)
Returns the value of attribute has_citibank_discount.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def has_citibank_discount @has_citibank_discount end |
#has_discount ⇒ Object (readonly)
Returns the value of attribute has_discount.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def has_discount @has_discount end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def id @id end |
#locality ⇒ Object (readonly)
Returns the value of attribute locality.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def locality @locality end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def name @name end |
#rating_editor_overall ⇒ Object (readonly)
Returns the value of attribute rating_editor_overall.
74 75 76 |
# File 'lib/zomato/restaurant.rb', line 74 def @rating_editor_overall end |
Class Method Details
.build(response, query) ⇒ Object
109 110 111 |
# File 'lib/zomato/restaurant.rb', line 109 def build(response, query) Collection.new(response, query) end |
.create_by_details(details) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/zomato/restaurant.rb', line 113 def create_by_details(details) attributes = { 'details' => details, 'name' => details['name'], 'id' => details['id'], 'address' => details['location']['address'], 'locality' => details['location']['locality'], 'city' => details['location']['city'], 'cuisines' => details['cuisines'], 'rating_editor_overall' => details['editorRating']['overall'], 'cost_for_two' => details['avgCostForTwo'] } Restaurant.new(attributes) end |
.near(lat, lon, query = {}) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/zomato/restaurant.rb', line 137 def near(lat, lon, query = {}) query = { :lat => lat, :lon => lon, :random => true }.merge(query) create_by_details(Api.get("/search/near", :query => query).parsed_response) end |
.search(city_id, search_term, query = {}) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/zomato/restaurant.rb', line 128 def search(city_id, search_term, query = {}) query = { :city_id => city_id, :q => search_term }.merge(query) response = Api.get("/search", :query => query).parsed_response Restaurant.build(response, query) end |
Instance Method Details
#details ⇒ Object
90 91 92 |
# File 'lib/zomato/restaurant.rb', line 90 def details @details ||= Api.get("/restaurant/#{id}").parsed_response end |
#report_error(data, name = nil) ⇒ Object
102 103 104 105 106 |
# File 'lib/zomato/restaurant.rb', line 102 def report_error(data, name = nil) query = {:res_id => id, :data => data} query.store(:name, name) if name Api.post('/contact', :query => query).parsed_response['status'] == 1 end |
#reviews(query = {}) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/zomato/restaurant.rb', line 94 def reviews(query = {}) query = { :start => 1, :count => 10 }.merge(query) Api.get("/reviews/#{id}/user", :query => query).parsed_response end |