abgabenrechner 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in abgabenrechner.gemspec
4
+ gemspec
5
+ gem 'rspec'
6
+ gem 'libxml-ruby'
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ abgabenrechner (0.2.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ libxml-ruby (2.0.6)
11
+ rspec (2.6.0)
12
+ rspec-core (~> 2.6.0)
13
+ rspec-expectations (~> 2.6.0)
14
+ rspec-mocks (~> 2.6.0)
15
+ rspec-core (2.6.3)
16
+ rspec-expectations (2.6.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.6.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ abgabenrechner!
25
+ libxml-ruby
26
+ rspec
data/README.markdown ADDED
@@ -0,0 +1,66 @@
1
+ # abgabenrechner
2
+
3
+ abgabenrechner.gem ist ein ruby wrapper für die api des Bundesministerium der Finanzen.
4
+ http://www.abgabenrechner.de/interface/
5
+
6
+
7
+ ## Installation
8
+ Add this line to your Gemfile:
9
+
10
+ ```
11
+ gem 'abgabenrechner'
12
+ ```
13
+
14
+
15
+
16
+ ```ruby
17
+ require 'rubygems'
18
+ require 'abgabenrechner'
19
+
20
+ parameter = {
21
+ :lzz => 1,
22
+ :re4 => 2600000,
23
+ :stkl => 1,
24
+ :r => 1
25
+ }
26
+
27
+ abgabenrechner = BMF::Abgabenrechner.new(parameter)
28
+ puts abgabenrechner.ausgaben.inspect # => {:solzs=>0, :bk=>313700, :solzv=>0, :bks=>0, :sts=>0, :bkv=>0, :stv=>0, :lstlzz=>313700, :solzlzz=>17253}
29
+ puts abgabenrechner.ausgaben[:lstlzz] # => 313700
30
+
31
+ puts abgabenrechner.xml =>
32
+ ```
33
+ ```xml
34
+ <lohnsteuer jahr="2011">
35
+ <eingaben>
36
+ <eingabe name="R" value="1" status="ok" />
37
+ <eingabe name="STKL" value="1" status="ok" />
38
+ <eingabe name="RE4" value="2600000" status="ok" />
39
+ <eingabe name="LZZ" value="1" status="ok" />
40
+ </eingaben>
41
+ <ausgaben>
42
+ <ausgabe name="BK" value="313700" />
43
+ <ausgabe name="BKS" value="0" />
44
+ <ausgabe name="BKV" value="0" />
45
+ <ausgabe name="LSTLZZ" value="313700" />
46
+ <ausgabe name="SOLZLZZ" value="17253" />
47
+ <ausgabe name="SOLZS" value="0" />
48
+ <ausgabe name="SOLZV" value="0" />
49
+ <ausgabe name="STS" value="0" />
50
+ <ausgabe name="STV" value="0" />
51
+ </ausgaben>
52
+ </lohnsteuer>
53
+ ```
54
+
55
+
56
+
57
+
58
+ ## Komplette API Dokumentation:
59
+ http://goo.gl/phFdj
60
+
61
+
62
+
63
+
64
+
65
+
66
+ Copyright (c) 2011 Felix Faerber. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,19 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "abgabenrechner"
8
- gem.summary = "One line summary of your gem"
9
- gem.description = "german tax calculator"
10
- gem.email = "mail@felixfaerber.de"
11
- gem.homepage = "http://github.com/ffaerber/abgabenrechner"
12
- gem.authors = ["Felix Faerber"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -1,53 +1,21 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "abgabenrechner/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{abgabenrechner}
8
- s.version = "0.1.1"
6
+ s.name = "abgabenrechner"
7
+ s.version = Abgabenrechner::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Felix Faerber"]
10
+ s.email = ["mail@ffaerber.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{abgabenrechner.gem ist ein wrapper für diese api www.abgabenrechner.de/interface/}
13
+ s.description = %q{mehr information über die möglichen ein-und ausgabewerte ist hier zu finden: http://goo.gl/phFdj}
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Felix Faerber"]
12
- s.date = %q{2010-06-18}
13
- s.description = %q{german tax calculator}
14
- s.email = %q{mail@felixfaerber.de}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".gitignore",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "abgabenrechner.gemspec",
26
- "lib/abgabenrechner.rb",
27
- "test/helper.rb",
28
- "test/test_abgabenrechner.rb"
29
- ]
30
- s.homepage = %q{http://github.com/ffaerber/abgabenrechner}
31
- s.rdoc_options = ["--charset=UTF-8"]
32
- s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.6}
34
- s.summary = %q{One line summary of your gem}
35
- s.test_files = [
36
- "test/helper.rb",
37
- "test/test_abgabenrechner.rb"
38
- ]
39
-
40
- if s.respond_to? :specification_version then
41
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
- s.specification_version = 3
15
+ s.rubyforge_project = "abgabenrechner"
43
16
 
44
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
46
- else
47
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
48
- end
49
- else
50
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
- end
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
52
21
  end
53
-
@@ -0,0 +1,3 @@
1
+ module Abgabenrechner
2
+ VERSION = "0.2.0"
3
+ end
@@ -1,60 +1,77 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
- require 'rexml/document'
3
+ require 'xml/libxml'
4
+
5
+
4
6
 
5
7
 
6
8
  module BMF
7
- class Abgabenrechner
8
-
9
+ class Abgabenrechner
10
+
11
+ attr_accessor :xml
9
12
 
10
- def initialize(argv)
11
-
12
-
13
- @year = argv[:year] # Jahr
14
- @lzz = argv[:lzz] # Lohnzahlungszeitraum
15
- @re4 = argv[:re4] # Einkommen
16
- @stkl = argv[:stkl] # Steuerklasse
13
+
14
+ def initialize(values)
15
+ @year = Time.new.year
17
16
 
17
+ url_params = []
18
+ values.keys.each do | value |
19
+ if value.to_s == "year"
20
+ @year = values[value]
21
+ else
22
+ url_params << "&#{value.to_s.upcase}=#{values[value]}"
23
+ end
24
+ end
18
25
 
26
+ @url_path = "/interface/#{@year}.jsp?#{url_params.join}"
19
27
  @http = Net::HTTP.new("www.abgabenrechner.de", 443)
20
28
  @http.use_ssl = true
29
+
30
+ resp, @xml = @http.get(@url_path, nil)
31
+ cookie = resp.response['set-cookie']
21
32
  end
22
33
 
23
34
 
24
35
 
25
- def array_to_hash(array)
26
- count = 0
27
- hash = Hash.new
28
- (array.length / 2).times do
29
- hash[array[count]] = array[count+1]
30
- count += 2
31
- end
32
- return hash
36
+ def ausgaben
37
+ parser = XML::SaxParser.string(@xml)
38
+ parser.callbacks = Saxparser.new
39
+ parser.parse
40
+ return parser.callbacks.ausgaben
33
41
  end
34
-
35
-
36
-
37
- def run
38
- path = "/interface/#{@year}.jsp?LZZ=#{@lzz}&RE4=#{@re4}&STKL=#{@stkl}"
42
+
43
+ end
44
+
45
+
46
+
47
+
48
+ class Saxparser
49
+ include XML::SaxParser::Callbacks
50
+ Ausgabe = Struct.new(:name, :value)
51
+ attr_accessor :ausgaben
52
+
53
+ def on_start_document
54
+ @ausgaben = Hash.new()
55
+ end
56
+
57
+
58
+ def on_start_element(element, attributes)
59
+ if element == 'ausgabe'
60
+ @ausgaben.store(attributes['name'].downcase.to_sym, attributes['value'].to_i )
61
+ end
62
+ end
63
+
64
+ def on_end_document
65
+ return @ausgaben
66
+ end
67
+
68
+ end
69
+
70
+
71
+
72
+
73
+
74
+ end
39
75
 
40
- # GET request -> so the host can set his cookies
41
- resp, data = @http.get(path, nil)
42
- cookie = resp.response['set-cookie']
43
76
 
44
77
 
45
- ausgaben = Array.new()
46
-
47
- doc = REXML::Document.new(data)
48
- doc.elements.each('lohnsteuer/ausgaben/ausgabe') do |ele|
49
- ausgaben << ele.attributes['name']
50
- ausgaben << ele.attributes['value']
51
- end
52
-
53
- array_to_hash(ausgaben)
54
-
55
- end
56
-
57
-
58
-
59
- end
60
- end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ describe Abgabenrechner do
3
+
4
+
5
+ it "Simple API call with HASH feedback" do
6
+ parameter = { :lzz => 1, :re4 => 2600000, :stkl => 1 }
7
+ BMF::Abgabenrechner.new(parameter).hash
8
+ end
9
+
10
+
11
+ it "Simple API call with XML feedback" do
12
+ parameter = { :lzz => 1, :re4 => 2600000, :stkl => 1 }
13
+ BMF::Abgabenrechner.new(parameter).xml
14
+ end
15
+
16
+
17
+
18
+ it "API call with HASH feedback" do
19
+
20
+ parameter = {
21
+ :lzz => 1,
22
+ :re4 => 2600000,
23
+ :stkl => 1,
24
+ :r => 1
25
+ }
26
+
27
+ abgabenrechner = BMF::Abgabenrechner.new(parameter)
28
+ puts abgabenrechner.ausgaben.inspect
29
+
30
+ end
31
+
32
+
33
+
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'abgabenrechner'
4
+
5
+ RSpec.configure do |config|
6
+ # some (optional) config here
7
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abgabenrechner
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Felix Faerber
@@ -14,70 +15,64 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-18 00:00:00 +02:00
18
+ date: 2011-07-24 00:00:00 +02:00
18
19
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :development
31
- version_requirements: *id001
32
- description: german tax calculator
33
- email: mail@felixfaerber.de
20
+ dependencies: []
21
+
22
+ description: "mehr information \xC3\xBCber die m\xC3\xB6glichen ein-und ausgabewerte ist hier zu finden: http://goo.gl/phFdj"
23
+ email:
24
+ - mail@ffaerber.com
34
25
  executables: []
35
26
 
36
27
  extensions: []
37
28
 
38
- extra_rdoc_files:
39
- - LICENSE
40
- - README.rdoc
29
+ extra_rdoc_files: []
30
+
41
31
  files:
42
32
  - .gitignore
43
- - LICENSE
44
- - README.rdoc
33
+ - Gemfile
34
+ - Gemfile.lock
35
+ - README.markdown
45
36
  - Rakefile
46
- - VERSION
47
37
  - abgabenrechner.gemspec
48
38
  - lib/abgabenrechner.rb
49
- - test/helper.rb
50
- - test/test_abgabenrechner.rb
39
+ - lib/abgabenrechner/version.rb
40
+ - spec/abgabenrechner_spec.rb
41
+ - spec/spec_helper.rb
51
42
  has_rdoc: true
52
- homepage: http://github.com/ffaerber/abgabenrechner
43
+ homepage: ""
53
44
  licenses: []
54
45
 
55
46
  post_install_message:
56
- rdoc_options:
57
- - --charset=UTF-8
47
+ rdoc_options: []
48
+
58
49
  require_paths:
59
50
  - lib
60
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
61
53
  requirements:
62
54
  - - ">="
63
55
  - !ruby/object:Gem::Version
56
+ hash: 3
64
57
  segments:
65
58
  - 0
66
59
  version: "0"
67
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
68
62
  requirements:
69
63
  - - ">="
70
64
  - !ruby/object:Gem::Version
65
+ hash: 3
71
66
  segments:
72
67
  - 0
73
68
  version: "0"
74
69
  requirements: []
75
70
 
76
- rubyforge_project:
77
- rubygems_version: 1.3.6
71
+ rubyforge_project: abgabenrechner
72
+ rubygems_version: 1.5.2
78
73
  signing_key:
79
74
  specification_version: 3
80
- summary: One line summary of your gem
75
+ summary: "abgabenrechner.gem ist ein wrapper f\xC3\xBCr diese api www.abgabenrechner.de/interface/"
81
76
  test_files:
82
- - test/helper.rb
83
- - test/test_abgabenrechner.rb
77
+ - spec/abgabenrechner_spec.rb
78
+ - spec/spec_helper.rb
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Felix Faerber
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = abgabenrechner
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Felix Faerber. See LICENSE for details.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'abgabenrechner'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestAbgabenrechner < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end