Module: Countir::ResourceBasedMethods

Included in:
Client
Defined in:
lib/countir/resource_based_methods.rb

Instance Method Summary collapse

Instance Method Details

#list_account_codesObject



3
4
5
# File 'lib/countir/resource_based_methods.rb', line 3

def 
  get('/account_codes', resource_class: Countir::AccountCode)
end

#list_journals(offset: nil, limit: nil) ⇒ Object



7
8
9
10
# File 'lib/countir/resource_based_methods.rb', line 7

def list_journals(offset: nil, limit: nil)
  params = {offset: offset, limit: limit}
  get('/journals', params, resource_class: Countir::Journal)
end

#post_journal(transaction_date:, memo:, entries:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/countir/resource_based_methods.rb', line 12

def post_journal(transaction_date:, memo:, entries:)
  unless entries.class == Array
    message = "entries should must be Array value"
    raise Countir::InvalidParameter.new(message)
  end

  entry_keys = [:account_code_id, :debit_or_credit, :price]

  entries_has_valid_keys = entries.map do |entry|
    entry.keys.sort == entry_keys
  end.all?

  unless entries_has_valid_keys
    message = sprintf("entry should have keys [%s]", entry_keys.join(?,))
    raise Countir::InvalidParameter.new(message)
  end

  params = {
    transaction_date: transaction_date,
    memo: memo,
    # entries: entry_keys.zip(*entries.valies_at(entry_keys)).to_h,
    entries: entries,
    images: [],
  }

  post('/journals', params)
end