kontoapi-ruby 0.0.1 → 0.1.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.
- data/Gemfile +2 -1
- data/Gemfile.lock +4 -2
- data/VERSION +1 -1
- data/kontoapi-ruby.gemspec +71 -0
- data/lib/kontoapi-ruby.rb +10 -6
- data/spec/kontoapi-ruby_spec.rb +57 -3
- data/spec/spec_helper.rb +1 -0
- metadata +22 -9
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,12 +3,12 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
addressable (2.2.5)
|
5
5
|
diff-lcs (1.1.2)
|
6
|
+
fakeweb (1.3.0)
|
6
7
|
git (1.2.5)
|
7
8
|
jeweler (1.5.2)
|
8
9
|
bundler (~> 1.0.0)
|
9
10
|
git (>= 1.2.5)
|
10
11
|
rake
|
11
|
-
nibbler (1.2.1)
|
12
12
|
rake (0.8.7)
|
13
13
|
rcov (0.9.9)
|
14
14
|
rspec (2.3.0)
|
@@ -19,6 +19,7 @@ GEM
|
|
19
19
|
rspec-expectations (2.3.0)
|
20
20
|
diff-lcs (~> 1.1.2)
|
21
21
|
rspec-mocks (2.3.0)
|
22
|
+
yajl-ruby (0.8.2)
|
22
23
|
|
23
24
|
PLATFORMS
|
24
25
|
ruby
|
@@ -26,7 +27,8 @@ PLATFORMS
|
|
26
27
|
DEPENDENCIES
|
27
28
|
addressable
|
28
29
|
bundler (~> 1.0.0)
|
30
|
+
fakeweb
|
29
31
|
jeweler (~> 1.5.2)
|
30
|
-
nibbler (>= 1.2.0)
|
31
32
|
rcov
|
32
33
|
rspec (~> 2.3.0)
|
34
|
+
yajl-ruby
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{kontoapi-ruby}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jan Schwenzien"]
|
12
|
+
s.date = %q{2011-04-18}
|
13
|
+
s.description = %q{A ruby library to access the Konto API (https://www.kontoapi.de/), a webservice that performs validity checks and other services regarding german bank accounts.}
|
14
|
+
s.email = %q{jan@general-scripting.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"kontoapi-ruby.gemspec",
|
27
|
+
"lib/kontoapi-ruby.rb",
|
28
|
+
"spec/kontoapi-ruby_spec.rb",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/GeneralScripting/kontoapi-ruby}
|
32
|
+
s.licenses = ["MIT"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.7.2}
|
35
|
+
s.summary = %q{Konto API Ruby Library}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/kontoapi-ruby_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
50
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
54
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
63
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/lib/kontoapi-ruby.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'addressable/uri'
|
2
|
+
require 'yajl/json_gem'
|
2
3
|
require 'net/http'
|
3
4
|
require 'net/https'
|
4
5
|
|
@@ -27,13 +28,15 @@ module KontoAPI
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def valid?(account_number, bank_code)
|
30
|
-
|
31
|
-
response
|
31
|
+
return false if account_number.to_s.strip.empty? || bank_code.to_s.strip.empty?
|
32
|
+
response = ask_for(:validity, { :ktn => account_number.to_s, :blz => bank_code.to_s })
|
33
|
+
response['answer'].eql?('yes')
|
32
34
|
end
|
33
35
|
|
34
36
|
def bank_name(bank_code)
|
35
|
-
|
36
|
-
response
|
37
|
+
return nil if bank_code.to_s.strip.empty?
|
38
|
+
response = ask_for(:bankname, { :blz => bank_code.to_s })
|
39
|
+
response['answer'].empty? ? nil : response['answer']
|
37
40
|
end
|
38
41
|
|
39
42
|
|
@@ -46,7 +49,7 @@ module KontoAPI
|
|
46
49
|
options.merge!( :key => api_key )
|
47
50
|
url.query_values = options
|
48
51
|
body = get_url(url)
|
49
|
-
|
52
|
+
JSON.parse(body)
|
50
53
|
end
|
51
54
|
|
52
55
|
def get_url(url)
|
@@ -56,7 +59,8 @@ module KontoAPI
|
|
56
59
|
# TODO include certs and enable SSL verification
|
57
60
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
58
61
|
response = http.get url.request_uri, 'User-agent' => 'Konto API Ruby Client'
|
59
|
-
|
62
|
+
case response
|
63
|
+
when Net::HTTPSuccess, Net::HTTPOK
|
60
64
|
response.body
|
61
65
|
else
|
62
66
|
response.error!
|
data/spec/kontoapi-ruby_spec.rb
CHANGED
@@ -1,7 +1,61 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
3
|
+
describe "KontoAPI" do
|
4
|
+
|
5
|
+
it "should raise if no api key was provided" do
|
6
|
+
lambda { KontoAPI::valid?('1234567', '12312312') }.should raise_error(RuntimeError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise if api key is invalid" do
|
10
|
+
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/validity.json?.*|, :body => '{"error":"unauthenticated"}', :status => ["401", "Unauthorized"])
|
11
|
+
KontoAPI::api_key = 'abc123'
|
12
|
+
lambda { KontoAPI::valid?('1234567', '12312312') }.should raise_error(Net::HTTPServerException)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "checking validity" do
|
16
|
+
|
17
|
+
it "should return false if account number or bank code are empty" do
|
18
|
+
KontoAPI::valid?(nil, nil).should be_false
|
19
|
+
KontoAPI::valid?('123', nil).should be_false
|
20
|
+
KontoAPI::valid?(nil, '123').should be_false
|
21
|
+
KontoAPI::valid?('', '').should be_false
|
22
|
+
KontoAPI::valid?('123', '').should be_false
|
23
|
+
KontoAPI::valid?('', '123').should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return true for successfull validity checks" do
|
27
|
+
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/validity.json?.*|, :body => '{"answer":"yes"}')
|
28
|
+
KontoAPI::api_key = 'abc123'
|
29
|
+
KontoAPI::valid?('correct_account_number', '12312312').should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return false for unsuccessfull validity checks" do
|
33
|
+
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/validity.json?.*|, :body => '{"answer":"no"}')
|
34
|
+
KontoAPI::api_key = 'abc123'
|
35
|
+
KontoAPI::valid?('incorrect_account_number', '12312312').should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "getting bank names" do
|
41
|
+
|
42
|
+
it "should return nil if no bank code was provided" do
|
43
|
+
KontoAPI::bank_name(nil).should be_nil
|
44
|
+
KontoAPI::bank_name('').should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil if no bank was found" do
|
48
|
+
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/bankname.json?.*|, :body => '{"answer":""}')
|
49
|
+
KontoAPI::api_key = 'abc123'
|
50
|
+
KontoAPI::bank_name('12312312').should be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return Postbank for bank code 10010010" do
|
54
|
+
FakeWeb.register_uri(:get, %r|https://ask\.kontoapi\.de/for/bankname.json?.*|, :body => '{"answer":"Postbank"}')
|
55
|
+
KontoAPI::api_key = 'abc123'
|
56
|
+
KontoAPI::bank_name('10010010').should == "Postbank"
|
57
|
+
end
|
58
|
+
|
6
59
|
end
|
60
|
+
|
7
61
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
4
|
require 'kontoapi-ruby'
|
5
|
+
require 'fakeweb'
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontoapi-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan Schwenzien
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-18 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: addressable
|
@@ -32,19 +32,17 @@ dependencies:
|
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: yajl-ruby
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
hash:
|
42
|
+
hash: 3
|
43
43
|
segments:
|
44
|
-
- 1
|
45
|
-
- 2
|
46
44
|
- 0
|
47
|
-
version:
|
45
|
+
version: "0"
|
48
46
|
type: :runtime
|
49
47
|
version_requirements: *id002
|
50
48
|
- !ruby/object:Gem::Dependency
|
@@ -109,6 +107,20 @@ dependencies:
|
|
109
107
|
version: "0"
|
110
108
|
type: :development
|
111
109
|
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fakeweb
|
112
|
+
prerelease: false
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
type: :development
|
123
|
+
version_requirements: *id007
|
112
124
|
description: A ruby library to access the Konto API (https://www.kontoapi.de/), a webservice that performs validity checks and other services regarding german bank accounts.
|
113
125
|
email: jan@general-scripting.com
|
114
126
|
executables: []
|
@@ -125,6 +137,7 @@ files:
|
|
125
137
|
- README.markdown
|
126
138
|
- Rakefile
|
127
139
|
- VERSION
|
140
|
+
- kontoapi-ruby.gemspec
|
128
141
|
- lib/kontoapi-ruby.rb
|
129
142
|
- spec/kontoapi-ruby_spec.rb
|
130
143
|
- spec/spec_helper.rb
|