Class: HomeController
Overview
typed: ignore frozen_string_literal: true
Instance Method Summary
collapse
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
#append_info_to_payload
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Method Details
#aasa ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/controllers/home_controller.rb', line 108
def aasa
file_name = 'apple-app-site-association.p7m'
file_path = Rails.root.join("tmp/#{file_name}")
ck = local_cache_key action_name
if should_download?(file_path, ck)
file_name_on_aws = "#{Rails.env}_#{file_name}"
download_asset_file(file_path, file_name_on_aws)
wait_for(file_path)
Rails.cache.write ck, true, expires_in: 1.hour
end
render json: file_path.read
end
|
#assetlinks ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/home_controller.rb', line 121
def assetlinks
file_path = Rails.root.join('tmp/assetlinks.json')
ck = local_cache_key ck
if should_download?(file_path, ck)
download_asset_file(file_path, 'assetlinks.json')
wait_for(file_path)
Rails.cache.write ck, true, expires_in: 1.hour
end
render json: file_path.read
end
|
#blog ⇒ Object
104
105
106
|
# File 'app/controllers/home_controller.rb', line 104
def blog
redirect_to 'https://blog.hungryhub.com'
end
|
#check_logging ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/home_controller.rb', line 8
def check_logging
reservation_id = rand(1_000_000)
payload = {
current_time: Time.zone.now,
}
CUSTOM_LOGGERS.each do |logger|
logger.set_business_context({
reservation_id: reservation_id,
})
logger.set_request_context(payload)
end
CUSTOM_LOGGERS.each do |logger|
logger.debug 'debug message'
logger.info 'info message'
logger.warn 'warn message'
logger.error 'error message'
end
render json: payload.merge(reservation_id: reservation_id)
end
|
#facebook_catalog ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'app/controllers/home_controller.rb', line 87
def facebook_catalog
file_path = Rails.root.join('tmp', Feeds::FacebookRestaurantsWorker::FILE_NAME)
ck = local_cache_key(action_name)
if should_download?(file_path, ck)
Feeds::FacebookRestaurantsWorker.download
wait_for(file_path)
Rails.cache.write ck, true, expires_in: 1.hour
end
send_file file_path, type: 'text/tab-separated-values; charset=utf-8', status: 200
end
|
#find_user_by_email ⇒ Object
172
173
174
175
176
177
178
179
|
# File 'app/controllers/home_controller.rb', line 172
def find_user_by_email
user = User.find_by email: params.require(:user).require(:email)
if user.present?
render json: { data: { id: user.id } }
else
render json: { messages: 'User not found' }, status: :unprocessable_entity
end
end
|
#forward_email ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'app/controllers/home_controller.rb', line 186
def forward_email
valid_params = params.require(:share).permit(:email)
if params[:reservation_id].blank?
redirect_back(fallback_location: root_path(locale: I18n.locale),
alert: 'Invalid reservation ID') && return
end
unless verify_recaptcha
redirect_back(fallback_location: root_path(locale: I18n.locale),
alert: 'Are you robot?') && return
end
emails = valid_params[:email].to_s.split(' ').presence || []
if emails.blank?
redirect_back(fallback_location: root_path(locale: I18n.locale),
alert: 'Email should be present') && return
end
reservation = Reservation.fetch(HungryHub::Reservation::Codec.decode(params.require(:reservation_id)))
if !reservation.reached_goal?
redirect_back(fallback_location: root_path(locale: I18n.locale),
alert: 'Your reservation has been cancelled or passed') && return
end
UserMailer.share_booking_confirmation(reservation.id, emails).deliver_later!
redirect_back(fallback_location: root_path(locale: I18n.locale),
notice: "Forwarding email success, your friend#{if emails.size > 1
's'
end} will receive it in few minutes")
rescue StandardError => e
APMErrorHandler.report e, params: params
Rails.logger.error e.message
Rails.logger.error e.backtrace.join("\n\t")
redirect_back(fallback_location: root_path(locale: I18n.locale),
alert: 'Something went wrong, please contact our support support@hungryhub.com')
end
|
181
182
183
184
|
# File 'app/controllers/home_controller.rb', line 181
def forward_email_form
set_meta_tags title: 'Share to Friends'
render layout: 'widget'
end
|
#gb_primepay_otp ⇒ Object
56
57
58
|
# File 'app/controllers/home_controller.rb', line 56
def gb_primepay_otp
render layout: nil
end
|
#health_check ⇒ Object
32
33
34
35
36
37
38
|
# File 'app/controllers/home_controller.rb', line 32
def health_check
if ActiveRecord::Base.connection.active?
render json: { status: 'ok' }, status: :ok
else
render json: { status: 'error' }, status: :service_unavailable
end
end
|
#helper_route_to_redirect_to_kiosque_callback_url ⇒ Object
60
61
62
63
|
# File 'app/controllers/home_controller.rb', line 60
def helper_route_to_redirect_to_kiosque_callback_url
query_param = request.query_parameters.to_param
redirect_to "#{AdminSetting.kiosque_callback_url}?#{query_param}"
end
|
#id_to_qrcode ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/home_controller.rb', line 65
def id_to_qrcode
id = params.require(:id).to_i.tap do |_id|
raise if _id.negative? || _id > 900_000_000
end.to_s
qrcode = RQRCode::QRCode.new(id)
png = qrcode.as_png(
bit_depth: 1,
border_modules: 4,
color_mode: ChunkyPNG::COLOR_GRAYSCALE,
color: 'black',
file: nil,
fill: 'white',
module_px_size: 6,
resize_exactly_to: false,
resize_gte_to: false,
size: 500
)
render plain: png.to_s, content_type: 'image/png'
end
|
#liveness ⇒ Object
40
41
42
|
# File 'app/controllers/home_controller.rb', line 40
def liveness
render json: { status: 'ok' }, status: :ok
end
|
#manifest ⇒ Object
132
133
134
|
# File 'app/controllers/home_controller.rb', line 132
def manifest
render json: Rails.root.join('public/manifest.json').read
end
|
#payment_redirect_to ⇒ Object
52
53
54
|
# File 'app/controllers/home_controller.rb', line 52
def payment_redirect_to
reservation = Reservation.find(Reservation.decrypt_id(params[:reservation_id]))
end
|
#readiness ⇒ Object
44
45
46
47
48
49
50
|
# File 'app/controllers/home_controller.rb', line 44
def readiness
if ActiveRecord::Base.connection.active?
render json: { status: 'ok' }, status: :ok
else
render json: { status: 'error' }, status: :service_unavailable
end
end
|
#restaurant_details ⇒ Object
used by app/assets/javascripts/externals/find-table.js
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'app/controllers/home_controller.rb', line 148
def restaurant_details
unless params[:id] != 'undefined'
begin
referrer = request.env['HTTP_REFERER'] || request.env['HTTP_REFERRER']
referrer = URI.parse(referrer)
restaurant_id = referrer.query.split('&').select do |query|
query.include? 'restaurant_id'
end
params[:id] = restaurant_id.present? ? restaurant_id.last.split('=').try(:last) : nil
raise 'params[:id] is nil' if params[:id].nil?
rescue StandardError => e
HH_LOGGER.info e, 'Invalid parameters'
return render json: opening_hours('')
end
end
restaurant = Restaurant.includes(:restaurant_external).find params[:id]
chalkboard = restaurant.restaurant_external.try(:chalkboard) || ''
response = opening_hours(restaurant.opening_hours).merge(chalkboard: Rinku.auto_link(chalkboard, :all, 'target="_blank"'),
booking_condition: restaurant.booking_condition,
largest_table: restaurant.largest_table,
party_size_html: view_context.party_size_html(restaurant))
render json: response.deep_transform_keys { |k| k.to_s.camelize(:lower) }
end
|
#sitemap ⇒ Object
136
137
138
139
140
141
142
143
144
145
|
# File 'app/controllers/home_controller.rb', line 136
def sitemap
file_path = Rails.root.join('tmp', 'sitemap.xml.gz')
ck = local_cache_key action_name
if should_download?(file_path, ck)
download_asset_file(file_path, 'sitemap.xml.gz')
wait_for(file_path)
Rails.cache.write ck, true, expires_in: 1.hour
end
send_file file_path
end
|
#tnc ⇒ Object
terms and conditions page used by mobile app
100
101
102
|
# File 'app/controllers/home_controller.rb', line 100
def tnc
redirect_to "https://www.hungryhub.com/uploads/restaurants/tc/image/6/tc.pdf?date=#{Time.zone.today}"
end
|