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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 59af58d7a0d079dec4dca4c1532b86e2663ac9e1
4
- data.tar.gz: d6d076636dbf8ecff1f567fdb7a9415e5ae4fb80
2
+ SHA256:
3
+ metadata.gz: 3b3256db49c369085a45a47586f7d225d6914a951f55baddb18b19d5385bf928
4
+ data.tar.gz: 9270c0ba4a7d6a228397f1d5439704808042e26f9dca5ce55c37686ce03f16b2
5
5
  SHA512:
6
- metadata.gz: ddac87c831ebb1de2e417075b17c3d43f253af1bbbce7a609418a192311ed3cd562fec65b4319920ff88131d51c01cfaab656f74546fc063529b34d3e017bad2
7
- data.tar.gz: f01b555e830993def27fcf61ea97e3add099707b84517777bb17d2047e8d0ed5aa1bed9bb38d5a72a74193bd42b7e0fe9a93c7fc6f6d4cd098800091bd7c3f98
6
+ metadata.gz: b05c78f9fed17951c19d6bffa5ad660a8f6f9ef693c87888e5c6767a1a47779b0a9ec87fd0ee2acb032441149ca553075e0356993ed8dd9ed418a864f718f084
7
+ data.tar.gz: b0c1081c67f7d9446b04f209fb5b0914470e7a36f7688f6e9d1d0e98e7f01bef640cd2c4299864d18599b8b49b716b9bca52ea389a4566c15f93f68d4d2e97b2
@@ -0,0 +1,3 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - spec/**/*.rb
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
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=
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
@@ -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.3'
22
- spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rspec', '~> 3.1.0'
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.3.0'
26
+ spec.add_dependency 'savon', '~> 2.12.0'
27
+
26
28
  end
@@ -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
- 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)
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
 
@@ -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(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)
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.first_name << hash[:etunimi2] if hash[:etunimi2]
30
- grantee.first_name << hash[:etunimi3] if hash[:etunimi3]
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
- Grantee.verify_ssn!(ssn)
38
- self.instance_variable_set('@ssn', ssn)
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Apralib
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'.freeze
3
3
  end
@@ -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.exists?(credentials_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
- Client.new(user, password)
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
@@ -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.1
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: 2014-10-02 00:00:00.000000000 Z
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.3'
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.3'
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.1.0
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.1.0
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.3.0
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.3.0
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: '0'
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
- rubyforge_project:
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: