Class: Ifin24::Client
- Inherits:
-
Object
- Object
- Ifin24::Client
- Defined in:
- lib/ifin24/client.rb
Constant Summary collapse
- LOGIN_FORM_URL =
'https://www.ifin24.pl/logowanie'
- ENTRY_FORM_URL =
'https://www.ifin24.pl/zarzadzanie-finansami/transakcje/dodaj-wydatek'
- LIST_URL =
'https://www.ifin24.pl/zarzadzanie-finansami/transakcje/lista'
- LIST_PAGE_PARAM =
'?pageNumber='
Instance Method Summary collapse
- #accounts ⇒ Object
- #categories ⇒ Object
- #fetch_entries(curr_page = 1) ⇒ Object
-
#initialize(login, password) ⇒ Client
constructor
A new instance of Client.
- #logged? ⇒ Boolean
- #send_entry(entry) ⇒ Object
Constructor Details
#initialize(login, password) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/ifin24/client.rb', line 8 def initialize(login, password) @agent = Mechanize.new login(login, password) end |
Instance Method Details
#accounts ⇒ Object
17 18 19 |
# File 'lib/ifin24/client.rb', line 17 def accounts fetch_accounts end |
#categories ⇒ Object
13 14 15 |
# File 'lib/ifin24/client.rb', line 13 def categories @categories ||= fetch_categories end |
#fetch_entries(curr_page = 1) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ifin24/client.rb', line 36 def fetch_entries(curr_page = 1) page = @agent.get(LIST_URL + LIST_PAGE_PARAM + curr_page.to_s) total_pages = extract_entries_total_pages(page) entry_row_elements = page.search('table tbody tr') entries = [] entry_row_elements.each do |entry_row_element| entry_elements = entry_row_element.search('td') next if entry_elements.size != 5 entry = Ifin24::Models::Entry.new title_column = entry_elements[2] entry.title = title_column.children[0].text.strip entry.note = title_column.search('span').text.strip date_column = entry_elements[1] entry.date = date_column.text.strip category_column = entry_elements[3] sub_category = Ifin24::Models::Category.new(:name => category_column.children[0].text.strip) entry.sub_category = sub_category entry. = category_column.search('span').text.strip amount_column = entry_elements[4] entry.amount = amount_column.text.strip entries << entry end return entries, total_pages end |
#logged? ⇒ Boolean
70 71 72 |
# File 'lib/ifin24/client.rb', line 70 def logged? @logged end |
#send_entry(entry) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ifin24/client.rb', line 21 def send_entry(entry) page = @agent.get(ENTRY_FORM_URL) form = page.forms.first form['entry.title'] = entry.title.to_s form['entry.date'] = entry.date.to_s form['selectedBankAccount'] = entry.account.id.to_s form['entry.entryCategory.id'] = entry.sub_category.id.to_s form['entry.amount'] = entry.amount.to_s form['value'] = entry..to_s form['entry.note'] = entry.note.to_s form.submit end |