apralib 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +3 -0
- data/.travis.yml +6 -6
- data/README.md +5 -0
- data/apralib.gemspec +6 -4
- data/lib/apralib/apra_service.rb +13 -7
- data/lib/apralib/grantee.rb +10 -6
- data/lib/apralib/response.rb +4 -2
- data/lib/apralib/version.rb +1 -1
- data/spec/lib/apra_service_spec.rb +15 -4
- data/spec/lib/grantee_spec.rb +22 -0
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b3256db49c369085a45a47586f7d225d6914a951f55baddb18b19d5385bf928
|
4
|
+
data.tar.gz: 9270c0ba4a7d6a228397f1d5439704808042e26f9dca5ce55c37686ce03f16b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05c78f9fed17951c19d6bffa5ad660a8f6f9ef693c87888e5c6767a1a47779b0a9ec87fd0ee2acb032441149ca553075e0356993ed8dd9ed418a864f718f084
|
7
|
+
data.tar.gz: b0c1081c67f7d9446b04f209fb5b0914470e7a36f7688f6e9d1d0e98e7f01bef640cd2c4299864d18599b8b49b716b9bca52ea389a4566c15f93f68d4d2e97b2
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
- 2.7.2
|
4
|
+
- 2.4.0
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
edge: true
|
8
|
+
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Apralib
|
2
2
|
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/nessche/apralib.svg?branch=master)](https://travis-ci.org/nessche/apralib)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/apralib.svg)](http://badge.fury.io/rb/apralib)
|
6
|
+
|
7
|
+
|
3
8
|
A Ruby library to submit documents to the Apra Service run by [Maatalousyrittäjien eläkelaitos](http://www.mela.fi)
|
4
9
|
|
5
10
|
## Installation
|
data/apralib.gemspec
CHANGED
@@ -17,10 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
|
+
spec.required_ruby_version = '>= 2.4.0'
|
20
21
|
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
22
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
23
|
+
spec.add_development_dependency 'rake', '< 11.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.10.0'
|
24
25
|
spec.add_development_dependency 'yard'
|
25
|
-
spec.add_dependency 'savon', '~> 2.
|
26
|
+
spec.add_dependency 'savon', '~> 2.12.0'
|
27
|
+
|
26
28
|
end
|
data/lib/apralib/apra_service.rb
CHANGED
@@ -6,10 +6,12 @@ module ApraService
|
|
6
6
|
|
7
7
|
class Client
|
8
8
|
|
9
|
-
def initialize(username, password)
|
9
|
+
def initialize(username, password, proxy = nil)
|
10
|
+
|
10
11
|
@client = Savon.client(wsdl: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS?wsdl',
|
11
12
|
wsse_auth: [username, password],
|
12
|
-
endpoint: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS'
|
13
|
+
endpoint: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS',
|
14
|
+
proxy: proxy)
|
13
15
|
end
|
14
16
|
|
15
17
|
def send_notifications(notifications)
|
@@ -17,11 +19,15 @@ module ApraService
|
|
17
19
|
raise ArgumentError, 'notifications object must be either a Notification object or an array of Notification objects' unless
|
18
20
|
(notifications.is_a? Notification or (notifications.is_a? Array and notifications.detect {|n| !n.is_a? Notification}.nil?))
|
19
21
|
notifications = [notifications] unless notifications.is_a? Array
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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?
|
27
|
+
Response.from_hash(response.body)
|
28
|
+
else
|
29
|
+
Response.new
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
|
data/lib/apralib/grantee.rb
CHANGED
@@ -2,8 +2,8 @@ module ApraService
|
|
2
2
|
|
3
3
|
class Grantee
|
4
4
|
|
5
|
-
SSN_REGEX = /(\d{6})([-+A])(\d{3})([0-9ABCDEFHJKLMNPRSTUVWXY])
|
6
|
-
CHECK_DIGITS = %w
|
5
|
+
SSN_REGEX = /(\d{6})([-+A])(\d{3})([0-9ABCDEFHJKLMNPRSTUVWXY])/.freeze
|
6
|
+
CHECK_DIGITS = %w[0 1 2 3 4 5 6 7 8 9 A B C D E F H J K L M N P R S T U V W X Y].freeze
|
7
7
|
|
8
8
|
attr_accessor :first_names, :last_name, :ssn, :address, :zip
|
9
9
|
|
@@ -26,16 +26,20 @@ module ApraService
|
|
26
26
|
grantee.address = hash[:apurahansaajanosoite]
|
27
27
|
grantee.zip = hash[:apurahansaajanpostinumero]
|
28
28
|
grantee.first_names = [hash[:etunimi1]]
|
29
|
-
grantee.
|
30
|
-
grantee.
|
29
|
+
grantee.first_names << hash[:etunimi2] if hash[:etunimi2]
|
30
|
+
grantee.first_names << hash[:etunimi3] if hash[:etunimi3]
|
31
31
|
grantee.ssn = hash[:henkilotunnus]
|
32
32
|
grantee.last_name = hash[:sukunimi]
|
33
33
|
grantee
|
34
34
|
end
|
35
35
|
|
36
36
|
def ssn=(ssn)
|
37
|
-
|
38
|
-
|
37
|
+
if ssn
|
38
|
+
Grantee.verify_ssn!(ssn.upcase)
|
39
|
+
self.instance_variable_set('@ssn', ssn.upcase)
|
40
|
+
else
|
41
|
+
self.instance_variable_set('@ssn', nil)
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def self.verify_ssn!(ssn)
|
data/lib/apralib/response.rb
CHANGED
@@ -4,6 +4,10 @@ module ApraService
|
|
4
4
|
|
5
5
|
attr_accessor :failed_notifications
|
6
6
|
|
7
|
+
def initialize
|
8
|
+
@failed_notifications = []
|
9
|
+
end
|
10
|
+
|
7
11
|
|
8
12
|
def self.from_hash(hash)
|
9
13
|
puts hash.inspect
|
@@ -13,8 +17,6 @@ module ApraService
|
|
13
17
|
if failures
|
14
18
|
failures = [failures] unless failures.is_a? Array
|
15
19
|
response.failed_notifications = failures.map {|notification| NotificationResponse.from_hash(notification) }
|
16
|
-
else
|
17
|
-
response.failed_notifications = []
|
18
20
|
end
|
19
21
|
response
|
20
22
|
end
|
data/lib/apralib/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'apralib'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
module ApraService
|
5
6
|
|
@@ -9,10 +10,11 @@ module ApraService
|
|
9
10
|
def get_client
|
10
11
|
credentials = {}
|
11
12
|
credentials_file = File.join(File.dirname(__FILE__), 'apra_credentials.yml')
|
12
|
-
credentials = YAML.load(File.read(credentials_file)) if File.
|
13
|
+
credentials = YAML.load(File.read(credentials_file)) if File.exist?(credentials_file)
|
13
14
|
user = credentials['user'] || ENV['APRA_USER']
|
14
15
|
password = credentials['password'] || ENV['APRA_PASSWORD']
|
15
|
-
|
16
|
+
proxy = credentials['proxy'] || ENV['PROXY_URL']
|
17
|
+
Client.new(user, password, proxy)
|
16
18
|
end
|
17
19
|
|
18
20
|
|
@@ -20,11 +22,15 @@ module ApraService
|
|
20
22
|
|
21
23
|
it 'should create a valid object' do
|
22
24
|
|
23
|
-
service = Client.new('user','password')
|
25
|
+
service = Client.new('user', 'password')
|
24
26
|
expect(service).not_to be_nil
|
25
27
|
|
26
28
|
end
|
27
29
|
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'send_notifications' do
|
33
|
+
|
28
34
|
it 'should send the notification to the server' do
|
29
35
|
|
30
36
|
service = get_client
|
@@ -71,7 +77,12 @@ module ApraService
|
|
71
77
|
expect(notification_response.notification.reference).to eq(notification.reference)
|
72
78
|
end
|
73
79
|
|
74
|
-
|
80
|
+
it 'should return an empty response when an empty array is passed' do
|
81
|
+
service = get_client
|
82
|
+
response = service.send_notifications([])
|
83
|
+
expect(response).not_to be_nil
|
84
|
+
expect(response.failed_notifications.count).to eq(0)
|
85
|
+
end
|
75
86
|
|
76
87
|
|
77
88
|
end
|
data/spec/lib/grantee_spec.rb
CHANGED
@@ -22,6 +22,28 @@ module ApraService
|
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
+
describe 'ssn=' do
|
26
|
+
|
27
|
+
it 'should convert the code to uppercase' do
|
28
|
+
|
29
|
+
grantee = Grantee.new
|
30
|
+
grantee.ssn = '111111-111c'
|
31
|
+
expect(grantee.ssn).to eq('111111-111C')
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set the value to nil when passed a nil value' do
|
36
|
+
|
37
|
+
grantee = Grantee.new
|
38
|
+
grantee.ssn = '111111-111C'
|
39
|
+
grantee.ssn = nil
|
40
|
+
expect(grantee.ssn).to be_nil
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|
25
47
|
end
|
26
48
|
|
27
49
|
end
|
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.0
|
4
|
+
version: 0.1.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:
|
11
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '11.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "<"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '11.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.10.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
54
|
+
version: 3.10.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.
|
75
|
+
version: 2.12.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.
|
82
|
+
version: 2.12.0
|
83
83
|
description: A Ruby client for the Apra Service
|
84
84
|
email:
|
85
85
|
- nessche@gmail.com
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
91
92
|
- ".travis.yml"
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
@@ -116,15 +117,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
117
|
requirements:
|
117
118
|
- - ">="
|
118
119
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
120
|
+
version: 2.4.0
|
120
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
122
|
requirements:
|
122
123
|
- - ">="
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.2.2
|
127
|
+
rubygems_version: 3.0.8
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: A Ruby library to submit documents to the Apra Service run by Maatalousyrittäjien
|
@@ -133,4 +133,3 @@ test_files:
|
|
133
133
|
- spec/lib/apra_service_spec.rb
|
134
134
|
- spec/lib/grantee_spec.rb
|
135
135
|
- spec/spec_helper.rb
|
136
|
-
has_rdoc:
|