5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/short_message/messages_controller.rb', line 5
def status
if callback_token_invalid?
return render plain: "Unauthorized", status: :unauthorized
end
message_id = params[:id] || params[:"message-id"]
dlr_mask = params[:"dlr-mask"]
error_code = params[:"error-code"]
return render plain: "OK", status: :ok if message_id.blank?
record = ShortMessage::Message.find_by(message_key: message_id)
return render plain: "OK", status: :ok unless record
update_params = {}
update_params[:status_code] = dlr_mask.to_i if dlr_mask.present?
if error_code.present? && error_code != "0000"
update_params[:error_code] = error_code
update_params[:error_message] = params[:"error-message"] if params[:"error-message"].present?
end
update_params[:submitted_at] = params[:"submit-date"] if params[:"submit-date"].present?
update_params[:delivered_at] = params[:"done-date"] if params[:"done-date"].present?
record.update(update_params)
ActiveSupport::Notifications.instrument("short_message.status_updated", key: message_id, status: record.status_code)
render plain: "OK", status: :ok
end
|