Class: UserRequestWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/user_request_worker.rb

Overview

typed: ignore frozen_string_literal: true

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Attribute Details

#cust_msgObject (readonly)

Returns the value of attribute cust_msg.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def cust_msg
  @cust_msg
end

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def name
  @name
end

#party_sizeObject (readonly)

Returns the value of attribute party_size.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def party_size
  @party_size
end

#phoneObject (readonly)

Returns the value of attribute phone.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def phone
  @phone
end

#restaurantObject (readonly)

Returns the value of attribute restaurant.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def restaurant
  @restaurant
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'app/workers/user_request_worker.rb', line 5

def time
  @time
end

Instance Method Details

#bodyObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/workers/user_request_worker.rb', line 32

def body
  msg = <<MSG
Restaurant: #{restaurant.name}
Date: #{date}
Time: #{time}
Party Size: #{party_size}
Name: #{name}
Phone: #{phone}
Message: #{cust_msg.present? ? cust_msg : '-'}
MSG
  msg
end

#perform(data) ⇒ Object



7
8
9
10
# File 'app/workers/user_request_worker.rb', line 7

def perform(data)
  setup_attr(data)
  send_email
end

#send_emailObject



12
13
14
15
# File 'app/workers/user_request_worker.rb', line 12

def send_email
  mail(subject: subject, from: NO_REPLY_EMAIL,
       reply_to: SUPPORT_EMAIL, to: ERROR_RECIPIENT_EMAIL, bcc: SUPPORT_EMAIL_SLACK)
end

#setup_attr(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'app/workers/user_request_worker.rb', line 17

def setup_attr(data)
  @restaurant = Restaurant.find(data['restaurant_id'])
  @cust_msg = data['message']
  @party_size = data['party_size']
  @phone = data['phone']
  @name = data['name']
  @date = data['date']
  @time = data['time']
  @date = Date.parse(@date) unless @date.is_a?(Date)
end

#subjectObject



28
29
30
# File 'app/workers/user_request_worker.rb', line 28

def subject
  "Urgent Message: #{restaurant.name}"
end