Class: ApraService::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/apralib/apra_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password, proxy = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
# File 'lib/apralib/apra_service.rb', line 9

def initialize(username, password, proxy = nil)

  @client = Savon.client(wsdl: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS?wsdl',
                         wsse_auth: [username, password],
                         endpoint: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS',
                         proxy: proxy)
end

Instance Method Details

#send_notifications(notifications) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/apralib/apra_service.rb', line 17

def send_notifications(notifications)
  raise ArgumentError, 'notifications object cannot be nil' unless notifications
  raise ArgumentError, 'notifications object must be either a Notification object or an array of Notification objects' unless
      (notifications.is_a? Notification or (notifications.is_a? Array and notifications.detect {|n| !n.is_a? Notification}.nil?))
  notifications = [notifications] unless notifications.is_a? Array
  if notifications.count > 0
    message = {}
    message[:arg0] = notifications.map {|notification| notification.to_hash}
    response = @client.call(:lisaa_apurahat, :message => message)
    raise RuntimeError, 'An error occurred while submitting the notification' unless response.success?
    Response.from_hash(response.body)
  else
    Response.new
  end
end