Class: Kenui::EmailNotificationService

Inherits:
KillBillClient::Model::Resource
  • Object
show all
Defined in:
app/services/kenui/email_notification_service.rb

Overview

class where email notification services resides

Constant Summary collapse

KILLBILL_EMAIL_NOTIFICATION_PREFIX =
'/plugins/killbill-email-notifications/v1'

Class Method Summary collapse

Class Method Details

.email_notification_plugin_available?(options = nil) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
# File 'app/services/kenui/email_notification_service.rb', line 47

def email_notification_plugin_available?(options = nil)
  # inquire if the plugin is listening
  path = KILLBILL_EMAIL_NOTIFICATION_PREFIX
  KillBillClient::API.get path, nil, options

  [true, nil]
# Response error if email notification plugin is not listening
rescue KillBillClient::API::ResponseError => e
  [false, e.message.to_s]
end

.get_configuration_per_account(account_id, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'app/services/kenui/email_notification_service.rb', line 24

def (, options = {})
  path = "#{KILLBILL_EMAIL_NOTIFICATION_PREFIX}/accounts/#{}"
  response = KillBillClient::API.get path, {}, options

  JSON.parse(response.body).map(&:symbolize_keys)
rescue StandardError => e
  [false, e.message.to_s]
end

.get_configurations(account_ids, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'app/services/kenui/email_notification_service.rb', line 15

def get_configurations(, options = {})
  path = "#{KILLBILL_EMAIL_NOTIFICATION_PREFIX}/accounts"
  response = KillBillClient::API.get path, { kbAccountId:  }, options

  JSON.parse(response.body).map(&:symbolize_keys)
rescue StandardError => e
  [false, e.message.to_s]
end

.get_events_to_consider(options = {}) ⇒ Object



9
10
11
12
13
# File 'app/services/kenui/email_notification_service.rb', line 9

def get_events_to_consider(options = {})
  path = "#{KILLBILL_EMAIL_NOTIFICATION_PREFIX}/eventsToConsider"
  response = KillBillClient::API.get path, {}, options
  JSON.parse(response.body)
end

.set_configuration_per_account(account_id, event_types, user = 'kenui', reason = nil, comment = nil, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/kenui/email_notification_service.rb', line 33

def (, event_types, user = 'kenui', reason = nil, comment = nil, options = {})
  path = "#{KILLBILL_EMAIL_NOTIFICATION_PREFIX}/accounts/#{}"
  more_options = {}
  more_options[:user] = user
  more_options[:reason] = reason unless reason.nil?
  more_options[:comment] = comment unless comment.nil?

  KillBillClient::API.post path, event_types, {}, options.merge(more_options)

  [true, "Email notifications for account #{} was successfully updated"]
rescue StandardError => e
  [false, e.message.to_s]
end