class Ragoon::Services::Notification

Constants

RETRIEVE_OPTIONS

Public Instance Methods

notification_get_notification_versions(module_id, date) click to toggle source
# 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) click to toggle source
# 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 = {}) click to toggle source
# 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