Class: NotificationService::Sms::Silverstreet::Service

Inherits:
Object
  • Object
show all
Includes:
APIConfig
Defined in:
app/services/notification_service/sms/silverstreet/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from APIConfig

#default_params, #endpoint

Constructor Details

#initializeService

Returns a new instance of Service.



7
8
9
10
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 7

def initialize
  @default_error_message = 'Failed to send SMS using Silverstreet'
  @service_provider = 'silverstreet'
end

Instance Attribute Details

#default_error_messageObject (readonly)

Returns the value of attribute default_error_message.



5
6
7
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 5

def default_error_message
  @default_error_message
end

#service_providerObject (readonly)

Returns the value of attribute service_provider.



5
6
7
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 5

def service_provider
  @service_provider
end

Instance Method Details

#handle_response(params, res, msg, phones, reservation_id) ⇒ Object



32
33
34
35
36
37
38
39
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 32

def handle_response(params, res, msg, phones, reservation_id)
  if sms_not_sent?(res)
    handle_sms_not_sent(msg, phones, reservation_id, res.body)
    raise default_error_message
  else
    handle_successful_sms(reservation_id, params, res.body)
  end
end

#make_request(params) ⇒ Object



25
26
27
28
29
30
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 25

def make_request(params)
  Faraday.post(endpoint, params)
rescue StandardError => e
  handle_error(e)
  raise default_error_message
end

#send_sms(msg, phones, reservation_id) ⇒ Boolean

Sends an SMS message using the Silverstreet service.

Parameters:

  • msg (String)

    The message to be sent.

  • phones (Array<String>)

    The phone numbers to send the message to.

  • reservation_id (Integer)

    The ID of the reservation associated with the message.

Returns:

  • (Boolean)

    Returns true if the SMS messages were sent successfully, false otherwise.



19
20
21
22
23
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 19

def send_sms(msg, phones, reservation_id)
  params = build_params(msg, phones, reservation_id)
  res = make_request(params)
  handle_response(params, res, msg, phones, reservation_id)
end

#sms_sent?(message_id) ⇒ Boolean

Checks if an SMS message has been sent.

Parameters:

  • message_id (String)

    The ID of the message to check.

Returns:

  • (Boolean)

    Returns true if the message has been sent, false otherwise.



45
46
47
48
# File 'app/services/notification_service/sms/silverstreet/service.rb', line 45

def sms_sent?(message_id)
  true
  # TODO: implement this method
end