fio_api 0.0.5 → 0.0.6

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.travis.yml +7 -2
  4. data/Gemfile +9 -12
  5. data/README.rdoc +8 -3
  6. data/Rakefile +11 -13
  7. data/VERSION +1 -1
  8. data/fio_api.gemspec +57 -33
  9. data/lib/base/account.rb +2 -2
  10. data/lib/base/deserializers/import_response_deserializer.rb +51 -0
  11. data/lib/base/deserializers/list_response_deserializer.rb +47 -36
  12. data/lib/base/list.rb +9 -14
  13. data/lib/base/payment.rb +40 -0
  14. data/lib/base/payments/domestic.rb +13 -0
  15. data/lib/base/payments/status.rb +8 -0
  16. data/lib/base/payments/xml/item.rb +41 -0
  17. data/lib/base/payments/xml/root.rb +30 -0
  18. data/lib/base/request.rb +4 -54
  19. data/lib/base/transaction.rb +2 -2
  20. data/lib/base.rb +2 -6
  21. data/lib/fio_api.rb +16 -10
  22. data/lib/utils/hash.rb +2 -2
  23. data/spec/base/account_spec.rb +4 -8
  24. data/spec/base/deserializers/import_response_deserializer_spec.rb +41 -0
  25. data/spec/base/deserializers/list_response_deserializer_spec.rb +48 -59
  26. data/spec/base/list_spec.rb +36 -23
  27. data/spec/base/payment_spec.rb +38 -0
  28. data/spec/base/payments/domestic_spec.rb +14 -0
  29. data/spec/base/payments/status_spec.rb +13 -0
  30. data/spec/base/payments/xml/root_spec.rb +63 -0
  31. data/spec/base/request_spec.rb +2 -49
  32. data/spec/base/transaction_spec.rb +5 -9
  33. data/spec/fio_api_spec.rb +4 -7
  34. data/spec/fixtures/vcr_cassettes/by_date_range.yml +47 -0
  35. data/spec/fixtures/vcr_cassettes/by_listing_id_and_year.yml +49 -0
  36. data/spec/fixtures/vcr_cassettes/from_last_fetch.yml +44 -0
  37. data/spec/fixtures/vcr_cassettes/import.yml +53 -0
  38. data/spec/fixtures/vcr_cassettes/invalid_import.yml +51 -0
  39. data/spec/fixtures/vcr_cassettes/set_last_fetch_date.yml +44 -0
  40. data/spec/fixtures/vcr_cassettes/set_last_fetch_id.yml +47 -0
  41. data/spec/spec_helper.rb +7 -2
  42. data/spec/utils/hash_spec.rb +10 -15
  43. metadata +70 -24
  44. data/lib/base/deserializer.rb +0 -19
  45. data/spec/base/deserializer_spec.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 685e91eac02a573999a18b5ac41b5505f35da56f
4
- data.tar.gz: ebe0594db6cb2c53b83fadacba9a5ba9ff6bab19
3
+ metadata.gz: 13a5ab858a6e9b441eb53773dbe28611e6754bf2
4
+ data.tar.gz: 9c9d9e3089fdd10c092d3ecfee8c35d17a2fdeb8
5
5
  SHA512:
6
- metadata.gz: cde73de58e95c2fa4a4496de6306fc6428bf679135603cc0fddbd7f864dd74f5669485e8002b38bf6ee461a2af38b6a15d8bb6c1f787ee2e349193b6ba7d6053
7
- data.tar.gz: aa54a2d8445b4f41cc2b694271f1884173e3fa2b206841fa6d435910557c6fa9375b880ef7eba0e982fcdb92ae278dc0c85be5c656b01743b9918013cab460df
6
+ metadata.gz: e19bf77982f36c837797367f617c7a66d2a4ae0ea29fb9888071f4965ff47469c6bdff10983d17fe034d13589ffeb6463ab85464eaaf09b77355f7a51935a9ae
7
+ data.tar.gz: 56c4ea9d17bb41eb1120998d1bfc7d60853f64c9fecfba7e4ac63b5a291b13bfc4690d424284bcda59cae0eec883fef5920de0fc867d262bfa255a6dacd01ed1
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Gemfile'
4
+ - '**/Rakefile'
5
+ Exclude:
6
+ - 'fio_api.gemspec'
7
+ Metrics/LineLength:
8
+ Max: 180
9
+ Documentation:
10
+ Enabled: false
11
+ Metrics/AbcSize:
12
+ Max: 38
13
+ Metrics/MethodLength:
14
+ Max: 50
15
+ Metrics/BlockLength:
16
+ Enabled: false
17
+ Metrics/CyclomaticComplexity:
18
+ Max: 7
19
+ Metrics/ClassLength:
20
+ Max: 230
21
+ Metrics/ModuleLength:
22
+ Max: 230
23
+ Style/FileName:
24
+ Enabled: true
25
+ Exclude:
26
+ - Guardfile
data/.travis.yml CHANGED
@@ -1,3 +1,8 @@
1
+ language: ruby
2
+ before_install: 'gem update bundler'
3
+ install: 'bundle install --jobs=3 --retry=3' # Suppress the --deployment flag'
1
4
  rvm:
2
- - 1.9.2
3
- - 1.9.3
5
+ - 2.1.0
6
+ - 2.2.2
7
+ - 2.3.0
8
+ - 2.3.1
data/Gemfile CHANGED
@@ -1,16 +1,13 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'http://rubygems.org'
5
2
 
6
- gem "httparty", ">= 0.13.7"
3
+ gem 'httparty', '>= 0.16.2'
7
4
 
8
- # Add dependencies to develop your gem here.
9
- # Include everything needed to run rake, tests, features, etc.
10
5
  group :development do
11
- gem "rspec", ">= 3.4.0"
12
- gem "rspec-mocks", ">= 3.4.0"
13
- gem "rdoc", ">= 4.2.0"
14
- gem "bundler", ">= 1.10.6"
15
- gem "jeweler", ">= 2.0.1"
6
+ gem 'bundler', '>= 1.10.6'
7
+ gem 'jeweler', '>= 2.1.1'
8
+ gem 'rdoc', '>= 4.2.0'
9
+ gem 'rspec'
10
+ gem 'rspec-mocks', '>= 3.4.0'
11
+ gem 'vcr'
12
+ gem 'webmock'
16
13
  end
data/README.rdoc CHANGED
@@ -1,10 +1,10 @@
1
- {<img src="https://secure.travis-ci.org/robinbortlik/fio_api.png?branch=master" alt="Build Status" />}[http://travis-ci.org/robinbortlik/fio_api]
2
- {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/robinbortlik/fio_api]
1
+ {<img src="https://travis-ci.org/14113/fio_api.svg?branch=master" alt="Build Status" />}[http://travis-ci.org/14113/fio_api]
2
+ {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/14113/fio_api]
3
3
  = Fio API
4
4
 
5
5
  This project rocks and uses MIT-LICENSE.
6
6
 
7
- This gem is a wrapper for Fio bank API. Currently Fio API support only data listing, so you can make only a requests to get all your money transaction in some date range.
7
+ This gem is a wrapper for Fio bank API.
8
8
 
9
9
  == Usage
10
10
 
@@ -34,6 +34,11 @@ This gem is a wrapper for Fio bank API. Currently Fio API support only data list
34
34
  list.set_last_fetch_date(Date.new(2012,11,05))
35
35
  list.response
36
36
 
37
+ === Import domestic payments for authorization
38
+ domestic = FioAPI::Payments::Domestic.new(***) # Create new payment
39
+ service = FioAPI::Payment.new domestic # Pass one payment or array of payments
40
+ service.import # Call API
41
+ service.response # Return deserialized response with status code etc.
37
42
 
38
43
  == Contributing to fio_api
39
44
 
data/Rakefile CHANGED
@@ -1,12 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
  require 'rubygems'
4
2
  require 'bundler'
5
3
  begin
6
4
  Bundler.setup(:default, :development)
7
5
  rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
6
+ warn e.message
7
+ warn 'Run `bundle install` to install missing gems'
10
8
  exit e.status_code
11
9
  end
12
10
  require 'rake'
@@ -14,13 +12,13 @@ require 'rake'
14
12
  require 'jeweler'
15
13
  Jeweler::Tasks.new do |gem|
16
14
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "fio_api"
18
- gem.homepage = "http://github.com/robinbortlik/fio_api"
19
- gem.license = "MIT"
20
- gem.summary = %Q{API wrapper for FIO bank}
21
- gem.description = %Q{API wrapper for FIO bank}
22
- gem.email = "robinbortlik@gmail.com"
23
- gem.authors = ["Robin Bortlik"]
15
+ gem.name = 'fio_api'
16
+ gem.homepage = 'http://github.com/14113/fio_api'
17
+ gem.license = 'MIT'
18
+ gem.summary = %(API wrapper for FIO bank)
19
+ gem.description = %(API wrapper for FIO bank)
20
+ gem.email = 'a.martinik@gmail.com'
21
+ gem.authors = ['Robin Bortlik', 'Adam Martinik']
24
22
  # dependencies defined in Gemfile
25
23
  end
26
24
  Jeweler::RubygemsDotOrgTasks.new
@@ -36,11 +34,11 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
34
  spec.rcov = true
37
35
  end
38
36
 
39
- task :default => :spec
37
+ task default: :spec
40
38
 
41
39
  require 'rdoc/task'
42
40
  Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
44
42
 
45
43
  rdoc.rdoc_dir = 'rdoc'
46
44
  rdoc.title = "fio_api #{version}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/fio_api.gemspec CHANGED
@@ -2,22 +2,25 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: fio_api 0.0.6 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
- s.name = "fio_api"
8
- s.version = "0.0.5"
8
+ s.name = "fio_api".freeze
9
+ s.version = "0.0.6"
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Robin Bortlik"]
12
- s.date = "2013-07-15"
13
- s.description = "API wrapper for FIO bank"
14
- s.email = "robinbortlik@gmail.com"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Robin Bortlik".freeze, "Adam Martinik".freeze]
14
+ s.date = "2018-06-04"
15
+ s.description = "API wrapper for FIO bank".freeze
16
+ s.email = "a.martinik@gmail.com".freeze
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
19
  "README.rdoc"
18
20
  ]
19
21
  s.files = [
20
22
  ".rspec",
23
+ ".rubocop.yml",
21
24
  ".travis.yml",
22
25
  "Gemfile",
23
26
  "LICENSE.txt",
@@ -27,54 +30,75 @@ Gem::Specification.new do |s|
27
30
  "fio_api.gemspec",
28
31
  "lib/base.rb",
29
32
  "lib/base/account.rb",
30
- "lib/base/deserializer.rb",
33
+ "lib/base/deserializers/import_response_deserializer.rb",
31
34
  "lib/base/deserializers/list_response_deserializer.rb",
32
35
  "lib/base/list.rb",
36
+ "lib/base/payment.rb",
37
+ "lib/base/payments/domestic.rb",
38
+ "lib/base/payments/status.rb",
39
+ "lib/base/payments/xml/item.rb",
40
+ "lib/base/payments/xml/root.rb",
33
41
  "lib/base/request.rb",
34
42
  "lib/base/transaction.rb",
35
43
  "lib/fio_api.rb",
36
44
  "lib/utils/hash.rb",
37
45
  "spec/base/account_spec.rb",
38
- "spec/base/deserializer_spec.rb",
46
+ "spec/base/deserializers/import_response_deserializer_spec.rb",
39
47
  "spec/base/deserializers/list_response_deserializer_spec.rb",
40
48
  "spec/base/list_spec.rb",
49
+ "spec/base/payment_spec.rb",
50
+ "spec/base/payments/domestic_spec.rb",
51
+ "spec/base/payments/status_spec.rb",
52
+ "spec/base/payments/xml/root_spec.rb",
41
53
  "spec/base/request_spec.rb",
42
54
  "spec/base/transaction_spec.rb",
43
55
  "spec/fio_api_spec.rb",
56
+ "spec/fixtures/vcr_cassettes/by_date_range.yml",
57
+ "spec/fixtures/vcr_cassettes/by_listing_id_and_year.yml",
58
+ "spec/fixtures/vcr_cassettes/from_last_fetch.yml",
59
+ "spec/fixtures/vcr_cassettes/import.yml",
60
+ "spec/fixtures/vcr_cassettes/invalid_import.yml",
61
+ "spec/fixtures/vcr_cassettes/set_last_fetch_date.yml",
62
+ "spec/fixtures/vcr_cassettes/set_last_fetch_id.yml",
44
63
  "spec/spec_helper.rb",
45
64
  "spec/utils/hash_spec.rb"
46
65
  ]
47
- s.homepage = "http://github.com/robinbortlik/fio_api"
48
- s.licenses = ["MIT"]
49
- s.require_paths = ["lib"]
50
- s.rubygems_version = "1.8.25"
51
- s.summary = "API wrapper for FIO bank"
66
+ s.homepage = "http://github.com/14113/fio_api".freeze
67
+ s.licenses = ["MIT".freeze]
68
+ s.rubygems_version = "2.6.11".freeze
69
+ s.summary = "API wrapper for FIO bank".freeze
52
70
 
53
71
  if s.respond_to? :specification_version then
54
- s.specification_version = 3
72
+ s.specification_version = 4
55
73
 
56
74
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<httparty>, [">= 0.9.0"])
58
- s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
59
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.8.0"])
60
- s.add_development_dependency(%q<rdoc>, [">= 3.12"])
61
- s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
62
- s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
75
+ s.add_runtime_dependency(%q<httparty>.freeze, [">= 0.16.2"])
76
+ s.add_development_dependency(%q<bundler>.freeze, [">= 1.10.6"])
77
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 2.1.1"])
78
+ s.add_development_dependency(%q<rdoc>.freeze, [">= 4.2.0"])
79
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
80
+ s.add_development_dependency(%q<rspec-mocks>.freeze, [">= 3.4.0"])
81
+ s.add_development_dependency(%q<vcr>.freeze, [">= 0"])
82
+ s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
63
83
  else
64
- s.add_dependency(%q<httparty>, [">= 0.9.0"])
65
- s.add_dependency(%q<rspec>, [">= 2.8.0"])
66
- s.add_dependency(%q<rspec-mocks>, [">= 2.8.0"])
67
- s.add_dependency(%q<rdoc>, [">= 3.12"])
68
- s.add_dependency(%q<bundler>, [">= 1.2.0"])
69
- s.add_dependency(%q<jeweler>, [">= 1.8.4"])
84
+ s.add_dependency(%q<httparty>.freeze, [">= 0.16.2"])
85
+ s.add_dependency(%q<bundler>.freeze, [">= 1.10.6"])
86
+ s.add_dependency(%q<jeweler>.freeze, [">= 2.1.1"])
87
+ s.add_dependency(%q<rdoc>.freeze, [">= 4.2.0"])
88
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
89
+ s.add_dependency(%q<rspec-mocks>.freeze, [">= 3.4.0"])
90
+ s.add_dependency(%q<vcr>.freeze, [">= 0"])
91
+ s.add_dependency(%q<webmock>.freeze, [">= 0"])
70
92
  end
71
93
  else
72
- s.add_dependency(%q<httparty>, [">= 0.9.0"])
73
- s.add_dependency(%q<rspec>, [">= 2.8.0"])
74
- s.add_dependency(%q<rspec-mocks>, [">= 2.8.0"])
75
- s.add_dependency(%q<rdoc>, [">= 3.12"])
76
- s.add_dependency(%q<bundler>, [">= 1.2.0"])
77
- s.add_dependency(%q<jeweler>, [">= 1.8.4"])
94
+ s.add_dependency(%q<httparty>.freeze, [">= 0.16.2"])
95
+ s.add_dependency(%q<bundler>.freeze, [">= 1.10.6"])
96
+ s.add_dependency(%q<jeweler>.freeze, [">= 2.1.1"])
97
+ s.add_dependency(%q<rdoc>.freeze, [">= 4.2.0"])
98
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
99
+ s.add_dependency(%q<rspec-mocks>.freeze, [">= 3.4.0"])
100
+ s.add_dependency(%q<vcr>.freeze, [">= 0"])
101
+ s.add_dependency(%q<webmock>.freeze, [">= 0"])
78
102
  end
79
103
  end
80
104
 
data/lib/base/account.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module FioAPI
2
2
  # == Account class representing the Account entity
3
3
  class Account < FioAPI::Base
4
- attr_accessor :account_id, :bank_id, :currency, :iban,:bic,:opening_balance,:closing_balance,
5
- :date_start, :date_end, :year_list, :id_list, :id_from, :id_to, :id_last_download
4
+ attr_accessor :account_id, :bank_id, :currency, :iban, :bic, :opening_balance, :closing_balance,
5
+ :date_start, :date_end, :year_list, :id_list, :id_from, :id_to, :id_last_download
6
6
  end
7
7
  end
@@ -0,0 +1,51 @@
1
+ require 'httparty'
2
+
3
+ module FioAPI
4
+ # == ImportResponseDeserializer
5
+ # Deserializer responsible for response json deserializing. Should construct object with status attributes.
6
+ #
7
+ class ImportResponseDeserializer < HTTParty::Parser
8
+ attr_accessor :status
9
+
10
+ # Parse json
11
+ #
12
+ # == Returns:
13
+ # Should return new deserialized object
14
+ #
15
+ def parse
16
+ deserialize super
17
+ end
18
+
19
+ # Deserialize json
20
+ #
21
+ # == Parameters:
22
+ # hash::
23
+ # Hash returned from payments request.
24
+ #
25
+ # == Returns:
26
+ # New object with status attributes
27
+ #
28
+ def deserialize(json)
29
+ self.status = deserialize_import(json.try_path('responseImport', 'result'))
30
+ self
31
+ end
32
+
33
+ private
34
+
35
+ # Deserialize import of payments
36
+ # == Parameters:
37
+ # response_json::
38
+ # Hash with informations about payments
39
+ # == Returns:
40
+ # Status
41
+ def deserialize_import(response_json)
42
+ FioAPI::Payments::Status.new(
43
+ error_code: response_json.try_path('errorCode').to_i,
44
+ error_message: response_json.try_path('message').to_s,
45
+ id_instruction: response_json.try_path('idInstruction').to_i,
46
+ sum_credit: response_json.try_path('sums', 'sum', 'sumCredit').to_f,
47
+ sum_debet: response_json.try_path('sums', 'sum', 'sumDebet').to_f
48
+ )
49
+ end
50
+ end
51
+ end
@@ -1,10 +1,21 @@
1
+ require 'httparty'
2
+
1
3
  module FioAPI
2
4
  # == ListResponseDeserializer
3
5
  # Deserializer responsible for response json deserializing. Should construct object with account and transactions attributes.
4
6
  #
5
- class ListResponseDeserializer < FioAPI::Deserializer
7
+ class ListResponseDeserializer < HTTParty::Parser
6
8
  attr_accessor :account, :transactions
7
9
 
10
+ # Parse json
11
+ #
12
+ # == Returns:
13
+ # Should return new deserialized object
14
+ #
15
+ def parse
16
+ deserialize super
17
+ end
18
+
8
19
  # Deserialize json
9
20
  #
10
21
  # == Parameters:
@@ -15,8 +26,8 @@ module FioAPI
15
26
  # New object with account and transactions attributes
16
27
  #
17
28
  def deserialize(json)
18
- self.account = deserialize_account(json.try_path("accountStatement", "info"))
19
- self.transactions = deserialize_transactions(json.try_path("accountStatement", "transactionList", "transaction"))
29
+ self.account = deserialize_account(json.try_path('accountStatement', 'info'))
30
+ self.transactions = deserialize_transactions(json.try_path('accountStatement', 'transactionList', 'transaction'))
20
31
  self
21
32
  end
22
33
 
@@ -30,20 +41,20 @@ module FioAPI
30
41
  # Account object
31
42
  def deserialize_account(account_json)
32
43
  FioAPI::Account.new(
33
- account_id: account_json.try_path("accountId"),
34
- bank_id: account_json.try_path("bankId"),
35
- currency: account_json.try_path("currency"),
36
- iban: account_json.try_path("iban"),
37
- bic: account_json.try_path("bic"),
38
- opening_balance: account_json.try_path("openingBalance"),
39
- closing_balance: account_json.try_path("closingBalance"),
40
- date_start: account_json.try_path("dateStart"),
41
- date_end: account_json.try_path("dateEnd"),
42
- year_list: account_json.try_path("yearList"),
43
- id_list: account_json.try_path("idList"),
44
- id_from: account_json.try_path("idFrom"),
45
- id_to: account_json.try_path("idTo"),
46
- id_last_download: account_json.try_path("idLastDownload")
44
+ account_id: account_json.try_path('accountId'),
45
+ bank_id: account_json.try_path('bankId'),
46
+ currency: account_json.try_path('currency'),
47
+ iban: account_json.try_path('iban'),
48
+ bic: account_json.try_path('bic'),
49
+ opening_balance: account_json.try_path('openingBalance'),
50
+ closing_balance: account_json.try_path('closingBalance'),
51
+ date_start: account_json.try_path('dateStart'),
52
+ date_end: account_json.try_path('dateEnd'),
53
+ year_list: account_json.try_path('yearList'),
54
+ id_list: account_json.try_path('idList'),
55
+ id_from: account_json.try_path('idFrom'),
56
+ id_to: account_json.try_path('idTo'),
57
+ id_last_download: account_json.try_path('idLastDownload')
47
58
  )
48
59
  end
49
60
 
@@ -56,25 +67,25 @@ module FioAPI
56
67
  def deserialize_transactions(transactions_json)
57
68
  Array(transactions_json).map do |trans_json|
58
69
  FioAPI::Transaction.new(
59
- transaction_id: trans_json.try_path("column22", "value"),
60
- date: trans_json.try_path("column0", "value"),
61
- amount: trans_json.try_path("column1", "value"),
62
- currency: trans_json.try_path("column14", "value"),
63
- account: trans_json.try_path("column2", "value"),
64
- account_name: trans_json.try_path("column10", "value"),
65
- bank_code: trans_json.try_path("column3", "value"),
66
- bank_name: trans_json.try_path("column12", "value"),
67
- ks: trans_json.try_path("column4", "value"),
68
- vs: trans_json.try_path("column5", "value"),
69
- ss: trans_json.try_path("column6", "value"),
70
- user_identification: trans_json.try_path("column7", "value"),
71
- message_for_recipient: trans_json.try_path("column16", "value"),
72
- transaction_type: trans_json.try_path("column8", "value"),
73
- sender: trans_json.try_path("column9", "value"),
74
- detail_info: trans_json.try_path("column18", "value"),
75
- comment: trans_json.try_path("column25", "value"),
76
- bic: trans_json.try_path("column26", "value"),
77
- action_id: trans_json.try_path("column17", "value")
70
+ transaction_id: trans_json.try_path('column22', 'value'),
71
+ date: trans_json.try_path('column0', 'value'),
72
+ amount: trans_json.try_path('column1', 'value'),
73
+ currency: trans_json.try_path('column14', 'value'),
74
+ account: trans_json.try_path('column2', 'value'),
75
+ account_name: trans_json.try_path('column10', 'value'),
76
+ bank_code: trans_json.try_path('column3', 'value'),
77
+ bank_name: trans_json.try_path('column12', 'value'),
78
+ ks: trans_json.try_path('column4', 'value'),
79
+ vs: trans_json.try_path('column5', 'value'),
80
+ ss: trans_json.try_path('column6', 'value'),
81
+ user_identification: trans_json.try_path('column7', 'value'),
82
+ message_for_recipient: trans_json.try_path('column16', 'value'),
83
+ transaction_type: trans_json.try_path('column8', 'value'),
84
+ sender: trans_json.try_path('column9', 'value'),
85
+ detail_info: trans_json.try_path('column18', 'value'),
86
+ comment: trans_json.try_path('column25', 'value'),
87
+ bic: trans_json.try_path('column26', 'value'),
88
+ action_id: trans_json.try_path('column17', 'value')
78
89
  )
79
90
  end
80
91
  end
data/lib/base/list.rb CHANGED
@@ -1,5 +1,3 @@
1
- require "base/deserializers/list_response_deserializer"
2
-
3
1
  module FioAPI
4
2
  # Base class for request to transactions listing and account information
5
3
  class List < FioAPI::Base
@@ -18,7 +16,7 @@ module FioAPI
18
16
  #
19
17
  # https://www.fio.cz/ib_api/rest/periods/(token)/(date_from)/(date_to)/transactions.(format)
20
18
  def by_date_range(from_date, to_date)
21
- fetch_and_deserialize_response('periods', FioAPI.token, from_date, to_date, 'transactions.json')
19
+ fetch_and_deserialize_response("/periods/#{FioAPI.token}/#{from_date}/#{to_date}/transactions.json")
22
20
  end
23
21
 
24
22
  # Allow request transactions by listing_id and year
@@ -34,7 +32,7 @@ module FioAPI
34
32
  #
35
33
  # https://www.fio.cz/ib_api/rest/by-id/(token)/(year)/(id)/transactions.(format)
36
34
  def by_listing_id_and_year(listing_id, year)
37
- fetch_and_deserialize_response('by-id', FioAPI.token, year, listing_id, 'transactions.json')
35
+ fetch_and_deserialize_response("/by-id/#{FioAPI.token}/#{year}/#{listing_id}/transactions.json")
38
36
  end
39
37
 
40
38
  # Allow request transactions from last request
@@ -44,7 +42,7 @@ module FioAPI
44
42
  #
45
43
  # https://www.fio.cz/ib_api/rest/last/(token)/transactions.(format)
46
44
  def from_last_fetch
47
- fetch_and_deserialize_response('last', FioAPI.token, 'transactions.json')
45
+ fetch_and_deserialize_response("/last/#{FioAPI.token}/transactions.json")
48
46
  end
49
47
 
50
48
  # Allow request to set last transaction_id
@@ -58,7 +56,7 @@ module FioAPI
58
56
  #
59
57
  # https://www.fio.cz/ib_api/rest/set-last-id/(token)/(id)/
60
58
  def set_last_fetch_id(transaction_id)
61
- fetch_and_deserialize_response('set-last-id', FioAPI.token, transaction_id, "/")
59
+ fetch_and_deserialize_response("/set-last-id/#{FioAPI.token}/#{transaction_id}/")
62
60
  end
63
61
 
64
62
  # Allow request to set last request date
@@ -72,7 +70,7 @@ module FioAPI
72
70
  #
73
71
  # https://www.fio.cz/ib_api/rest/set-last-date/(token)/(rrrr-mm-dd)/
74
72
  def set_last_fetch_date(date)
75
- fetch_and_deserialize_response('set-last-date', FioAPI.token, date, "/")
73
+ fetch_and_deserialize_response("/set-last-date/#{FioAPI.token}/#{date}/")
76
74
  end
77
75
 
78
76
  private
@@ -87,13 +85,10 @@ module FioAPI
87
85
  # == Returns:
88
86
  # List insatnce with account info and transactions list
89
87
  #
90
- def fetch_and_deserialize_response(*args)
91
- self.request = FioAPI::Request.new(deserializer: FioAPI::ListResponseDeserializer.new())
92
- self.request.set_uri(*args)
93
- self.request.fetch
94
- self.response = self.request.response
95
- self
88
+ def fetch_and_deserialize_response(path)
89
+ self.request = FioAPI::Request.get(path, parser: ListResponseDeserializer)
90
+ self.response = request.parsed_response
91
+ request
96
92
  end
97
-
98
93
  end
99
94
  end
@@ -0,0 +1,40 @@
1
+ module FioAPI
2
+ # Base class for submit payments and waiting for authorization
3
+ class Payment
4
+ attr_accessor :request, :response, :payments
5
+
6
+ def initialize(payments)
7
+ @payments = [payments].flatten
8
+ end
9
+
10
+ def path
11
+ "/import/?token=#{FioAPI.token}&type=xml"
12
+ end
13
+
14
+ def import
15
+ self.request ||= FioAPI::Request.post(path, headers: headers, body: { 'file' => file }, parser: FioAPI::ImportResponseDeserializer)
16
+ self.response ||= self.request.parsed_response
17
+ self.request
18
+ end
19
+
20
+ private
21
+
22
+ def headers
23
+ {
24
+ 'Content-Type' => 'multipart/form-data',
25
+ 'boundary' => '-----------RubyMultipartPost'
26
+ }
27
+ end
28
+
29
+ def xml
30
+ FioAPI::Payments::Xml::Root.new(payments).build
31
+ end
32
+
33
+ def file
34
+ file = Tempfile.new('fio')
35
+ file.write xml
36
+ file.rewind
37
+ file
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ module FioAPI
2
+ module Payments
3
+ # == Domestic class representing the Domestic entity
4
+ class Domestic < FioAPI::Base
5
+ attr_accessor :account_from, :currency, :amount, :account_to, :bank_code, :ks, :vs, :ss,
6
+ :date, :message_for_recipient, :comment
7
+
8
+ def payment_type
9
+ '431001'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module FioAPI
2
+ module Payments
3
+ # == Status class representing the Status entity
4
+ class Status < FioAPI::Base
5
+ attr_accessor :error_code, :id_instruction, :error_message, :sum_credit, :sum_debet
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ module FioAPI
2
+ module Payments
3
+ module Xml
4
+ class Item
5
+ attr_reader :builder, :payment
6
+
7
+ def initialize(builder, payment)
8
+ @builder = builder
9
+ @payment = payment
10
+ end
11
+
12
+ def build
13
+ @build ||= builder.DomesticTransaction do
14
+ builder.accountFrom payment.account_from
15
+ builder.currency payment.currency
16
+ builder.amount payment.amount
17
+ builder.accountTo payment.account_to
18
+ builder.bankCode payment.bank_code
19
+ builder.ks payment.ks
20
+ builder.vs payment.vs
21
+ builder.ss payment.ss
22
+ builder.date payment.date
23
+ builder.messageForRecipient payment.message_for_recipient
24
+ comment
25
+ builder.paymentType payment.payment_type
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def create_element(name, value = '')
32
+ builder.parent.add_child builder.doc.create_element(name, value)
33
+ end
34
+
35
+ def comment
36
+ create_element('comment', payment.comment)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end