Class: VEText::Service
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
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Instance Method Details
#app_sid(app_name) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/vetext/service.rb', line 58
def app_sid(app_name)
settings = Settings.vetext_push
if settings.key?(:"#{app_name}_sid")
settings[:"#{app_name}_sid"]
else
raise Common::Exceptions::RecordNotFound, app_name
end
end
|
67
68
69
70
71
72
73
|
# File 'lib/vetext/service.rb', line 67
def format_personalization(personalization)
formatted_personalization = {}
personalization.each do |k, v|
formatted_personalization[k.upcase] = v
end
formatted_personalization
end
|
#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
|