Module: NotificationService::Sms::Kaleyra::APIConfig

Included in:
Service
Defined in:
app/services/notification_service/sms/kaleyra/api_config.rb

Instance Method Summary collapse

Instance Method Details

#default_paramsObject



8
9
10
11
12
13
14
# File 'app/services/notification_service/sms/kaleyra/api_config.rb', line 8

def default_params
  {
    sender: 'HungryHub',
    type: 'DEFAULT',
    unicode: 'AUTO',
  }
end

#endpointObject



3
4
5
6
# File 'app/services/notification_service/sms/kaleyra/api_config.rb', line 3

def endpoint
  sid = Figaro.env.KALEYRA_IO_SID_KEY!
  "#{AdminSetting.kaleyra_io_api_host}/#{sid}/messages"
end

#headersObject



16
17
18
19
20
21
# File 'app/services/notification_service/sms/kaleyra/api_config.rb', line 16

def headers
  api_key = Figaro.env.KALEYRA_IO_API_KEY!
  {
    "api-key": api_key,
  }
end

#sort_params(params, sort = 'asc') ⇒ Hash

Sorts the given parameters in ascending or descending order based on the specified sort order (default asc).

Parameters:

  • params (Hash)

    The parameters to be sorted.

  • sort (String) (defaults to: 'asc')

    The sort order. Valid values are 'asc' for ascending and 'desc' for descending.

Returns:

  • (Hash)

    The sorted parameters.

Raises:

  • (ArgumentError)

    If the params argument is not a hash or if the sort argument is not 'asc' or 'desc'.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/notification_service/sms/kaleyra/api_config.rb', line 29

def sort_params(params, sort = 'asc')
  unless params.is_a?(Hash)
    raise ArgumentError, "Params must be a hash, got #{params.class} instead."
  end

  case sort.downcase
  when 'asc'
    params.sort.to_h
  when 'desc'
    params.sort.reverse.to_h
  else
    raise ArgumentError, "Invalid sort order: #{sort}. Use 'asc' or 'desc'."
  end
end