iban_client 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0fa08c6d9600a3514e1f918e946720d5cee99b9
4
+ data.tar.gz: d4e5ee0bdd74451b80edf18209a5869f77dd5083
5
+ SHA512:
6
+ metadata.gz: a48569faf547dac2eb5284a5253eb1867262227104541aff0bdfee32e4ab3c606a545e9245cfd670859488a8006c1195f7f79a3c744d8131088439a063884e56
7
+ data.tar.gz: eeea6eb87bfc230045b6837adc1e5d19d635f8fa0d5041a301bebb7d388fa7c8b180c71f9d396f2a7a913ac6429a42a6e732ffa5ffdd614fabbd8be79e2471af
@@ -0,0 +1,41 @@
1
+ module IbanClient
2
+ class Error < StandardError
3
+ attr_reader :iban
4
+
5
+ def initialize(iban:)
6
+ @iban = iban
7
+ end
8
+ end
9
+
10
+ class RequestError < Error
11
+ attr_reader :initial_error
12
+
13
+ def initialize(iban:, initial_error:)
14
+ @initial_error = initial_error
15
+ super(iban: iban)
16
+ end
17
+
18
+ def message
19
+ "#{initial_error.message}\n"\
20
+ "Request iban: #{iban}\n"\
21
+ "Response: #{initial_error.response}"
22
+ end
23
+ end
24
+
25
+ class AccountError < Error
26
+ attr_reader :errors
27
+
28
+ def initialize(iban:, errors:)
29
+ @errors = errors
30
+ super(iban: iban)
31
+ end
32
+
33
+ def code
34
+ errors.first['code']
35
+ end
36
+
37
+ def message
38
+ "#{errors.first['message']} (#{code})"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,79 @@
1
+ module IbanClient
2
+ class Iban
3
+ BANK_DATA_GETTER = %w(bic bank address city state zip country country_iso account)
4
+ SEPA_DATA_GETTER = %w(sct sdd cor1 b2b scc)
5
+
6
+ VALIDATION_MESSAGES = {
7
+ '201' => :invalid_account_number,
8
+ '202' => :invalid_iban_digit,
9
+ '203' => :invalid_iban_length,
10
+ '205' => :invalid_iban_structure
11
+ }
12
+
13
+ attr_reader :iban
14
+
15
+ def initialize(iban)
16
+ @iban = iban
17
+ end
18
+
19
+ BANK_DATA_GETTER.each do |attribute|
20
+ define_method(attribute) do
21
+ handle_result { (result['bank_data'] || [])[attribute] }
22
+ end
23
+ end
24
+
25
+ SEPA_DATA_GETTER.each do |attribute|
26
+ define_method("#{attribute}?") do
27
+ handle_result { (result['sepa_data'] || [])[attribute.upcase] == 'YES' }
28
+ end
29
+ end
30
+
31
+ def attributes
32
+ handle_result { (result['bank_data'] || {}).merge('iban' => iban) }
33
+ end
34
+
35
+ def valid?
36
+ errors.empty?
37
+ end
38
+
39
+ def errors
40
+ handle_result do
41
+ (result['validations'] || []).map { |validation| VALIDATION_MESSAGES[validation['code']] }
42
+ .reject(&:nil?)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def request
49
+ RestClient::Request.execute(
50
+ method: :get,
51
+ url: "#{IbanClient.api_base}?#{params}",
52
+ timeout: IbanClient.timeout
53
+ )
54
+ rescue RestClient::ExceptionWithResponse => err
55
+ raise IbanClient::RequestError.new(iban: iban, initial_error: err)
56
+ end
57
+
58
+ def params
59
+ URI.encode_www_form(
60
+ format: :json,
61
+ api_key: IbanClient.api_key,
62
+ iban: iban
63
+ )
64
+ end
65
+
66
+ def result
67
+ @result ||= JSON.parse(request)
68
+ end
69
+
70
+ def api_errors
71
+ result['errors']
72
+ end
73
+
74
+ def handle_result(&block)
75
+ raise IbanClient::AccountError.new(iban: iban, errors: api_errors) if api_errors.count > 0
76
+ yield
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module IbanClient
2
+ VERSION = '0.0.3'
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ require 'iban_client/errors'
6
+ require 'iban_client/iban'
7
+
8
+ module IbanClient
9
+ @api_base = 'https://api.iban.com/clients/api/ibanv2.php'
10
+ @timeout = 10
11
+
12
+ class << self
13
+ attr_accessor :api_key, :timeout
14
+ attr_reader :api_base
15
+ end
16
+
17
+ def self.config
18
+ yield self if block_given?
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iban_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Vincent Pochet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
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'
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Wrapper for the Iban.com API
126
+ email: vincent@qonto.eu
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - lib/iban_client.rb
132
+ - lib/iban_client/errors.rb
133
+ - lib/iban_client/iban.rb
134
+ - lib/iban_client/version.rb
135
+ homepage: https://github.com/qonto/iban-client
136
+ licenses:
137
+ - WTFPL
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '2.2'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.8.11
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.5.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Iban.com client
159
+ test_files: []