fio_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "httparty", "0.9.0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "rspec-mocks", "~> 2.8.0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.2.0"
15
+ gem "jeweler", "~> 1.8.4"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ httparty (0.9.0)
7
+ multi_json (~> 1.0)
8
+ multi_xml
9
+ jeweler (1.8.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.7.5)
15
+ multi_json (1.3.7)
16
+ multi_xml (0.5.1)
17
+ rake (10.0.2)
18
+ rdoc (3.12)
19
+ json (~> 1.4)
20
+ rspec (2.8.0)
21
+ rspec-core (~> 2.8.0)
22
+ rspec-expectations (~> 2.8.0)
23
+ rspec-mocks (~> 2.8.0)
24
+ rspec-core (2.8.0)
25
+ rspec-expectations (2.8.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-mocks (2.8.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.2.0)
34
+ httparty (= 0.9.0)
35
+ jeweler (~> 1.8.4)
36
+ rdoc (~> 3.12)
37
+ rspec (~> 2.8.0)
38
+ rspec-mocks (~> 2.8.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Robin Bortlik
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 ADDED
@@ -0,0 +1,44 @@
1
+ = Fio API
2
+
3
+ This project rocks and uses MIT-LICENSE.
4
+
5
+ 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.
6
+
7
+ == Usage
8
+
9
+ === Add to your gemfile
10
+ gem 'fio_api'
11
+
12
+ === Setup API token
13
+ FioAPI.token = "8JSKJ823DN86YRH87UIRUI2363ND5xcr3"
14
+
15
+ === Request transactions in date range 2012-11-05 and 2012-12-26
16
+ list = FioAPI::List.new # Create new listing request
17
+ list.by_date_range(Date.new(2012,11,05), Date.new(2012,12,26)) # Specify listing condition and fetch request
18
+ list.response # Return deserialized response
19
+
20
+ === Request transactions by listing_id and year
21
+ list = FioAPI::List.new
22
+ list.by_listing_id_and_year("43XC6362ASD", 2012)
23
+ list.response
24
+
25
+ === Request to set last request id
26
+ list = FioAPI::List.new
27
+ list.set_last_fetch_id("SHXG738377834")
28
+ list.response
29
+
30
+ === Request to set last request date
31
+ list = FioAPI::List.new
32
+ list.set_last_fetch_date(Date.new(2012,11,05))
33
+ list.response
34
+
35
+
36
+ == Contributing to fio_api
37
+
38
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
39
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
40
+ * Fork the project.
41
+ * Start a feature/bugfix branch.
42
+ * Commit and push until you are happy with your contribution.
43
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
44
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # 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"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "fio_api #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/fio_api.gemspec ADDED
@@ -0,0 +1,80 @@
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 = "fio_api"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Robin Bortlik"]
12
+ s.date = "2012-12-06"
13
+ s.description = "API wrapper for FIO bank"
14
+ s.email = "robinbortlik@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".rspec",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "fio_api.gemspec",
28
+ "lib/base.rb",
29
+ "lib/base/account.rb",
30
+ "lib/base/deserializer.rb",
31
+ "lib/base/deserializers/list_response_deserializer.rb",
32
+ "lib/base/list.rb",
33
+ "lib/base/request.rb",
34
+ "lib/base/transaction.rb",
35
+ "lib/fio_api.rb",
36
+ "lib/utils/hash.rb",
37
+ "spec/base/account_spec.rb",
38
+ "spec/base/deserializer_spec.rb",
39
+ "spec/base/deserializers/list_response_deserializer_spec.rb",
40
+ "spec/base/list_spec.rb",
41
+ "spec/base/request_spec.rb",
42
+ "spec/base/transaction_spec.rb",
43
+ "spec/fio_api_spec.rb",
44
+ "spec/spec_helper.rb",
45
+ "spec/utils/hash_spec.rb"
46
+ ]
47
+ s.homepage = "http://github.com/robinbortlik/fio_api"
48
+ s.licenses = ["MIT"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = "1.8.24"
51
+ s.summary = "API wrapper for FIO bank"
52
+
53
+ if s.respond_to? :specification_version then
54
+ s.specification_version = 3
55
+
56
+ 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"])
63
+ 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"])
70
+ end
71
+ 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"])
78
+ end
79
+ end
80
+
@@ -0,0 +1,7 @@
1
+ module FioAPI
2
+ # == Account class representing the Account entity
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
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module FioAPI
2
+ # == Base class for deserializers. Should
3
+ class Deserializer < FioAPI::Base
4
+
5
+ # Deserialize method is required for every deserializer
6
+ #
7
+ # == Parameters:
8
+ # hash::
9
+ # Hash returned form request
10
+ #
11
+ # == Returns:
12
+ # Should return new deserialized object
13
+ #
14
+ def deserialize(json)
15
+ raise "Implement deserialize method"
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,82 @@
1
+ module FioAPI
2
+ # == ListResponseDeserializer
3
+ # Deserializer responsible for response json deserializing. Should construct object with account and transactions attributes.
4
+ #
5
+ class ListResponseDeserializer < FioAPI::Deserializer
6
+ attr_accessor :account, :transactions
7
+
8
+ # Deserialize json
9
+ #
10
+ # == Parameters:
11
+ # hash::
12
+ # Hash returned from list request.
13
+ #
14
+ # == Returns:
15
+ # New object with account and transactions attributes
16
+ #
17
+ def deserialize(json)
18
+ self.account = deserialize_account(json.try_path("accountStatement", "info"))
19
+ self.transactions = deserialize_transactions(json.try_path("accountStatement", "transactionList", "transaction"))
20
+ self
21
+ end
22
+
23
+ private
24
+
25
+ # Deserialize account info
26
+ # == Parameters:
27
+ # account_json::
28
+ # Hash with informations obout account
29
+ # == Returns:
30
+ # Account object
31
+ def deserialize_account(account_json)
32
+ 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")
47
+ )
48
+ end
49
+
50
+ # Deserialize list of transactions
51
+ # == Parameters:
52
+ # transactions_json::
53
+ # Hash with informations obout transactions
54
+ # == Returns:
55
+ # Array of transactions
56
+ def deserialize_transactions(transactions_json)
57
+ Array(transactions_json).map do |trans_json|
58
+ 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")
78
+ )
79
+ end
80
+ end
81
+ end
82
+ end
data/lib/base/list.rb ADDED
@@ -0,0 +1,99 @@
1
+ require "base/deserializers/list_response_deserializer"
2
+
3
+ module FioAPI
4
+ # Base class for request to transactions listing and account information
5
+ class List < FioAPI::Base
6
+ attr_accessor :request, :response
7
+
8
+ # Allow request transactions in date range
9
+ #
10
+ # == Parameters:
11
+ # from_date::
12
+ # Start date for transactions list
13
+ # to_date::
14
+ # End date for transactions list
15
+ #
16
+ # == Returns:
17
+ # List insatnce with account info and transactions list
18
+ #
19
+ # https://www.fio.cz/ib_api/rest/periods/(token)/(date_from)/(date_to)/transactions.(format)
20
+ def by_date_range(from_date, to_date)
21
+ fetch_and_deserialize_response('periods', FioAPI.token, from_date, to_date, 'transactions.json')
22
+ end
23
+
24
+ # Allow request transactions by listing_id and year
25
+ #
26
+ # == Parameters:
27
+ # listing_id::
28
+ # Id of listing
29
+ # year::
30
+ # Year when listing was provided
31
+ #
32
+ # == Returns:
33
+ # List insatnce with account info and transactions list
34
+ #
35
+ # https://www.fio.cz/ib_api/rest/by-id/(token)/(year)/(id)/transactions.(format)
36
+ def by_listing_id_and_year(listing_id, year)
37
+ fetch_and_deserialize_response('by-id', FioAPI.token, year, listing_id, 'transactions.json')
38
+ end
39
+
40
+ # Allow request transactions from last request
41
+ #
42
+ # == Returns:
43
+ # List insatnce with account info and transactions list
44
+ #
45
+ # https://www.fio.cz/ib_api/rest/last/(token)/transactions.(format)
46
+ def from_last_fetch
47
+ fetch_and_deserialize_response('last', FioAPI.token, 'transactions.json')
48
+ end
49
+
50
+ # Allow request to set last transaction_id
51
+ #
52
+ # == Parameters:
53
+ # transaction_id::
54
+ # Id of transaction
55
+ #
56
+ # == Returns:
57
+ # List insatnce with account info and transactions list
58
+ #
59
+ # https://www.fio.cz/ib_api/rest/set-last-id/(token)/(id)/
60
+ def set_last_fetch_id(transaction_id)
61
+ fetch_and_deserialize_response('set-last-id', FioAPI.token, transaction_id)
62
+ end
63
+
64
+ # Allow request to set last request date
65
+ #
66
+ # == Parameters:
67
+ # date::
68
+ # Date when last request was provided
69
+ #
70
+ # == Returns:
71
+ # List insatnce with account info and transactions list
72
+ #
73
+ # https://www.fio.cz/ib_api/rest/set-last-date/(token)/(rrrr-mm-dd)/
74
+ def set_last_fetch_date(date)
75
+ fetch_and_deserialize_response('set-last-date', FioAPI.token, date)
76
+ end
77
+
78
+ private
79
+
80
+ # Create request object ot provided uri and instantiate list deserializer.
81
+ # Request uri and deserialize response to response object with account info and transactions list.
82
+ #
83
+ # == Parameters:
84
+ # args::
85
+ # Parts of uri
86
+ #
87
+ # == Returns:
88
+ # List insatnce with account info and transactions list
89
+ #
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
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,71 @@
1
+ require 'httparty'
2
+
3
+ module FioAPI
4
+ class Request < FioAPI::Base
5
+ # Consant of base part of uri for requesting
6
+ BASE_URI = "https://www.fio.cz/ib_api/rest/"
7
+
8
+ class << self
9
+
10
+ # Reader for token
11
+ def token
12
+ @@token
13
+ end
14
+
15
+ # Setter for token
16
+ def token= token
17
+ @@token = token
18
+ end
19
+ end
20
+
21
+ attr_accessor :uri, :response_json, :deserializer
22
+
23
+ # Make request to uri
24
+ #
25
+ # == Returns:
26
+ # Request instance
27
+ #
28
+ def fetch
29
+ self.response_json = HTTParty.get(uri)
30
+ self
31
+ end
32
+
33
+ # Set uri for request
34
+ #
35
+ # == Parameters:
36
+ # args::
37
+ # Parts of uri
38
+ #
39
+ # == Returns:
40
+ # Uri string
41
+ #
42
+ def set_uri(*args)
43
+ self.uri = construct_uri(*args)
44
+ end
45
+
46
+ # Reader for request response
47
+ #
48
+ # == Returns:
49
+ # Response as a JSON or a deserialilzed response. Depends if the deserializer is set
50
+ #
51
+ def response
52
+ @response ||= deserializer ? deserializer.deserialize(response_json) : response_json
53
+ end
54
+
55
+ private
56
+
57
+ # Uri constructor
58
+ #
59
+ # == Parameters:
60
+ # args::
61
+ # Parts of uri
62
+ #
63
+ # == Returns:
64
+ # Uri string
65
+ #
66
+ def construct_uri(*args)
67
+ url_parts = args.map(&:to_s).join("/")
68
+ URI::join(BASE_URI, url_parts).to_s
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ module FioAPI
2
+ # == Transaction class representing the Transaction entity
3
+ class Transaction < FioAPI::Base
4
+ attr_accessor :transaction_id, :date, :amount, :currency, :account, :account_name, :bank_code,
5
+ :bank_name, :ks, :vs, :ss, :user_identification, :message_for_recipient, :transaction_type,
6
+ :sender, :detail_info, :comment, :bic, :action_id
7
+ end
8
+ end
data/lib/base.rb ADDED
@@ -0,0 +1,20 @@
1
+ module FioAPI
2
+ class Base
3
+ # Allow ruby object to be initialized with params
4
+ #
5
+ # == Parameters:
6
+ # hash::
7
+ # Hash where key is attribute and value is new attribute value
8
+ #
9
+ # == Returns:
10
+ # New object with prefilled attributes
11
+ #
12
+ def initialize(*h)
13
+ if h.length == 1 && h.first.kind_of?(Hash)
14
+ h.first.each { |k,v| send("#{k}=",v) }
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+
data/lib/fio_api.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "utils/hash"
2
+ require "base"
3
+ require "base/deserializer"
4
+ require "base/account"
5
+ require "base/transaction"
6
+ require "base/list"
7
+ require "base/request"
8
+
9
+ module FioAPI
10
+ # == Returns:
11
+ # A string with current version of gem
12
+ #
13
+ VERSION = "0.0.1"
14
+
15
+ # Set API token for requests
16
+ #
17
+ # == Parameters:
18
+ # token::
19
+ # Long string generated in Fio API banking application
20
+ #
21
+ # == Returns:
22
+ # Token
23
+ #
24
+ def self.token= token
25
+ FioAPI::Request.token = token
26
+ end
27
+
28
+ # Get API token
29
+ #
30
+ # == Returns:
31
+ # Token from gem configuration
32
+ #
33
+ def self.token
34
+ FioAPI::Request.token
35
+ end
36
+ end
37
+
data/lib/utils/hash.rb ADDED
@@ -0,0 +1,22 @@
1
+ class Hash
2
+ # Try provided path on hash
3
+ #
4
+ # == Parameters:
5
+ # args::
6
+ # Keys of hash you want to try
7
+ #
8
+ # == Returns:
9
+ # Value or nil if key does not exist
10
+ #
11
+ def try_path(*args)
12
+ value = self
13
+ args.each{ |arg_name| value = value.nil? ? nil : value[arg_name] }
14
+ value
15
+ end
16
+ end
17
+
18
+ class NilClass
19
+ def try_path(*args)
20
+ nil
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FioAPI::Account do
4
+
5
+ describe "instance attributes" do
6
+
7
+ [:account_id, :bank_id, :currency, :iban,:bic,:opening_balance,:closing_balance,
8
+ :date_start, :date_end, :year_list, :id_list, :id_from, :id_to, :id_last_download].each do |attr|
9
+
10
+ it "should respond to #{attr}" do
11
+ FioAPI::Account.new.should respond_to(attr)
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FioAPI::Deserializer do
4
+
5
+ describe "deserialize" do
6
+
7
+ it "should raise exception" do
8
+ expect { FioAPI::Deserializer.new.deserialize }.to raise_error
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,92 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FioAPI::ListResponseDeserializer do
4
+
5
+ describe "instance attributes" do
6
+
7
+ it "should respond to account" do
8
+ FioAPI::ListResponseDeserializer.new.should respond_to(:account)
9
+ end
10
+
11
+ it "should respond to transactions" do
12
+ FioAPI::ListResponseDeserializer.new.should respond_to(:transactions)
13
+ end
14
+
15
+ end
16
+
17
+ describe "deserialization" do
18
+ before(:each) do
19
+ @deserializer = FioAPI::ListResponseDeserializer.new
20
+ end
21
+
22
+ it "deserialize account info" do
23
+ account_json = { "accountId" => "26457567988", "bankId" => "2010", "currency" => "CZK",
24
+ "iban" => "CZ03345356456702600147988", "bic" => "FIOBCZPPXXX", "openingBalance" => 0.0, "closingBalance" => 11669.96,
25
+ "dateStart" => "2011-01-01+0100", "dateEnd" => "2012-12-26+0100", "yearList" => 2012, "idList" => 353434,
26
+ "idFrom" => 1145645683284, "idTo" => 1167566706, "idLastDownload" => 234234234234
27
+ }
28
+
29
+ result = { :account_id => "26457567988", :bank_id => "2010", :currency => "CZK", :iban => "CZ03345356456702600147988",
30
+ :bic => "FIOBCZPPXXX", :opening_balance => 0.0, :closing_balance => 11669.96, :date_start => "2011-01-01+0100",
31
+ :date_end => "2012-12-26+0100", :year_list => 2012, :id_list => 353434, :id_from => 1145645683284,
32
+ :id_to => 1167566706, :id_last_download => 234234234234 }
33
+
34
+ deserialized = @deserializer.send(:deserialize_account, account_json)
35
+
36
+ result.each do |attr_name,value|
37
+ deserialized.send(attr_name).should eq(value)
38
+ end
39
+ end
40
+
41
+
42
+
43
+ it "deserialize transaction info" do
44
+ transaction_json = {
45
+ "column22" => { "value" => 1148734530, "name" => "ID pohybu", "id" => 22},
46
+ "column0" => { "value" => 1340661600000, "name" => "Datum", "id" => 0},
47
+ "column1" => { "value" => 1, "name" => "Objem", "id" => 1 },
48
+ "column14" => { "value" => "CZK", "name" => "Mena", "id" => 14 },
49
+ "column2" => { "value" => "2900233333", "name" => "Protiucet", "id" => 2 },
50
+ "column10" => { "value" => "Pavel, Novak", "name" => "Nazev protiuctu", "id" => 10},
51
+ "column3" => { "value" => "2010", "name" => "Kod banky", "id" => 3},
52
+ "column12" => { "value" => "Fio banka, a.s.", "name" => "Nazev banky", "id" => 12 },
53
+ "column4" => { "value" => "0558", "name" => "KS", "id" => 4 },
54
+ "column5" => { "value" => "0558345345345", "name" => "VS", "id" => 5 },
55
+ "column6" => { "value" => "055234", "name" => "SS", "id" => 6 },
56
+ "column7" => { "value" => "Prikaz", "name" => "Identifikace uzivatelem", "id" => 7 },
57
+ "column16" => { "value" => "Prikaz pro tomase", "name" => "Zprava pro prijemce", "id" => 16 },
58
+ "column8" => { "value" => "Prijem prevodem uvnitr banky", "name" => "Typ", "id" => 8 },
59
+ "column9" => { "value" => "Robin Bortlik", "name" => "Odesilatel", "id" => 9 },
60
+ "column18" => { "value" => "Detail info", "name" => "Detailni informace", "id" => 18 },
61
+ "column25" => { "value" => "Text", "name" => "Komentar", "id" => 25 },
62
+ "column26" => { "value" => "345790", "name" => "BIC", "id" => 26 },
63
+ "column17" => { "value" => 2105685816, "name" => "ID pokynu", "id" => 17}
64
+ }
65
+
66
+ result = {:date => 1340661600000, :amount => 1, :currency => "CZK", :account => "2900233333",
67
+ :account_name => "Pavel, Novak", :bank_code => "2010", :bank_name => "Fio banka, a.s.",
68
+ :ks => "0558", :vs => "0558345345345", :ss => "055234", :user_identification => "Prikaz",
69
+ :message_for_recipient => "Prikaz pro tomase", :transaction_type => "Prijem prevodem uvnitr banky",
70
+ :sender => "Robin Bortlik", :detail_info => "Detail info", :comment => "Text", :bic => "345790",
71
+ :action_id => 2105685816}
72
+
73
+ deserialized = @deserializer.send(:deserialize_transactions, [transaction_json])[0]
74
+
75
+ result.each do |attr_name,value|
76
+ deserialized.send(attr_name).should eq(value)
77
+ end
78
+ end
79
+
80
+ it "should return deserializer object with account and transactions" do
81
+ @deserializer.deserialize({"accountStatement" => {"transactionList" => {"transaction" => [{}] }}} )
82
+ @deserializer.account.class.should eq FioAPI::Account
83
+ @deserializer.transactions.class.should eq Array
84
+ @deserializer.transactions.first.class.should eq FioAPI::Transaction
85
+ end
86
+ end
87
+ end
88
+
89
+
90
+
91
+
92
+
@@ -0,0 +1,45 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FioAPI::List do
4
+ before(:each) do
5
+ @list = FioAPI::List.new
6
+ HTTParty.stub(:get) { {response: "response"} }
7
+ end
8
+
9
+ it "should set request with uri for date range" do
10
+ date_from = Date.new(2011,1,1)
11
+ date_to = Date.new(2012,11,25)
12
+ url = "https://www.fio.cz/ib_api/rest/periods/#{FioAPI.token}/#{date_from}/#{date_to}/transactions.json"
13
+ @list.by_date_range(date_from, date_to).request.uri.should eq url
14
+ end
15
+
16
+ it "should set request with uri for listing_id and year" do
17
+ year = 2012
18
+ id = "12345"
19
+ url = "https://www.fio.cz/ib_api/rest/by-id/#{FioAPI.token}/#{year}/#{id}/transactions.json"
20
+ @list.by_listing_id_and_year(id, year).request.uri.should eq url
21
+ end
22
+
23
+ it "should set request with uri from last fetch" do
24
+ url = "https://www.fio.cz/ib_api/rest/last/#{FioAPI.token}/transactions.json"
25
+ @list.from_last_fetch.request.uri.should eq url
26
+ end
27
+
28
+ it "should set request with uri to set last fetch id" do
29
+ id = "12345"
30
+ url = "https://www.fio.cz/ib_api/rest/set-last-id/#{FioAPI.token}/#{id}"
31
+ @list.set_last_fetch_id(id).request.uri.should eq url
32
+ end
33
+
34
+ it "should set request with uri to set last date" do
35
+ date = Date.new(2012,11,25)
36
+ url = "https://www.fio.cz/ib_api/rest/set-last-date/#{FioAPI.token}/#{date}"
37
+ @list.set_last_fetch_date(date).request.uri.should eq url
38
+ end
39
+
40
+ it "should fetch and deserialize response" do
41
+ @list.send(:fetch_and_deserialize_response)
42
+ @list.request.should_not be_nil
43
+ @list.response.should_not be_nil
44
+ end
45
+ end
@@ -0,0 +1,54 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FioAPI::Request do
4
+
5
+ it "should have defined token" do
6
+ FioAPI::Request.should respond_to :token
7
+ end
8
+
9
+ it "should have defined uri" do
10
+ FioAPI::Request.new.should respond_to :uri
11
+ end
12
+
13
+ it "should have defined response" do
14
+ FioAPI::Request.new.should respond_to :response
15
+ end
16
+
17
+ describe "fetch" do
18
+ before(:each) do
19
+ @response = {response: "response"}
20
+ HTTParty.stub(:get) { @response }
21
+ end
22
+
23
+ it "should fill the response" do
24
+ request = FioAPI::Request.new
25
+ request.fetch
26
+ request.response.should eq @response
27
+ end
28
+
29
+ it "should deserialize the response" do
30
+ deserializer = FioAPI::ListResponseDeserializer.new
31
+ request = FioAPI::Request.new(deserializer: deserializer)
32
+ request.fetch
33
+ request.response.should eq deserializer.deserialize(@response)
34
+ end
35
+ end
36
+
37
+ describe "uri manipulation" do
38
+ before(:each) do
39
+ FioAPI.token = "somelongtoken"
40
+ @url = "https://www.fio.cz/ib_api/rest/#{FioAPI.token}/transactions.json"
41
+ @request = FioAPI::Request.new
42
+ end
43
+
44
+ it "should construct uri from arguments" do
45
+ @request.send(:construct_uri, FioAPI.token, 'transactions.json').to_s.should eq @url
46
+ end
47
+
48
+ it "should set uri from arguments" do
49
+ @request.set_uri FioAPI.token, 'transactions.json'
50
+ @request.uri.should eq @url
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FioAPI::Transaction do
4
+
5
+ describe "instance attributes" do
6
+
7
+ [:transaction_id, :date, :amount, :currency, :account, :account_name, :bank_code,
8
+ :bank_name, :ks, :vs, :ss, :user_identification, :message_for_recipient, :transaction_type,
9
+ :sender, :detail_info, :comment, :bic, :action_id].each do |attr|
10
+
11
+ it "should respond to #{attr}" do
12
+ FioAPI::Transaction.new.should respond_to(attr)
13
+ end
14
+
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe FioAPI do
4
+ it "should setup token" do
5
+ token = "some token"
6
+ FioAPI.token = token
7
+ FioAPI::Request.token.should eq token
8
+ end
9
+
10
+ it "should return token" do
11
+ token = "some token"
12
+ FioAPI::Request.token = token
13
+ FioAPI.token.should eq token
14
+ end
15
+ end
16
+
17
+
18
+
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'fio_api'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ FioAPI.token = "somelongtoken"
11
+
12
+ RSpec.configure do |config|
13
+
14
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe Hash do
4
+
5
+ describe "try_path" do
6
+
7
+ it "should respond to try_path method" do
8
+ {}.should respond_to(:try_path)
9
+ end
10
+
11
+ it "should return nil if can't find key" do
12
+ {}.try_path("key1", "key2").should be_nil
13
+ end
14
+
15
+ it "should return value on path" do
16
+ {"key1" => {"key2" => "value"} }.try_path("key1", "key2").should eq "value"
17
+ end
18
+ end
19
+ end
20
+
21
+ describe NilClass do
22
+
23
+ describe "try_path" do
24
+
25
+ it "should respond to try_path method" do
26
+ nil.should respond_to(:try_path)
27
+ end
28
+
29
+ it "should return nil" do
30
+ nil.try_path("key1", "key2").should be_nil
31
+ end
32
+
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fio_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robin Bortlik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.8.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.8.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-mocks
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.8.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.12'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.2.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.4
110
+ description: API wrapper for FIO bank
111
+ email: robinbortlik@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ files:
118
+ - .rspec
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - fio_api.gemspec
126
+ - lib/base.rb
127
+ - lib/base/account.rb
128
+ - lib/base/deserializer.rb
129
+ - lib/base/deserializers/list_response_deserializer.rb
130
+ - lib/base/list.rb
131
+ - lib/base/request.rb
132
+ - lib/base/transaction.rb
133
+ - lib/fio_api.rb
134
+ - lib/utils/hash.rb
135
+ - spec/base/account_spec.rb
136
+ - spec/base/deserializer_spec.rb
137
+ - spec/base/deserializers/list_response_deserializer_spec.rb
138
+ - spec/base/list_spec.rb
139
+ - spec/base/request_spec.rb
140
+ - spec/base/transaction_spec.rb
141
+ - spec/fio_api_spec.rb
142
+ - spec/spec_helper.rb
143
+ - spec/utils/hash_spec.rb
144
+ homepage: http://github.com/robinbortlik/fio_api
145
+ licenses:
146
+ - MIT
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ segments:
158
+ - 0
159
+ hash: -4192978993207160883
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 1.8.24
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: API wrapper for FIO bank
172
+ test_files: []