Class: Julianus::KrediidiRegister

Inherits:
Object
  • Object
show all
Defined in:
lib/krediidiregister.rb

Constant Summary collapse

TEST_KR_ENDPOINT =
"https://www.taust.ee/importer/wsdl-krediidiinfo.php"
LIVE_KR_ENDPOINT =
"https://www.taust.ee/importer/wsdl-krediidiinfo.php"
WSDL =
"https://www.taust.ee/importer/wsdl-krediidiinfo.php?WSDL"

Class Method Summary collapse

Class Method Details

.upload_file(file) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/krediidiregister.rb', line 15

def self.upload_file(file)
  base64 = to_base64("#{Julianus.config[:kr_username]}:#{Julianus.config[:kr_password]}").gsub(/\n$/, "")
  file_name = File.basename(file)

  @client = Savon.client(
    :ssl_verify_mode => :none,
    :wsdl => WSDL,
    :endpoint => TEST_KR_ENDPOINT,
    :headers => { 'Authorization' => "Basic #{base64}"}
  )
  
  @file_id = @client.call(
    :start_upload, 
    :message => { :file_name => file_name }
  )
  
  id = @file_id.body[:start_upload_response][:return].to_i

  @client.call(
    :upload_chunk, 
    :message => { :doc_id => id,
                  :chunk => to_base64(File.read(file)), :order! => [:doc_id, :chunk]
                }
  )
  
  response = @client.call(
                  :finish_upload, 
                  :message => { :doc_id => id, 
                                :md5 => md5(File.read(file)), 
                                :order! => [:doc_id, :md5]
                  }
            )
  
  (response.body[:finish_upload_response][:return].to_i==0)? true : false
end