Class: VEText::Service

Inherits:
Common::Client::Base show all
Defined in:
lib/vetext/service.rb

Overview

Class used to connect to the VEText service which sends push notifications.

Constant Summary collapse

STATSD_KEY_PREFIX =
'vetext_push'
BASE_PATH =
'/api/vetext/pub/mobile/push'
REGISTER_PATH =
"#{BASE_PATH}/endpoint".freeze
PREFERENCES_PATH =
"#{BASE_PATH}/preferences/client".freeze
SEND_PATH =
"#{BASE_PATH}/send".freeze

Instance Method Summary collapse

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Instance Method Details

#get_preferences(endpoint_sid) ⇒ Object



29
30
31
32
# File 'lib/vetext/service.rb', line 29

def get_preferences(endpoint_sid)
  Rails.logger.info('VEText Push service get prefs method enter', endpoint_sid:)
  perform(:get, "#{PREFERENCES_PATH}/#{endpoint_sid}", nil)
end

#register(app_name, device_token, icn, os, device_name = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vetext/service.rb', line 18

def register(app_name, device_token, icn, os, device_name = nil)
  Rails.logger.info('VEText Push service register method enter', app_name:, app_sid: app_sid(app_name))
  perform(:put, REGISTER_PATH, {
            appSid: app_sid(app_name),
            token: device_token,
            icn:,
            os:,
            deviceName: device_name || os
          })
end

#send_notification(app_name, icn, template_id, personalization = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/vetext/service.rb', line 45

def send_notification(app_name, icn, template_id, personalization = {})
  Rails.logger.info('VEText Push service send notification method enter', app_name:,
                                                                          template_id:, icn:)
  perform(:post, SEND_PATH, {
            appSid: app_sid(app_name),
            icn:,
            templateSid: template_id,
            personalization: format_personalization(personalization)
          })
end

#set_preference(endpoint_sid, preference_id, receive_preference) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/vetext/service.rb', line 34

def set_preference(endpoint_sid, preference_id, receive_preference)
  Rails.logger.info('VEText Push service set pref method enter', endpoint_sid:,
                                                                 preference_id:,
                                                                 receive_preference:)
  perform(:put, PREFERENCES_PATH, {
            endpointSid: endpoint_sid,
            preferenceId: preference_id,
            value: receive_preference == true
          })
end