Class: ApraService::Client
- Inherits:
-
Object
- Object
- ApraService::Client
- Defined in:
- lib/apralib/apra_service.rb
Overview
The main entry point for the library
Instance Method Summary collapse
-
#initialize(username, password, proxy = nil) ⇒ Client
constructor
A new instance of Client.
- #send_notifications(notifications) ⇒ Object
- #type_or_array_of_type(arg, type, message) ⇒ Object
Constructor Details
#initialize(username, password, proxy = nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 |
# File 'lib/apralib/apra_service.rb', line 10 def initialize(username, password, proxy = nil) wsdl_file = File.('../wsdl/ApurahanSyotto.wsdl', __dir__) @client = Savon.client(wsdl: wsdl_file, wsse_auth: [username, password], endpoint: 'https://palvelurajapinta.mela.fi/Apurahailmoitukset/ApurahanSyotto', proxy: proxy, follow_redirects: true) end |
Instance Method Details
#send_notifications(notifications) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/apralib/apra_service.rb', line 28 def send_notifications(notifications) type_or_array_of_type(notifications, Notification, 'notifications object must be either a Notification object' + 'or an array of Notification objects') notifications = [notifications] unless notifications.is_a? Array if notifications.count.positive? = { apurahailmoitustiedot: notifications.map(&:to_hash) } response = @client.call(:lisaa_apurahat, message: ) raise 'An error occurred while submitting the notification' unless response.success? Response.from_hash(response.body) else Response.new end end |
#type_or_array_of_type(arg, type, message) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/apralib/apra_service.rb', line 20 def type_or_array_of_type(arg, type, ) raise ArgumentError, 'object cannot be nil' unless arg return if arg.is_a?(type) || (arg.is_a?(Array) && arg.all? { |i| i.is_a? type }) raise ArgumentError, end |