apralib 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c82771315862534107fdf877581a8acc4b834d57b3b162b4248784fc0476ea8f
4
- data.tar.gz: 63cbc93ef71202087e605373b254da69cfee60bf072f3143e5c47f6f4ea43018
3
+ metadata.gz: c622f4562613956c04bd339229bba76d93710f30e759857d5484a25a3e009124
4
+ data.tar.gz: dcfd5590999ac42db30d87ea0970cd5147f72d44a45d13ab0895f942bbda2f85
5
5
  SHA512:
6
- metadata.gz: b3b976bd086d348a024924fef2c9846910a842f1c39cd0892ec3a0d84bf89fd1f381d0b850b89119b106f138a4a437540e2a689be5c74491b97d41859b5df248
7
- data.tar.gz: d54037f2eaf19b88077336da847dd3e7331fdf201be8f9a5ff841b434d95b198baf77cfef29f503248141cc436fea4101235304e309da552b09fc5fa04177fd0
6
+ metadata.gz: 20e87a804bb01d8c5823a3ed5f1c38c4b5e7a1f39a2e99fec1fbb1b8562f97a9ec6b1ea8b6d315410622fbb8e2c9fd84b0cf218a6926da2cd948ef55e881c038
7
+ data.tar.gz: ab964e22af2019bae50817f17462a686156a1b10c6e89a929fa1643cb34be6c4c0aa458f0b59d8711bd8d7c3b60318d5b4ac1f25b0aed85d2b8087e5e61d990c
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
@@ -1,38 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'notification'
2
4
  require_relative 'response'
3
5
  require 'savon'
4
6
 
5
7
  module ApraService
6
-
8
+ # The main entry point for the library
7
9
  class Client
8
-
9
10
  def initialize(username, password, proxy = nil)
11
+ wsdl_file = File.expand_path('../wsdl/ApurahanSyotto.wsdl', __dir__)
10
12
 
11
- @client = Savon.client(wsdl: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS?wsdl',
13
+ @client = Savon.client(wsdl: wsdl_file,
12
14
  wsse_auth: [username, password],
13
- endpoint: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS',
14
- proxy: proxy)
15
+ endpoint: 'https://palvelurajapinta.mela.fi/Apurahailmoitukset/ApurahanSyotto',
16
+ proxy: proxy,
17
+ follow_redirects: true)
18
+ end
19
+
20
+ def type_or_array_of_type(arg, type, message)
21
+ raise ArgumentError, 'object cannot be nil' unless arg
22
+
23
+ return if arg.is_a?(type) || (arg.is_a?(Array) && arg.all? { |i| i.is_a? type })
24
+
25
+ raise ArgumentError, message
15
26
  end
16
27
 
17
28
  def send_notifications(notifications)
18
- raise ArgumentError, 'notifications object cannot be nil' unless notifications
19
- raise ArgumentError, 'notifications object must be either a Notification object or an array of Notification objects' unless
20
- (notifications.is_a? Notification or (notifications.is_a? Array and notifications.detect {|n| !n.is_a? Notification}.nil?))
29
+
30
+ type_or_array_of_type(notifications, Notification,
31
+ 'notifications object must be either a Notification object' +
32
+ 'or an array of Notification objects')
33
+
21
34
  notifications = [notifications] unless notifications.is_a? Array
22
- if notifications.count > 0
23
- message = {}
24
- message[:arg0] = notifications.map {|notification| notification.to_hash}
25
- response = @client.call(:lisaa_apurahat, :message => message)
26
- raise RuntimeError, 'An error occurred while submitting the notification' unless response.success?
35
+ if notifications.count.positive?
36
+ message = { apurahailmoitustiedot: notifications.map(&:to_hash) }
37
+ response = @client.call(:lisaa_apurahat, message: message)
38
+ raise 'An error occurred while submitting the notification' unless response.success?
39
+
27
40
  Response.from_hash(response.body)
28
41
  else
29
42
  Response.new
30
43
  end
31
44
  end
32
-
33
-
34
-
35
45
  end
36
-
37
-
38
- end
46
+ end
@@ -7,8 +7,8 @@ module ApraService
7
7
  :work_end_date, :reference, :work_duration_months, :work_duration_days,
8
8
  :work_duration_years, :ignore_work_duration
9
9
 
10
- NON_NILLABLE_KEYS = [:purpose, :expense_amount, :grant_date, :granted_to_group, :work_duration_months,
11
- :work_duration_days, :work_duration_years, :grantee, :amount, :ignore_work_duration]
10
+ NON_NILLABLE_KEYS = %i[purpose expense_amount grant_date granted_to_group work_duration_months
11
+ work_duration_days work_duration_years grantee amount ignore_work_duration].freeze
12
12
 
13
13
 
14
14
  def initialize
@@ -22,7 +22,7 @@ module ApraService
22
22
 
23
23
  def to_hash
24
24
  NON_NILLABLE_KEYS.each do |key|
25
- raise RuntimeError, "Variable #{key.to_s} cannot be nil" if self.instance_variable_get("@#{key.to_s}").nil?
25
+ raise "Variable #{key} cannot be nil" if instance_variable_get("@#{key}").nil?
26
26
  end
27
27
  result = {}
28
28
  result[:kayttotarkoitus] = purpose
@@ -33,7 +33,7 @@ module ApraService
33
33
  result[:onko_myonnetty_tyoryhmalle] = granted_to_group
34
34
  result[:rahamaara] = amount
35
35
  result[:saajatiedot] = grantee.to_hash
36
- result[:sisaltaako_kuluja] = (expense_amount > 0)
36
+ result[:sisaltaako_kuluja] = expense_amount.positive?
37
37
 
38
38
  if ignore_work_duration
39
39
  result[:tyon_kesto_kuukausia] = 0
@@ -1,14 +1,14 @@
1
- module ApraService
1
+ # frozen_string_literal: true
2
2
 
3
+ module ApraService
4
+ # The response received from the WebService
3
5
  class Response
4
-
5
6
  attr_accessor :failed_notifications
6
7
 
7
8
  def initialize
8
9
  @failed_notifications = []
9
10
  end
10
11
 
11
-
12
12
  def self.from_hash(hash)
13
13
  puts hash.inspect
14
14
  response = Response.new
@@ -16,15 +16,9 @@ module ApraService
16
16
  failures = raw_response[:epaonnistuneet_ilmoitukset]
17
17
  if failures
18
18
  failures = [failures] unless failures.is_a? Array
19
- response.failed_notifications = failures.map {|notification| NotificationResponse.from_hash(notification) }
19
+ response.failed_notifications = failures.map { |notification| NotificationResponse.from_hash(notification) }
20
20
  end
21
21
  response
22
22
  end
23
-
24
-
25
23
  end
26
-
27
-
28
-
29
-
30
- end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Apralib
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -0,0 +1,103 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <wsdl:definitions name="ApurahanSyotto"
3
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
5
+ xmlns:tns="http://palvelurajapinta.mela.fi/WebService/"
6
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
7
+ targetNamespace="http://palvelurajapinta.mela.fi/WebService/">
8
+ <wsdl:types>
9
+ <xs:schema xmlns:tns="http://palvelurajapinta.mela.fi/WebService/"
10
+ targetNamespace="http://palvelurajapinta.mela.fi/WebService/"
11
+ xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified"
12
+ attributeFormDefault="unqualified">
13
+ <xs:element type="tns:lisaaApurahat" name="lisaaApurahat" />
14
+ <xs:element type="tns:lisaaApurahatResponse" name="lisaaApurahatResponse" />
15
+
16
+ <xs:complexType name="lisaaApurahat">
17
+ <xs:sequence>
18
+ <xs:element type="tns:apurahailmoitustiedot" name="apurahailmoitustiedot" minOccurs="0" maxOccurs="unbounded" />
19
+ </xs:sequence>
20
+ </xs:complexType>
21
+ <xs:complexType name="apurahailmoitustiedot">
22
+ <xs:sequence>
23
+ <xs:element type="xs:string" name="kayttotarkoitus" />
24
+ <xs:element type="xs:string" name="kayttotarkoitustarkenne" minOccurs="0" />
25
+ <xs:element type="xs:decimal" name="kuluosuusrahamaara" minOccurs="0" />
26
+ <xs:element type="xs:string" name="kuluosuusteksti" minOccurs="0" />
27
+ <xs:element type="xs:dateTime" name="myontopaatoksenAntopvm" />
28
+ <xs:element type="xs:boolean" name="onkoMyonnettyTyoryhmalle" />
29
+ <xs:element type="xs:decimal" name="rahamaara" />
30
+ <xs:element type="tns:saajatiedot" name="saajatiedot" />
31
+ <xs:element type="xs:boolean" name="sisaltaakoKuluja" />
32
+ <xs:element type="xs:int" name="tyonKestoKuukausia" />
33
+ <xs:element type="xs:int" name="tyonKestoPaivia" />
34
+ <xs:element type="xs:int" name="tyonKestoVuosia" />
35
+ <xs:element type="xs:string" name="tyonkestoeikantaa" minOccurs="0" />
36
+ <xs:element type="xs:dateTime" name="tyoskentelynAlkamispvm" minOccurs="0" />
37
+ <xs:element type="xs:dateTime" name="tyoskentelynPaattymispvm" minOccurs="0" />
38
+ <xs:element type="xs:string" name="viite" minOccurs="0" />
39
+ </xs:sequence>
40
+ </xs:complexType>
41
+ <xs:complexType name="saajatiedot">
42
+ <xs:sequence>
43
+ <xs:element type="xs:string" name="apurahansaajanosoite" minOccurs="0" />
44
+ <xs:element type="xs:string" name="apurahansaajanpostinumero" minOccurs="0" />
45
+ <xs:element type="xs:string" name="etunimi1" />
46
+ <xs:element type="xs:string" name="etunimi2" minOccurs="0" />
47
+ <xs:element type="xs:string" name="etunimi3" minOccurs="0" />
48
+ <xs:element type="tns:HenkilotunnusTyyppi" name="henkilotunnus" />
49
+ <xs:element type="xs:string" name="sukunimi" />
50
+ </xs:sequence>
51
+ </xs:complexType>
52
+ <xs:complexType name="lisaaApurahatResponse">
53
+ <xs:sequence>
54
+ <xs:element type="tns:epaonnistunutIlmoitus" name="epaonnistuneetIlmoitukset" minOccurs="0" maxOccurs="unbounded" />
55
+ </xs:sequence>
56
+ </xs:complexType>
57
+ <xs:complexType name="epaonnistunutIlmoitus">
58
+ <xs:sequence>
59
+ <xs:element type="tns:apurahailmoitustiedot" name="ilmoitus" />
60
+ <xs:element type="xs:string" name="virhe" />
61
+ </xs:sequence>
62
+ </xs:complexType>
63
+ <xs:simpleType name="HenkilotunnusTyyppi">
64
+ <xs:restriction base="xs:string">
65
+ <xsd:pattern value="[0-3]\d[01]\d{3}[+\-A]\d{3}[0-9A-FHJ-NPR-Y]"/>
66
+ </xs:restriction>
67
+ </xs:simpleType>
68
+ </xs:schema>
69
+ </wsdl:types>
70
+ <wsdl:message name="lisaaApurahatResponse">
71
+ <wsdl:part name="parameters" element="tns:lisaaApurahatResponse">
72
+ </wsdl:part>
73
+ </wsdl:message>
74
+ <wsdl:message name="lisaaApurahat">
75
+ <wsdl:part name="parameters" element="tns:lisaaApurahat">
76
+ </wsdl:part>
77
+ </wsdl:message>
78
+ <wsdl:portType name="ApurahanSyotto">
79
+ <wsdl:operation name="lisaaApurahat">
80
+ <wsdl:input name="lisaaApurahat" message="tns:lisaaApurahat">
81
+ </wsdl:input>
82
+ <wsdl:output name="lisaaApurahatResponse" message="tns:lisaaApurahatResponse">
83
+ </wsdl:output>
84
+ </wsdl:operation>
85
+ </wsdl:portType>
86
+ <wsdl:binding type="tns:ApurahanSyotto" name="ApurahanSyottoSoapBinding">
87
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
88
+ <wsdl:operation name="lisaaApurahat">
89
+ <soap:operation style="document" soapAction="http://palvelurajapinta.mela.fi/WebService/lisaaApurahat" />
90
+ <wsdl:input name="lisaaApurahat">
91
+ <soap:body use="literal" />
92
+ </wsdl:input>
93
+ <wsdl:output name="lisaaApurahatResponse">
94
+ <soap:body use="literal" />
95
+ </wsdl:output>
96
+ </wsdl:operation>
97
+ </wsdl:binding>
98
+ <wsdl:service name="ApurahanSyotto">
99
+ <wsdl:port name="ApurahanSyottoImplPort" binding="tns:ApurahanSyottoSoapBinding">
100
+ <soap:address location="http://palvelurajapinta.mela.fi/Apurahailmoitukset/ApurahanSyotto"/>
101
+ </wsdl:port>
102
+ </wsdl:service>
103
+ </wsdl:definitions>
@@ -53,7 +53,11 @@ module ApraService
53
53
  notification.work_start_date = Date.today
54
54
  notification.work_end_date = Date.today >> 1
55
55
  notification1 = Notification.new
56
- notification1.grantee = grantee
56
+ grantee1 = Grantee.new
57
+ grantee1.first_names='Matti'
58
+ grantee1.last_name = 'Matelija'
59
+ grantee1.ssn = '111111-111C'
60
+ notification1.grantee = grantee1
57
61
  notification1.granted_to_group = false
58
62
  notification1.expense_amount = 0
59
63
  notification1.amount = 10000
@@ -69,9 +73,11 @@ module ApraService
69
73
  response = service.send_notifications([notification, notification1])
70
74
  expect(response).not_to be_nil
71
75
  failed_notifications = response.failed_notifications
76
+ puts(failed_notifications)
72
77
  expect(failed_notifications).not_to be_nil
73
78
  expect(failed_notifications).to be_a Array
74
79
  expect(failed_notifications.count).to eq(1)
80
+
75
81
  notification_response = failed_notifications[0]
76
82
  expect(notification_response.error).not_to be_nil
77
83
  expect(notification_response.notification.reference).to eq(notification.reference)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apralib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Sandrini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-21 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rubocop.yml"
92
+ - ".ruby-version"
92
93
  - ".travis.yml"
93
94
  - Gemfile
94
95
  - LICENSE.txt
@@ -102,6 +103,7 @@ files:
102
103
  - lib/apralib/notification_response.rb
103
104
  - lib/apralib/response.rb
104
105
  - lib/apralib/version.rb
106
+ - lib/wsdl/ApurahanSyotto.wsdl
105
107
  - spec/lib/apra_service_spec.rb
106
108
  - spec/lib/grantee_spec.rb
107
109
  - spec/spec_helper.rb