Class: NotificationService::Sms::Alibaba::Service
- Inherits:
-
Object
- Object
- NotificationService::Sms::Alibaba::Service
- Includes:
- APIConfig, Validations
- Defined in:
- app/services/notification_service/sms/alibaba/service.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#default_error_message ⇒ Object
readonly
Returns the value of attribute default_error_message.
-
#service_provider ⇒ Object
readonly
Returns the value of attribute service_provider.
Instance Method Summary collapse
- #handle_response(params, response, msg, phone, reservation_id) ⇒ Object
-
#initialize ⇒ Service
constructor
A new instance of Service.
-
#send_sms(msg, phones, reservation_id) ⇒ Boolean
Sends an SMS message to multiple phone numbers.
-
#sms_sent?(message_id) ⇒ Boolean
Checks if an SMS message has been sent.
Methods included from APIConfig
#access_key_secret, #default_params, #endpoint, #http_method, #separator, #sort_params
Constructor Details
#initialize ⇒ Service
Returns a new instance of Service.
8 9 10 11 12 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 8 def initialize @auth = Authentication.new @default_error_message = 'Failed to send SMS using Alibaba' @service_provider = 'alibaba' end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
6 7 8 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 6 def auth @auth end |
#default_error_message ⇒ Object (readonly)
Returns the value of attribute default_error_message.
6 7 8 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 6 def @default_error_message end |
#service_provider ⇒ Object (readonly)
Returns the value of attribute service_provider.
6 7 8 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 6 def service_provider @service_provider end |
Instance Method Details
#handle_response(params, response, msg, phone, reservation_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 30 def handle_response(params, response, msg, phone, reservation_id) res_json = JSON.parse(response.body) if sms_not_sent?(response, res_json) handle_sms_not_sent(msg, phone, reservation_id, res_json) else handle_successful_sms(msg, phone, reservation_id, params, res_json) end rescue StandardError => e handle_error(e, msg, phone, reservation_id) end |
#send_sms(msg, phones, reservation_id) ⇒ Boolean
Sends an SMS message to multiple phone numbers.
20 21 22 23 24 25 26 27 28 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 20 def send_sms(msg, phones, reservation_id) phones.each do |phone| next unless valid_to_send_sms?(phone) params = generate_request_params(phone, msg) res = Faraday.get(endpoint, params) handle_response(params, res, msg, phone, reservation_id) end end |
#sms_sent?(message_id) ⇒ Boolean
Checks if an SMS message has been sent.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/services/notification_service/sms/alibaba/service.rb', line 45 def sms_sent?() params = generate_request_status_params() res = Faraday.get(endpoint, params) res_json = JSON.parse(res.body) if sms_not_sent?(res, res_json) if send_report_when_fail_send_sms? APMErrorHandler.report(, message_id: , response: res_json) end return false end res_json['ErrorCode'] == 'DELIVERED' rescue StandardError => e HH_LOGGER.error(, error: e, message_id: ) false end |