julianus 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OThjMmY0MGIxZThiMDU1YTAxMDQ1MmFjMTNlOTZhNzEwODc5MzEwOA==
5
+ data.tar.gz: !binary |-
6
+ OTNmMDNlMDE3MzBmNGQxNGU5N2ZjMWJmOGRmMGRhZGU0OGNhZjU4Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Mzk0ZDAxYjBhYjA4YWE5ZGExOTZmMGEzYmM3ZjU4NjQzMWJiYTVlNThkMTUw
10
+ OGNjN2RlNGQwYzVjODBlMDBmYzA2NDU2ZjlhNGRkMzA0NTk2MmE3NzI0MDVh
11
+ NTc5MWE1OTQxNjNiNWY4MjMxM2FlZGY1N2RjM2UxM2Q4NDFmYWE=
12
+ data.tar.gz: !binary |-
13
+ OTVhMjdkYmFkY2YyYWExNDI0YmE0ZGZjNDZkYjhhMzU0Y2Q1MDM0YWRlOGRl
14
+ ZWM4NWIxOTk2MWUyMGIxZDNkMDM4YTg2MGExNWI2NDRhNTkzM2I5ZTk3ZTcy
15
+ MTQwYjZmZmYyMTFjZjY5ZTlkODMyMzU0ZTI3YmMzZTY5Nzg4Y2Y=
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ julianus
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in julianus.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'savon'
8
+ gem 'httpclient'
9
+ gem 'awesome_print'
10
+ gem 'airbrake'
11
+ gem "json"
12
+ gem 'rdoc'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mai-Liis Hütt & Desk Rock OÜ
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,40 @@
1
+ # Julianus
2
+
3
+ Julianus is a gem for getting dept information from Julianus Inkasso.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'julianus', :git => 'git@github.com:deskrock/julianus.git'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install julianus
18
+
19
+ ## Usage
20
+
21
+ To use Julianus you first have to configure it.
22
+ You have to enter your username, password. Depending whether you are testing or using Julianus gem in live environment attribute 'live' must be set either false or true.
23
+
24
+ Julianus.configure(:username => "", :password => "", :live => true/false)
25
+
26
+ Next you have to make a request, for example:
27
+
28
+ report = Julianus.report("47101010033")
29
+
30
+ After making the request you can get all depts with:
31
+
32
+ report.claims
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/julianus.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'julianus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "julianus"
8
+ spec.version = Julianus::VERSION
9
+ spec.authors = ["Mai-Liis"]
10
+ spec.email = ["mailiish@gmail.com"]
11
+ spec.description = ""
12
+ spec.summary = ""
13
+ spec.homepage = ""
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_runtime_dependency "savon", "~> 2.11"
24
+ spec.add_runtime_dependency "nokogiri"
25
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,39 @@
1
+ # class that holds all items that it has
2
+ module Julianus
3
+ class Claim
4
+ require 'julianus/item'
5
+ # new claim with on items
6
+ def initialize items
7
+ @items = []
8
+ items = [] << items unless items.is_a?(Array)
9
+ items.each do |item|
10
+ new_item = Item.new(item) if item
11
+ @items << new_item
12
+ end
13
+ end
14
+
15
+ # returns true or false according to
16
+ # if claim has items or false
17
+ def has_items?
18
+ @items.length > 0
19
+ end
20
+
21
+ # returns list of items claim has
22
+ def items
23
+ @items
24
+ end
25
+
26
+ # add item to items list
27
+ def add_item item
28
+ @items << item
29
+ end
30
+
31
+ def to_s
32
+ result = []
33
+ @items.each do |item|
34
+ result << item
35
+ end
36
+ result
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ # class that holds data for each item (dept) inside claim
2
+ module Julianus
3
+ class Item
4
+ attr_accessor :claimant, :start_date, :end_date, :amount, :status
5
+
6
+ # gives values to new item
7
+ def initialize item
8
+ self.claimant = item[:claimant]
9
+ self.start_date = item[:start_date]
10
+ self.end_date = item[:end_date]
11
+ self.amount = item[:amount]
12
+ self.status = item[:status]
13
+ end
14
+
15
+ # returns Item as Hash
16
+ def to_s
17
+ result = {
18
+ :claimant => self.claimant,
19
+ :start_date => self.start_date,
20
+ :end_date => self.end_date,
21
+ :amount => self.amount,
22
+ :status => self.status
23
+ }
24
+ result
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ # class that holds all cliams inside it
2
+ module Julianus
3
+ class Report
4
+ require 'julianus/claim'
5
+
6
+ attr_accessor :body
7
+
8
+ # new report with no claims
9
+ def initialize body
10
+ @claims = []
11
+ @body = body
12
+ end
13
+
14
+ # returns true or false according to
15
+ # if claim has items or false
16
+ def has_claims?
17
+ @claims.length > 0
18
+ end
19
+
20
+ #returns all claims
21
+ def claims
22
+ @claims
23
+ end
24
+
25
+ # adds new claim
26
+ def add_claim c
27
+ claim = Claim.new(c[:item])
28
+ @claims << claim
29
+ end
30
+
31
+ def to_s
32
+ result = []
33
+ @claims.each do |claim|
34
+ result << claim
35
+ end
36
+ result
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ # Holds version for Julianus Gem
2
+ module Julianus
3
+ VERSION = "1.0"
4
+ end
data/lib/julianus.rb ADDED
@@ -0,0 +1,67 @@
1
+ # main class for Julianus gem
2
+ module Julianus
3
+
4
+ require "julianus/version"
5
+ require 'julianus/report'
6
+ require 'krediidiregister'
7
+ require "savon"
8
+
9
+ LIVE_KH_ENDPOINT = "https://www.krediidihaldus.ee/export/wsdl-claim.php"
10
+ LIVE_KH_NAMESPACE = "https://www.krediidihaldus.ee/export/"
11
+
12
+ TEST_KH_ENDPOINT = "https://test.krediidihaldus.ee/export/wsdl-claim.php"
13
+ TEST_KH_NAMESPACE = "https://test.krediidihaldus.ee/export/"
14
+
15
+
16
+ @@config = {
17
+ :kh_username => nil,
18
+ :kh_password => nil,
19
+ :live => false,
20
+ :kr_username => nil,
21
+ :kr_password => nil,
22
+ }
23
+
24
+ @valid_config_keys= @@config.keys
25
+
26
+ # configure password, username,
27
+ # endpoint and namespace
28
+ def self.configure(opts = {})
29
+ opts.each { |k,v| @@config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
30
+ if @@config[:kh_username] && @@config[:kh_password]
31
+ @@config[:endpoint] = @@config[:live] ? LIVE_KH_ENDPOINT : TEST_KH_ENDPOINT
32
+ @@config[:namespace] = @@config[:live] ? LIVE_KH_NAMESPACE : TEST_KH_NAMESPACE
33
+ end
34
+ end
35
+
36
+ # returns configuration options
37
+ def self.config
38
+ @@config
39
+ end
40
+
41
+ # returns report
42
+ # main method for Julianus
43
+ def self.report identity_code
44
+ @client = Savon.client do
45
+ ssl_verify_mode :none
46
+ endpoint @@config[:endpoint]
47
+ namespace @@config[:namespace]
48
+ end
49
+ message = {
50
+ :customerData => {
51
+ :username => @@config[:kh_username],
52
+ :password => @@config[:kh_password],
53
+ :code => identity_code
54
+ }
55
+ }
56
+ response = @client.call(:get_by_code, :message => message)
57
+ report = Report.new(response.http.raw_body)
58
+ claim = response.body[:get_by_code_response][:return][:claims]
59
+ report.add_claim(claim)
60
+ report
61
+ end
62
+
63
+ # upload to kr or ki
64
+ def self.send_report file
65
+ KrediidiRegister.upload_file(file)
66
+ end
67
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: UTF-8
2
+ require 'base64'
3
+ require 'digest/md5'
4
+
5
+ module Julianus
6
+ class KrediidiRegister
7
+
8
+ TEST_KR_ENDPOINT = "https://www.taust.ee/importer/wsdl-krediidiinfo.php"
9
+ LIVE_KR_ENDPOINT = "https://www.taust.ee/importer/wsdl-krediidiinfo.php"
10
+
11
+ WSDL = "https://www.taust.ee/importer/wsdl-krediidiinfo.php?WSDL"
12
+
13
+
14
+
15
+ def self.upload_file(file)
16
+ base64 = to_base64("#{Julianus.config[:kr_username]}:#{Julianus.config[:kr_password]}").gsub(/\n$/, "")
17
+ file_name = File.basename(file)
18
+
19
+ @client = Savon.client(
20
+ :ssl_verify_mode => :none,
21
+ :wsdl => WSDL,
22
+ :endpoint => TEST_KR_ENDPOINT,
23
+ :headers => { 'Authorization' => "Basic #{base64}"}
24
+ )
25
+
26
+ @file_id = @client.call(
27
+ :start_upload,
28
+ :message => { :file_name => file_name }
29
+ )
30
+
31
+ id = @file_id.body[:start_upload_response][:return].to_i
32
+
33
+ @client.call(
34
+ :upload_chunk,
35
+ :message => { :doc_id => id,
36
+ :chunk => to_base64(File.read(file)), :order! => [:doc_id, :chunk]
37
+ }
38
+ )
39
+
40
+ response = @client.call(
41
+ :finish_upload,
42
+ :message => { :doc_id => id,
43
+ :md5 => md5(File.read(file)),
44
+ :order! => [:doc_id, :md5]
45
+ }
46
+ )
47
+
48
+ (response.body[:finish_upload_response][:return].to_i==0)? true : false
49
+ end
50
+
51
+
52
+ private
53
+
54
+ def self.to_base64 str
55
+ Base64.encode64(str)
56
+ end
57
+
58
+ def self.md5 str
59
+ Digest::MD5.hexdigest(str)
60
+ end
61
+ end
62
+ end
data/spec/.DS_Store ADDED
Binary file