ifin24-client 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/ifin24 +4 -3
- data/lib/ifin24/client.rb +19 -12
- data/lib/ifin24/commands/add_expense.rb +33 -28
- data/lib/ifin24/commands/base.rb +1 -0
- data/lib/ifin24/commands/list_entries.rb +10 -19
- data/lib/ifin24/commands/list_limits.rb +38 -7
- data/lib/ifin24/console.rb +13 -19
- data/lib/ifin24/helpers.rb +1 -0
- data/lib/ifin24/helpers/menu.rb +20 -0
- data/lib/ifin24/models/base.rb +0 -2
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/bin/ifin24
CHANGED
@@ -12,6 +12,7 @@ require 'optparse'
|
|
12
12
|
require 'ostruct'
|
13
13
|
|
14
14
|
require 'ifin24'
|
15
|
+
include Ifin24
|
15
16
|
|
16
17
|
class LoginError < StandardError
|
17
18
|
end
|
@@ -30,15 +31,15 @@ class App
|
|
30
31
|
def run
|
31
32
|
parse_options!
|
32
33
|
|
33
|
-
config =
|
34
|
+
config = Configuration.instance
|
34
35
|
login = @options.login || config[:login]
|
35
36
|
password = @options.password || config[:password]
|
36
37
|
|
37
38
|
begin
|
38
|
-
client =
|
39
|
+
client = Client.new(login, password)
|
39
40
|
client.login or raise LoginError
|
40
41
|
|
41
|
-
console =
|
42
|
+
console = Console.new(client)
|
42
43
|
console.main_menu
|
43
44
|
rescue LoginError
|
44
45
|
puts "Zły login lub hasło."
|
data/lib/ifin24/client.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
|
3
3
|
class Ifin24::Client
|
4
|
+
include Ifin24::Models
|
4
5
|
|
5
|
-
LOGIN_FORM_URL = 'https://www.ifin24.pl/logowanie'
|
6
|
-
ENTRY_FORM_URL = 'https://www.ifin24.pl/zarzadzanie-finansami/transakcje/dodaj-wydatek'
|
6
|
+
LOGIN_FORM_URL = 'https://www.ifin24.pl/logowanie'.freeze
|
7
|
+
ENTRY_FORM_URL = 'https://www.ifin24.pl/zarzadzanie-finansami/transakcje/dodaj-wydatek'.freeze
|
7
8
|
|
8
|
-
LIST_URL = 'https://www.ifin24.pl/zarzadzanie-finansami/transakcje/lista'
|
9
|
-
LIMITS_URL = 'https://www.ifin24.pl/zarzadzanie-finansami/kontrola-wydatkow'
|
9
|
+
LIST_URL = 'https://www.ifin24.pl/zarzadzanie-finansami/transakcje/lista'.freeze
|
10
|
+
LIMITS_URL = 'https://www.ifin24.pl/zarzadzanie-finansami/kontrola-wydatkow'.freeze
|
10
11
|
|
11
12
|
def initialize(login, password)
|
12
13
|
@login, @password = login, password
|
@@ -54,7 +55,7 @@ class Ifin24::Client
|
|
54
55
|
entry_elements = entry_row_element.search('td')
|
55
56
|
next if entry_elements.size != 5
|
56
57
|
|
57
|
-
entry =
|
58
|
+
entry = Entry.new
|
58
59
|
|
59
60
|
title_column = entry_elements[2]
|
60
61
|
entry.title = title_column.children[0].text.strip
|
@@ -64,7 +65,7 @@ class Ifin24::Client
|
|
64
65
|
entry.date = date_column.text.strip
|
65
66
|
|
66
67
|
category_column = entry_elements[3]
|
67
|
-
sub_category =
|
68
|
+
sub_category = Category.new(:name => category_column.children[0].text.strip)
|
68
69
|
entry.sub_category = sub_category
|
69
70
|
|
70
71
|
entry.tags = category_column.search('span').text.strip
|
@@ -77,14 +78,20 @@ class Ifin24::Client
|
|
77
78
|
return entries, total_pages
|
78
79
|
end
|
79
80
|
|
80
|
-
def fetch_limits
|
81
|
-
|
81
|
+
def fetch_limits(date = nil)
|
82
|
+
limits_url = "#{LIMITS_URL}"
|
83
|
+
if date
|
84
|
+
date = date.is_a?(Date) ? date.strftime("%Y-%m") : date
|
85
|
+
limits_url << "?data=#{date}"
|
86
|
+
end
|
87
|
+
|
88
|
+
page = agent.get(limits_url)
|
82
89
|
|
83
90
|
limits = []
|
84
91
|
|
85
92
|
table = page.search('table#expenses-tracking-limits tbody')
|
86
93
|
table.search('tr').each do |tr|
|
87
|
-
limit =
|
94
|
+
limit = Limit.new
|
88
95
|
columns = tr.search('td')
|
89
96
|
|
90
97
|
name_column = columns[0]
|
@@ -132,14 +139,14 @@ class Ifin24::Client
|
|
132
139
|
next if category_without_children
|
133
140
|
|
134
141
|
category_name = category_elem.children[0].text.strip
|
135
|
-
category =
|
142
|
+
category = Category.new(:name => category_name)
|
136
143
|
children_element = category_elem.children[1].children.search('li')
|
137
144
|
|
138
145
|
children_element.each do |child_elem|
|
139
146
|
child_id = child_elem.attributes['rel'].value
|
140
147
|
child_name = child_elem.text.strip
|
141
148
|
|
142
|
-
child =
|
149
|
+
child = Category.new(:id => child_id, :name => child_name)
|
143
150
|
category.children << child
|
144
151
|
end
|
145
152
|
|
@@ -159,7 +166,7 @@ class Ifin24::Client
|
|
159
166
|
next if id == '0' # skip the prompt
|
160
167
|
name = account_elem.text.strip
|
161
168
|
|
162
|
-
accounts <<
|
169
|
+
accounts << Account.new(:id => id, :name => name)
|
163
170
|
end
|
164
171
|
|
165
172
|
return accounts
|
@@ -1,34 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class Ifin24::Commands::AddExpense < Ifin24::Commands::Base
|
4
|
+
include Ifin24::Models
|
4
5
|
|
5
6
|
def execute
|
6
7
|
entry = get_entry
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
menu.choice("Powrót do głównego menu") do
|
23
|
-
throw :all_ok
|
24
|
-
end
|
25
|
-
|
26
|
-
menu.choice("Wyślij") do
|
27
|
-
puts "Wysyłanie danych..."
|
28
|
-
@client.send_entry(entry)
|
29
|
-
throw :all_ok
|
30
|
-
end
|
31
|
-
end
|
9
|
+
console_menu('Powrót do głównego menu') do |menu|
|
10
|
+
menu.choice("Nazwa: #{entry.title}") { get_title_for(entry) }
|
11
|
+
menu.choice("Data: #{entry.date}") { get_date_for(entry) }
|
12
|
+
menu.choice("Konto: #{entry.account.name}") { get_account_for(entry) }
|
13
|
+
menu.choice("Kategoria: #{entry.category_full_name}") { get_category_for(entry) }
|
14
|
+
menu.choice("Kwota: #{entry.amount}") { get_amount_for(entry) }
|
15
|
+
menu.choice("Tagi: #{entry.tags}") { get_tags_for(entry) }
|
16
|
+
menu.choice("Opis: #{entry.note}") { get_note_for(entry) }
|
17
|
+
|
18
|
+
menu.choice("Wyślij") do
|
19
|
+
puts "Wysyłanie danych..."
|
20
|
+
@client.send_entry(entry)
|
21
|
+
throw :exit
|
32
22
|
end
|
33
23
|
end
|
34
24
|
end
|
@@ -36,7 +26,7 @@ class Ifin24::Commands::AddExpense < Ifin24::Commands::Base
|
|
36
26
|
private
|
37
27
|
|
38
28
|
def get_entry
|
39
|
-
entry =
|
29
|
+
entry = Entry.new
|
40
30
|
|
41
31
|
get_title_for(entry)
|
42
32
|
get_date_for(entry)
|
@@ -54,9 +44,24 @@ class Ifin24::Commands::AddExpense < Ifin24::Commands::Base
|
|
54
44
|
end
|
55
45
|
|
56
46
|
def get_date_for(entry)
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
choose do |menu|
|
48
|
+
menu.prompt = 'Data: '
|
49
|
+
|
50
|
+
today = Date.today
|
51
|
+
menu.choice(today) do
|
52
|
+
entry.date = today
|
53
|
+
end
|
54
|
+
|
55
|
+
yesterday = today - 1
|
56
|
+
menu.choice(yesterday) do
|
57
|
+
entry.date = yesterday
|
58
|
+
end
|
59
|
+
|
60
|
+
menu.choice('Inna data') do
|
61
|
+
entry.date = ask('Data: ') do |q|
|
62
|
+
q.default = Date.today
|
63
|
+
end
|
64
|
+
end
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
data/lib/ifin24/commands/base.rb
CHANGED
@@ -7,28 +7,19 @@ class Ifin24::Commands::ListEntries < Ifin24::Commands::Base
|
|
7
7
|
list, pages = @client.fetch_entries(current_page)
|
8
8
|
print_entries(list)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
menu.index = :letter
|
14
|
-
menu.index_suffix = ") "
|
10
|
+
console_menu('Powrót do głównego menu') do |menu|
|
11
|
+
menu.choice("Poprzednia strona") do
|
12
|
+
current_page -= 1 if current_page > 1
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
list, pages = @client.fetch_entries(current_page)
|
20
|
-
print_entries(list)
|
21
|
-
end
|
22
|
-
|
23
|
-
menu.choice("Następna strona") do
|
24
|
-
current_page += 1 if current_page < pages
|
14
|
+
list, pages = @client.fetch_entries(current_page)
|
15
|
+
print_entries(list)
|
16
|
+
end
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
18
|
+
menu.choice("Następna strona") do
|
19
|
+
current_page += 1 if current_page < pages
|
29
20
|
|
30
|
-
|
31
|
-
|
21
|
+
list, pages = @client.fetch_entries(current_page)
|
22
|
+
print_entries(list)
|
32
23
|
end
|
33
24
|
end
|
34
25
|
end
|
@@ -1,21 +1,52 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class Ifin24::Commands::ListLimits < Ifin24::Commands::Base
|
4
|
-
LIMIT_BAR_SIZE =
|
4
|
+
LIMIT_BAR_SIZE = 64
|
5
5
|
|
6
6
|
def execute
|
7
|
-
|
7
|
+
curr_date = Date.today
|
8
|
+
limits = @client.fetch_limits(curr_date)
|
9
|
+
print_report(limits)
|
10
|
+
|
11
|
+
console_menu('Powrót do głównego menu') do |menu|
|
12
|
+
menu.choice("Poprzedni miesiąc") do
|
13
|
+
curr_date = curr_date << 1
|
14
|
+
|
15
|
+
limits = @client.fetch_limits(curr_date)
|
16
|
+
print_report(limits)
|
17
|
+
end
|
18
|
+
|
19
|
+
menu.choice("Następny miesiąc") do
|
20
|
+
curr_date = curr_date >> 1
|
21
|
+
|
22
|
+
limits = @client.fetch_limits(curr_date)
|
23
|
+
print_report(limits)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def print_report(limits)
|
31
|
+
widest_name_size = limits.inject(0) { |max, limit| limit.name.size >= max ? limit.name.size : max }
|
32
|
+
|
8
33
|
limits.each do |limit|
|
9
|
-
widest_name_size = limits.map { |l| l.name }.inject(0) { |max, name| name.size >= max ? name.size : max }
|
10
34
|
name = limit.name.ljust(widest_name_size)
|
11
35
|
limit_bar = make_limit_bar(limit.amount, limit.max)
|
12
|
-
|
36
|
+
amount_summary = "#{limit.amount}zł z #{limit.max}zł"
|
13
37
|
|
14
|
-
puts "#{name} #{limit_bar} #{
|
38
|
+
puts "#{name} #{limit_bar} #{amount_summary}"
|
15
39
|
end
|
16
|
-
end
|
17
40
|
|
18
|
-
|
41
|
+
total_amount = limits.inject(0) { |sum, limit| sum += limit.amount }
|
42
|
+
total_max = limits.inject(0) { |sum, limit| sum += limit.max }
|
43
|
+
|
44
|
+
total_name = 'Podsumowanie:'.ljust(widest_name_size)
|
45
|
+
total_limit_bar = make_limit_bar(total_amount, total_max)
|
46
|
+
total_amount_summary = "#{total_amount}zł z #{total_max}zł"
|
47
|
+
|
48
|
+
puts "\n#{total_name} #{total_limit_bar} #{total_amount_summary}"
|
49
|
+
end
|
19
50
|
|
20
51
|
def make_limit_bar(amount, max)
|
21
52
|
limit_exceeded = amount >= max
|
data/lib/ifin24/console.rb
CHANGED
@@ -1,44 +1,38 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class Ifin24::Console
|
4
|
+
include Ifin24
|
5
|
+
include Helpers::Menu
|
4
6
|
|
5
7
|
def initialize(client)
|
6
8
|
@client = client
|
7
9
|
end
|
8
10
|
|
9
11
|
def main_menu
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
menu.choice("Dodaj wydatek") { add_expense }
|
18
|
-
menu.choice("Lista kont") { list_accounts }
|
19
|
-
menu.choice("Lista ostatnich transakcji") { list_entries }
|
20
|
-
menu.choice("Kontrola wydatków") { list_limits }
|
21
|
-
|
22
|
-
menu.choice("Koniec") { throw :exit }
|
23
|
-
end
|
24
|
-
end
|
12
|
+
console_menu('Koniec') do |menu|
|
13
|
+
menu.header = "Menu główne"
|
14
|
+
|
15
|
+
menu.choice("Dodaj wydatek") { add_expense }
|
16
|
+
menu.choice("Lista kont") { list_accounts }
|
17
|
+
menu.choice("Lista ostatnich transakcji") { list_entries }
|
18
|
+
menu.choice("Kontrola wydatków") { list_limits }
|
25
19
|
end
|
26
20
|
end
|
27
21
|
|
28
22
|
def add_expense
|
29
|
-
execute_command(
|
23
|
+
execute_command(Commands::AddExpense)
|
30
24
|
end
|
31
25
|
|
32
26
|
def list_accounts
|
33
|
-
execute_command(
|
27
|
+
execute_command(Commands::ListAccounts)
|
34
28
|
end
|
35
29
|
|
36
30
|
def list_entries
|
37
|
-
execute_command(
|
31
|
+
execute_command(Commands::ListEntries)
|
38
32
|
end
|
39
33
|
|
40
34
|
def list_limits
|
41
|
-
execute_command(
|
35
|
+
execute_command(Commands::ListLimits)
|
42
36
|
end
|
43
37
|
|
44
38
|
private
|
data/lib/ifin24/helpers.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ifin24::Helpers
|
2
|
+
module Menu
|
3
|
+
|
4
|
+
def console_menu(exit_prompt)
|
5
|
+
catch :exit do
|
6
|
+
loop do
|
7
|
+
choose do |menu|
|
8
|
+
menu.index = :letter
|
9
|
+
menu.index_suffix = ") "
|
10
|
+
|
11
|
+
yield menu
|
12
|
+
|
13
|
+
menu.choice(exit_prompt) { throw :exit }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/ifin24/models/base.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ifin24-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "\xC5\x81ukasz Bandzarewicz"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-22 00:00:00 +02:00
|
19
19
|
default_executable: ifin24
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/ifin24/configuration.rb
|
121
121
|
- lib/ifin24/console.rb
|
122
122
|
- lib/ifin24/helpers.rb
|
123
|
+
- lib/ifin24/helpers/menu.rb
|
123
124
|
- lib/ifin24/helpers/printer.rb
|
124
125
|
- lib/ifin24/models.rb
|
125
126
|
- lib/ifin24/models/account.rb
|