apralib 0.0.1
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 +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +10 -0
- data/apralib.gemspec +26 -0
- data/lib/apralib/apra_service.rb +32 -0
- data/lib/apralib/grantee.rb +63 -0
- data/lib/apralib/notification.rb +79 -0
- data/lib/apralib/notification_response.rb +23 -0
- data/lib/apralib/response.rb +28 -0
- data/lib/apralib/version.rb +3 -0
- data/lib/apralib.rb +8 -0
- data/spec/lib/apra_service_spec.rb +86 -0
- data/spec/lib/grantee_spec.rb +27 -0
- data/spec/spec_helper.rb +11 -0
- metadata +136 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 59af58d7a0d079dec4dca4c1532b86e2663ac9e1
|
|
4
|
+
data.tar.gz: d6d076636dbf8ecff1f567fdb7a9415e5ae4fb80
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ddac87c831ebb1de2e417075b17c3d43f253af1bbbce7a609418a192311ed3cd562fec65b4319920ff88131d51c01cfaab656f74546fc063529b34d3e017bad2
|
|
7
|
+
data.tar.gz: f01b555e830993def27fcf61ea97e3add099707b84517777bb17d2047e8d0ed5aa1bed9bb38d5a72a74193bd42b7e0fe9a93c7fc6f6d4cd098800091bd7c3f98
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
rvm:
|
|
3
|
+
- 2.1.3
|
|
4
|
+
- 1.9.3
|
|
5
|
+
env:
|
|
6
|
+
global:
|
|
7
|
+
- secure: XQ58eL4HELhYo0x1RgzyLkAF+XCBzTZLe3NIs4qsc4wIbeIUWVxb6chm/8ikbQn8ndk06EsJrZV/HC08EebUtgb1WTGeaEhyJGdyTVThO2dbLc+wKdrrGcmxiZEd1N6pg0G+4l8QsvMCTWJts6ZhrvVtmle6izGPfF467hLWIjM=
|
|
8
|
+
- secure: FY5lZvsTluLglsk0j4c4rPXj0BqN80PVUzCLwFtBzhZJ/Dic8c6IGGDy91RQPoR11bcsqQgUhEOeTh0LEjmuGijZ1WIm0/0PynLZe2rxM76OA/ph5KKmYIgi5OLEkWJ8mQRLSeOqpw2BeaqW35MfhX6uItcJbEztiSgVkx01Y4g=
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Marco Sandrini
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Apralib
|
|
2
|
+
|
|
3
|
+
A Ruby library to submit documents to the Apra Service run by [Maatalousyrittäjien eläkelaitos](http://www.mela.fi)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'apralib'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install apralib
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
To use this gem you will need credentials from [Maatalousyrittäjien eläkelaitos](http://www.mela.fi).
|
|
22
|
+
|
|
23
|
+
Once you have obtained the credentials you can instantiate a client
|
|
24
|
+
|
|
25
|
+
ApraService::Client.new(username, password)
|
|
26
|
+
|
|
27
|
+
you can then create one or more notifications to be sent to the server
|
|
28
|
+
|
|
29
|
+
notification = Notification.new
|
|
30
|
+
grantee = Grantee.new
|
|
31
|
+
grantee.first_names='Teppo'
|
|
32
|
+
grantee.last_name = 'Taiteilija'
|
|
33
|
+
grantee.ssn = '111111-111C'
|
|
34
|
+
notification.grantee = grantee
|
|
35
|
+
notification.granted_to_group = false
|
|
36
|
+
notification.expense_amount = 0
|
|
37
|
+
notification.amount = 10000
|
|
38
|
+
notification.purpose = 'My grant purpose'
|
|
39
|
+
notification.grant_date = Date.today << 1
|
|
40
|
+
notification.reference = 'My project rede'
|
|
41
|
+
notification.work_duration_months = 1
|
|
42
|
+
notification.work_duration_days = 2
|
|
43
|
+
notification.work_duration_years = 3
|
|
44
|
+
notification.work_start_date = Date.today
|
|
45
|
+
notification.work_end_date = Date.today >> 1
|
|
46
|
+
service.send_notifications(notification)
|
|
47
|
+
|
|
48
|
+
As the information passed through the notification is dependent on the statutory earnings-related pension of those receiving
|
|
49
|
+
a grant or a scholarship from Finland, this readme does not explain the meaning of the different fields in the notification
|
|
50
|
+
object. For further information please refer to the [Mela website](http://www.mela.fi)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Contributing
|
|
54
|
+
|
|
55
|
+
1. Fork it
|
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
59
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/apralib.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'apralib/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'apralib'
|
|
8
|
+
spec.version = Apralib::VERSION
|
|
9
|
+
spec.authors = ['Marco Sandrini']
|
|
10
|
+
spec.email = ['nessche@gmail.com']
|
|
11
|
+
spec.description = %q{A Ruby client for the Apra Service}
|
|
12
|
+
spec.summary = %q{A Ruby library to submit documents to the Apra Service run by Maatalousyrittäjien eläkelaitos}
|
|
13
|
+
spec.homepage = 'https://github.com/nessche/apralib'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
|
22
|
+
spec.add_development_dependency 'rake'
|
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
|
24
|
+
spec.add_development_dependency 'yard'
|
|
25
|
+
spec.add_dependency 'savon', '~> 2.3.0'
|
|
26
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative 'notification'
|
|
2
|
+
require_relative 'response'
|
|
3
|
+
require 'savon'
|
|
4
|
+
|
|
5
|
+
module ApraService
|
|
6
|
+
|
|
7
|
+
class Client
|
|
8
|
+
|
|
9
|
+
def initialize(username, password)
|
|
10
|
+
@client = Savon.client(wsdl: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS?wsdl',
|
|
11
|
+
wsse_auth: [username, password],
|
|
12
|
+
endpoint: 'https://palvelu.mela.fi/Apurahailmoitukset/ws/apurahanSyottoWS')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def send_notifications(notifications)
|
|
16
|
+
raise ArgumentError, 'notifications object cannot be nil' unless notifications
|
|
17
|
+
raise ArgumentError, 'notifications object must be either a Notification object or an array of Notification objects' unless
|
|
18
|
+
(notifications.is_a? Notification or (notifications.is_a? Array and notifications.detect {|n| !n.is_a? Notification}.nil?))
|
|
19
|
+
notifications = [notifications] unless notifications.is_a? Array
|
|
20
|
+
message = {}
|
|
21
|
+
message[:arg0] = notifications.map {|notification| notification.to_hash}
|
|
22
|
+
response = @client.call(:lisaa_apurahat, :message => message)
|
|
23
|
+
raise RuntimeError, 'An error occurred while submitting the notification' unless response.success?
|
|
24
|
+
Response.from_hash(response.body)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module ApraService
|
|
2
|
+
|
|
3
|
+
class Grantee
|
|
4
|
+
|
|
5
|
+
SSN_REGEX = /(\d{6})([-+A])(\d{3})([0-9ABCDEFHJKLMNPRSTUVWXY])/
|
|
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 X Y)
|
|
7
|
+
|
|
8
|
+
attr_accessor :first_names, :last_name, :ssn, :address, :zip
|
|
9
|
+
|
|
10
|
+
def to_hash
|
|
11
|
+
result = {}
|
|
12
|
+
result[:apurahansaajanosoite] = address if address
|
|
13
|
+
result[:apurahansaajanpostinumero] = zip if zip
|
|
14
|
+
first_names.split(' ')[0..2].each_with_index do |name, index|
|
|
15
|
+
result["etunimi#{index + 1}".to_sym] = name
|
|
16
|
+
end
|
|
17
|
+
result[:henkilotunnus] = ssn if ssn
|
|
18
|
+
result[:sukunimi] = last_name
|
|
19
|
+
|
|
20
|
+
result
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.from_hash(hash)
|
|
25
|
+
grantee = Grantee.new
|
|
26
|
+
grantee.address = hash[:apurahansaajanosoite]
|
|
27
|
+
grantee.zip = hash[:apurahansaajanpostinumero]
|
|
28
|
+
grantee.first_names = [hash[:etunimi1]]
|
|
29
|
+
grantee.first_name << hash[:etunimi2] if hash[:etunimi2]
|
|
30
|
+
grantee.first_name << hash[:etunimi3] if hash[:etunimi3]
|
|
31
|
+
grantee.ssn = hash[:henkilotunnus]
|
|
32
|
+
grantee.last_name = hash[:sukunimi]
|
|
33
|
+
grantee
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ssn=(ssn)
|
|
37
|
+
Grantee.verify_ssn!(ssn)
|
|
38
|
+
self.instance_variable_set('@ssn', ssn)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.verify_ssn!(ssn)
|
|
42
|
+
raise RuntimeError, 'The Social Security Number is not in the correct format' unless ssn =~ SSN_REGEX
|
|
43
|
+
big_number = "#{$1}#{$3}".to_i
|
|
44
|
+
check = CHECK_DIGITS[big_number % 31]
|
|
45
|
+
raise RuntimeError, "The check digit does not match, expected #{check}, got #{$4}" unless check == $4
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.verify_ssn(ssn)
|
|
49
|
+
begin
|
|
50
|
+
verify_ssn! ssn
|
|
51
|
+
true
|
|
52
|
+
rescue RuntimeError => e
|
|
53
|
+
puts e.message
|
|
54
|
+
false
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module ApraService
|
|
2
|
+
|
|
3
|
+
class Notification
|
|
4
|
+
|
|
5
|
+
attr_accessor :purpose, :purpose_description, :expense_amount, :expense_description,
|
|
6
|
+
:grant_date, :granted_to_group, :amount, :grantee, :work_start_date,
|
|
7
|
+
:work_end_date, :reference, :work_duration_months, :work_duration_days,
|
|
8
|
+
:work_duration_years, :ignore_work_duration
|
|
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]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@ignore_work_duration = false
|
|
16
|
+
@granted_to_group = false
|
|
17
|
+
@work_duration_days = 0
|
|
18
|
+
@work_duration_months = 0
|
|
19
|
+
@work_duration_years = 0
|
|
20
|
+
@expense_amount = 0
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_hash
|
|
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?
|
|
26
|
+
end
|
|
27
|
+
result = {}
|
|
28
|
+
result[:kayttotarkoitus] = purpose
|
|
29
|
+
result[:kayttotarkoitustarkenne] = purpose_description if purpose_description
|
|
30
|
+
result[:kuluosuusrahamaara] = expense_amount
|
|
31
|
+
result[:kuluosuusteksti] = expense_description if expense_description
|
|
32
|
+
result[:myontopaatoksen_antopvm] = grant_date.rfc3339
|
|
33
|
+
result[:onko_myonnetty_tyoryhmalle] = granted_to_group
|
|
34
|
+
result[:rahamaara] = amount
|
|
35
|
+
result[:saajatiedot] = grantee.to_hash
|
|
36
|
+
result[:sisaltaako_kuluja] = (expense_amount > 0)
|
|
37
|
+
|
|
38
|
+
if ignore_work_duration
|
|
39
|
+
result[:tyon_kesto_kuukausia] = 0
|
|
40
|
+
result[:tyon_kesto_paivia] = 0
|
|
41
|
+
result[:tyon_kesto_vuosia] = 0
|
|
42
|
+
else
|
|
43
|
+
result[:tyon_kesto_kuukausia] = work_duration_months
|
|
44
|
+
result[:tyon_kesto_paivia] = work_duration_days
|
|
45
|
+
result[:tyon_kesto_vuosia] = work_duration_years
|
|
46
|
+
end
|
|
47
|
+
result[:tyonkestoeikantaa] = ignore_work_duration
|
|
48
|
+
result[:tyoskentelyn_alkamispvm] = work_start_date.rfc3339 if work_start_date
|
|
49
|
+
result[:tyoskentelyn_paattymispvm] = work_end_date.rfc3339 if work_end_date
|
|
50
|
+
result[:viite] = reference
|
|
51
|
+
result
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.from_hash(hash)
|
|
56
|
+
notification = Notification.new
|
|
57
|
+
notification.purpose = hash[:kayttotarkoitus]
|
|
58
|
+
notification.purpose_description = hash[:kayttotarkoitustarkenne]
|
|
59
|
+
notification.expense_amount = hash[:kuluosuusrahamaara]
|
|
60
|
+
notification.expense_description = hash[:kuluosuusteksti]
|
|
61
|
+
notification.grant_date = hash[:myontopaatoksen_antopvm]
|
|
62
|
+
notification.granted_to_group = hash[:onko_myonnetty_tyoryhmalle]
|
|
63
|
+
notification.amount = hash[:rahamaara]
|
|
64
|
+
notification.grantee = Grantee.from_hash(hash[:saajatiedot])
|
|
65
|
+
notification.work_duration_months = hash[:tyon_kesto_kuukausia]
|
|
66
|
+
notification.work_duration_days = hash[:tyon_kesto_paivia]
|
|
67
|
+
notification.work_duration_years = hash[:tyon_kesto_vuosia]
|
|
68
|
+
notification.ignore_work_duration = hash[:tyonkestoeikantaa]
|
|
69
|
+
notification.work_start_date = hash[:tyoskentelyn_alkamispvm]
|
|
70
|
+
notification.work_end_date = hash[:tyoskentelyn_paattymispvm]
|
|
71
|
+
notification.reference = hash[:viite]
|
|
72
|
+
notification
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ApraService
|
|
2
|
+
|
|
3
|
+
class NotificationResponse
|
|
4
|
+
|
|
5
|
+
attr_accessor :notification, :error
|
|
6
|
+
|
|
7
|
+
def initialize(notification, error)
|
|
8
|
+
@notification = notification
|
|
9
|
+
@error = error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def self.from_hash(hash)
|
|
14
|
+
notification = Notification.from_hash(hash[:ilmoitus])
|
|
15
|
+
error = hash[:virhe]
|
|
16
|
+
NotificationResponse.new(notification, error)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module ApraService
|
|
2
|
+
|
|
3
|
+
class Response
|
|
4
|
+
|
|
5
|
+
attr_accessor :failed_notifications
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def self.from_hash(hash)
|
|
9
|
+
puts hash.inspect
|
|
10
|
+
response = Response.new
|
|
11
|
+
raw_response = hash[:lisaa_apurahat_response]
|
|
12
|
+
failures = raw_response[:epaonnistuneet_ilmoitukset]
|
|
13
|
+
if failures
|
|
14
|
+
failures = [failures] unless failures.is_a? Array
|
|
15
|
+
response.failed_notifications = failures.map {|notification| NotificationResponse.from_hash(notification) }
|
|
16
|
+
else
|
|
17
|
+
response.failed_notifications = []
|
|
18
|
+
end
|
|
19
|
+
response
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
end
|
data/lib/apralib.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'apralib'
|
|
3
|
+
|
|
4
|
+
module ApraService
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe 'Client' do
|
|
8
|
+
|
|
9
|
+
def get_client
|
|
10
|
+
credentials = {}
|
|
11
|
+
credentials_file = File.join(File.dirname(__FILE__), 'apra_credentials.yml')
|
|
12
|
+
credentials = YAML.load(File.read(credentials_file)) if File.exists?(credentials_file)
|
|
13
|
+
user = credentials['user'] || ENV['APRA_USER']
|
|
14
|
+
password = credentials['password'] || ENV['APRA_PASSWORD']
|
|
15
|
+
Client.new(user, password)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
describe 'initialize' do
|
|
20
|
+
|
|
21
|
+
it 'should create a valid object' do
|
|
22
|
+
|
|
23
|
+
service = Client.new('user','password')
|
|
24
|
+
expect(service).not_to be_nil
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should send the notification to the server' do
|
|
29
|
+
|
|
30
|
+
service = get_client
|
|
31
|
+
notification = Notification.new
|
|
32
|
+
grantee = Grantee.new
|
|
33
|
+
grantee.first_names='Teppo'
|
|
34
|
+
grantee.last_name = 'Taiteilija'
|
|
35
|
+
grantee.ssn = '111111-111C'
|
|
36
|
+
notification.grantee = grantee
|
|
37
|
+
notification.granted_to_group = false
|
|
38
|
+
notification.expense_amount = 0
|
|
39
|
+
notification.amount = 10000
|
|
40
|
+
notification.purpose = 'Patsaan rakentaminen'
|
|
41
|
+
notification.grant_date = Date.today << 1
|
|
42
|
+
notification.reference = SecureRandom.hex(16)
|
|
43
|
+
notification.work_duration_months = 1
|
|
44
|
+
notification.work_duration_days = 2
|
|
45
|
+
notification.work_duration_years = 3
|
|
46
|
+
notification.ignore_work_duration = true
|
|
47
|
+
notification.work_start_date = Date.today
|
|
48
|
+
notification.work_end_date = Date.today >> 1
|
|
49
|
+
notification1 = Notification.new
|
|
50
|
+
notification1.grantee = grantee
|
|
51
|
+
notification1.granted_to_group = false
|
|
52
|
+
notification1.expense_amount = 0
|
|
53
|
+
notification1.amount = 10000
|
|
54
|
+
notification1.purpose = 'Patsaan rakentaminen'
|
|
55
|
+
notification1.grant_date = Date.today << 1
|
|
56
|
+
notification1.reference = SecureRandom.hex(10)
|
|
57
|
+
notification1.work_duration_months = 1
|
|
58
|
+
notification1.work_duration_days = 2
|
|
59
|
+
notification1.work_duration_years = 3
|
|
60
|
+
notification1.ignore_work_duration = true
|
|
61
|
+
notification1.work_start_date = Date.today
|
|
62
|
+
notification1.work_end_date = Date.today >> 1
|
|
63
|
+
response = service.send_notifications([notification, notification1])
|
|
64
|
+
expect(response).not_to be_nil
|
|
65
|
+
failed_notifications = response.failed_notifications
|
|
66
|
+
expect(failed_notifications).not_to be_nil
|
|
67
|
+
expect(failed_notifications).to be_a Array
|
|
68
|
+
expect(failed_notifications.count).to eq(1)
|
|
69
|
+
notification_response = failed_notifications[0]
|
|
70
|
+
expect(notification_response.error).not_to be_nil
|
|
71
|
+
expect(notification_response.notification.reference).to eq(notification.reference)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'apralib'
|
|
3
|
+
|
|
4
|
+
module ApraService
|
|
5
|
+
|
|
6
|
+
describe 'Grantee' do
|
|
7
|
+
|
|
8
|
+
describe 'verify_ssn' do
|
|
9
|
+
|
|
10
|
+
it 'should return true when the ssn is valid' do
|
|
11
|
+
expect(Grantee.verify_ssn('111111-111C')).to be_truthy
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe 'verify_ssn!' do
|
|
18
|
+
|
|
19
|
+
it 'should not throw any exception when the ssn is valid' do
|
|
20
|
+
expect{Grantee.verify_ssn!('111111-111C')}.not_to raise_error
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# Requires supporting files with custom matchers and macros, etc,
|
|
5
|
+
# in ./support/ and its subdirectories.
|
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
7
|
+
|
|
8
|
+
RSpec.configure do |config|
|
|
9
|
+
config.color = true
|
|
10
|
+
config.formatter = 'documentation'
|
|
11
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: apralib
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Marco Sandrini
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 3.1.0
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 3.1.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: yard
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: savon
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 2.3.0
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 2.3.0
|
|
83
|
+
description: A Ruby client for the Apra Service
|
|
84
|
+
email:
|
|
85
|
+
- nessche@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".travis.yml"
|
|
92
|
+
- Gemfile
|
|
93
|
+
- LICENSE.txt
|
|
94
|
+
- README.md
|
|
95
|
+
- Rakefile
|
|
96
|
+
- apralib.gemspec
|
|
97
|
+
- lib/apralib.rb
|
|
98
|
+
- lib/apralib/apra_service.rb
|
|
99
|
+
- lib/apralib/grantee.rb
|
|
100
|
+
- lib/apralib/notification.rb
|
|
101
|
+
- lib/apralib/notification_response.rb
|
|
102
|
+
- lib/apralib/response.rb
|
|
103
|
+
- lib/apralib/version.rb
|
|
104
|
+
- spec/lib/apra_service_spec.rb
|
|
105
|
+
- spec/lib/grantee_spec.rb
|
|
106
|
+
- spec/spec_helper.rb
|
|
107
|
+
homepage: https://github.com/nessche/apralib
|
|
108
|
+
licenses:
|
|
109
|
+
- MIT
|
|
110
|
+
metadata: {}
|
|
111
|
+
post_install_message:
|
|
112
|
+
rdoc_options: []
|
|
113
|
+
require_paths:
|
|
114
|
+
- lib
|
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - ">="
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0'
|
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
requirements: []
|
|
126
|
+
rubyforge_project:
|
|
127
|
+
rubygems_version: 2.2.2
|
|
128
|
+
signing_key:
|
|
129
|
+
specification_version: 4
|
|
130
|
+
summary: A Ruby library to submit documents to the Apra Service run by Maatalousyrittäjien
|
|
131
|
+
eläkelaitos
|
|
132
|
+
test_files:
|
|
133
|
+
- spec/lib/apra_service_spec.rb
|
|
134
|
+
- spec/lib/grantee_spec.rb
|
|
135
|
+
- spec/spec_helper.rb
|
|
136
|
+
has_rdoc:
|