Class: Ragoon::Services::Notification
Constant Summary
collapse
- RETRIEVE_OPTIONS =
{
date: Date.today,
module_ids: %w[grn.schedule grn.workflow],
}.freeze
SERVICE_LOCATIONS
Instance Attribute Summary
#action_type, #client
Instance Method Summary
collapse
#endpoint, #garoon_endpoint, #initialize, start_and_end
Instance Method Details
#notification_get_notification_versions(module_id, date) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/ragoon/services/notification.rb', line 37
def notification_get_notification_versions(module_id, date)
action_name = 'NotificationGetNotificationVersions'
body_node = Ragoon::XML.create_node(action_name)
target_date = Ragoon::Services.start_and_end(date)
parameter_node = Ragoon::XML.create_node(
'parameters',
start: target_date[:start].strftime('%FT%T'),
end: target_date[:end].strftime('%FT%T'),
module_id: module_id,
)
body_node.add_child(parameter_node)
client.request(action_name, body_node)
client.result_set
end
|
#notification_get_notifications_by_id(notification_items) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/ragoon/services/notification.rb', line 55
def notification_get_notifications_by_id(notification_items)
action_name = 'NotificationGetNotificationsById'
body_node = Ragoon::XML.create_node(action_name)
today = Ragoon::Services.start_and_end
parameter_node = Ragoon::XML.create_node('parameters')
notification_items.each do |notification_item|
parameter_node.add_child(
Ragoon::XML.create_node(
'notification_id',
module_id: notification_item[:module_id],
item: notification_item[:item]
)
)
end
body_node.add_child(parameter_node)
client.request(action_name, body_node)
client.result_set
end
|
#retrieve(options = {}) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ragoon/services/notification.rb', line 7
def retrieve(options = {})
options = RETRIEVE_OPTIONS.dup.merge(options)
results = options[:module_ids].each_with_object({}) do |module_id, result|
result[module_id] = notification_get_notification_versions(module_id, options[:date])
client.reset
end
items = results.each_with_object([]) do |(module_id, notifications), result|
notifications.xpath('//notification_item').each do |notification|
result.push(
{
module_id: module_id,
item: notification.xpath('notification_id').first[:item]
}
)
end
end
notifications = notification_get_notifications_by_id(items)
first_item = notifications.xpath('//notification').first
return [] if first_item.nil?
keys = first_item.attributes.keys.map(&:to_sym)
notifications.xpath('//notification').each_with_object([]) do |notification, result|
result.push(
keys.each_with_object({}) { |key, hash| hash[key] = notification[key] }
)
end
end
|