xero-cli 0.0.2 → 0.0.3
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.
- checksums.yaml +5 -5
- data/lib/xero_api.rb +5 -5
- data/lib/xero_cli.rb +1 -0
- data/lib/xero_cli/accounts_storage.rb +19 -0
- data/lib/xero_cli/commands/accounts.rb +1 -0
- data/lib/xero_cli/commands/base.rb +1 -1
- data/lib/xero_cli/commands/receive.rb +5 -4
- data/lib/xero_cli/commands/spend.rb +5 -4
- data/lib/xero_cli/commands/transfer.rb +2 -2
- data/lib/xero_cli/constants.rb +1 -1
- data/lib/xero_cli/helper.rb +1 -6
- data/lib/xero_cli/options.rb +1 -5
- data/lib/xero_cli/templates/transaction.rb +14 -8
- data/lib/xero_cli/templates/transfer.rb +4 -4
- data/lib/xero_cli/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3fa43c4c67c9638663ea8ae28f0719ab66f7895b
|
4
|
+
data.tar.gz: 5df056a65e8371f199a95335fb78e139d0b4c51f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 333361104b7aced7143ddd72e161ebb1ecd24fe9439d60d014b0dc621cf4d3f5d9eae7a2a41e54793e6fdab8cd662f78913b61297c9cde8b9c13839316eb2482
|
7
|
+
data.tar.gz: 33ba21c0e134bc0b5aa43268091efacd24a7936aace642189d7080ae991db443d902b1ae48248d67755946fe8369377324513911db6460172d21d963d3ac8c6e
|
data/lib/xero_api.rb
CHANGED
@@ -15,12 +15,12 @@ class XeroAPI
|
|
15
15
|
[]
|
16
16
|
end
|
17
17
|
|
18
|
-
def new_transaction(transaction_data
|
19
|
-
post('/transactions/new', data: transaction_data
|
18
|
+
def new_transaction(transaction_data)
|
19
|
+
post('/transactions/new', data: transaction_data)
|
20
20
|
end
|
21
21
|
|
22
|
-
def new_invoice(invoice_data
|
23
|
-
post('/invoices/new', data: invoice_data
|
22
|
+
def new_invoice(invoice_data)
|
23
|
+
post('/invoices/new', data: invoice_data)
|
24
24
|
end
|
25
25
|
|
26
26
|
def new_transfer(transfer_data)
|
@@ -28,7 +28,7 @@ class XeroAPI
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def balance(bank_name)
|
31
|
-
|
31
|
+
get('/balance', { bank_name: bank_name }).body
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
data/lib/xero_cli.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative '../lib/xero_cli/helper'
|
|
11
11
|
require_relative '../lib/xero_cli/options_parser'
|
12
12
|
require_relative '../lib/xero_cli/options'
|
13
13
|
require_relative '../lib/xero_cli/credentials'
|
14
|
+
require_relative '../lib/xero_cli/accounts_storage'
|
14
15
|
require_relative '../lib/xero_cli/commands'
|
15
16
|
require_relative '../lib/xero_cli/commands/base'
|
16
17
|
require_relative '../lib/xero_cli/commands/spend'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
class AccountsStorage
|
3
|
+
JSON_FILE = 'accounts_storage.json'.freeze
|
4
|
+
|
5
|
+
def self.set(accounts)
|
6
|
+
File.open(JSON_FILE, 'w+') do |file|
|
7
|
+
file.write(accounts.to_json)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find_account_code_by_name(name)
|
12
|
+
file = File.read(JSON_FILE)
|
13
|
+
data_hash = JSON.parse(file)
|
14
|
+
data_hash.find { |element| element['name'] == name }['code']
|
15
|
+
rescue StandardError
|
16
|
+
raise Exception, 'Wrong category name'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -2,7 +2,7 @@ class XeroCLI::Commands::Receive < XeroCLI::Commands::Base
|
|
2
2
|
TRANSACTION_TYPE = 'RECEIVE'.freeze
|
3
3
|
|
4
4
|
def initialize(options)
|
5
|
-
@receive = options.receive
|
5
|
+
@receive = options.receive.to_f
|
6
6
|
@to = options.to
|
7
7
|
@from = options.from
|
8
8
|
@on = options.on
|
@@ -11,7 +11,8 @@ class XeroCLI::Commands::Receive < XeroCLI::Commands::Base
|
|
11
11
|
|
12
12
|
def perform
|
13
13
|
check_exceptions
|
14
|
-
|
14
|
+
account_code = as.nil? ? nil : XeroCLI::AccountsStorage.find_account_code_by_name(as)
|
15
|
+
transaction_attributes = XeroCLI::Templates::Transaction.attributes(receive, TRANSACTION_TYPE, from, to, account_code, on)
|
15
16
|
create_transaction(transaction_attributes)
|
16
17
|
write_to_terminal
|
17
18
|
end
|
@@ -26,7 +27,7 @@ class XeroCLI::Commands::Receive < XeroCLI::Commands::Base
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def write_to_terminal
|
29
|
-
output = ["Received #{
|
30
|
+
output = ["Received #{receive}"]
|
30
31
|
output << "from #{from}"
|
31
32
|
output << "to #{to || XeroCLI::Constants::STRIPE_BANK_NAME}"
|
32
33
|
output << "as #{as}" if as
|
@@ -35,6 +36,6 @@ class XeroCLI::Commands::Receive < XeroCLI::Commands::Base
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def create_transaction(json)
|
38
|
-
xero_api.new_transaction(json
|
39
|
+
xero_api.new_transaction(json)
|
39
40
|
end
|
40
41
|
end
|
@@ -2,7 +2,7 @@ class XeroCLI::Commands::Spend < XeroCLI::Commands::Base
|
|
2
2
|
TRANSACTION_TYPE = 'SPEND'.freeze
|
3
3
|
|
4
4
|
def initialize(options)
|
5
|
-
@spend = options.spend
|
5
|
+
@spend = options.spend.to_f
|
6
6
|
@to = options.to
|
7
7
|
@from = options.from
|
8
8
|
@on = options.on
|
@@ -11,7 +11,8 @@ class XeroCLI::Commands::Spend < XeroCLI::Commands::Base
|
|
11
11
|
|
12
12
|
def perform
|
13
13
|
check_exceptions
|
14
|
-
|
14
|
+
account_code = as.nil? ? nil : XeroCLI::AccountsStorage.find_account_code_by_name(as)
|
15
|
+
transaction_attributes = XeroCLI::Templates::Transaction.attributes(spend, TRANSACTION_TYPE, to, from, account_code, on)
|
15
16
|
create_transaction(transaction_attributes)
|
16
17
|
write_to_terminal
|
17
18
|
end
|
@@ -26,7 +27,7 @@ class XeroCLI::Commands::Spend < XeroCLI::Commands::Base
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def write_to_terminal
|
29
|
-
output = ["Spent #{
|
30
|
+
output = ["Spent #{spend}"]
|
30
31
|
output << "from #{from || XeroCLI::Constants::STRIPE_BANK_NAME}"
|
31
32
|
output << "to #{to}"
|
32
33
|
output << "as #{as}" if as
|
@@ -35,6 +36,6 @@ class XeroCLI::Commands::Spend < XeroCLI::Commands::Base
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def create_transaction(json)
|
38
|
-
xero_api.new_transaction(json
|
39
|
+
xero_api.new_transaction(json)
|
39
40
|
end
|
40
41
|
end
|
@@ -2,7 +2,7 @@ class XeroCLI::Commands::Transfer < XeroCLI::Commands::Base
|
|
2
2
|
TRANSACTION_TYPE = 'RECEIVE'.freeze
|
3
3
|
|
4
4
|
def initialize(options)
|
5
|
-
@transfer = options.transfer
|
5
|
+
@transfer = options.transfer.to_f
|
6
6
|
@to = options.to
|
7
7
|
@from = options.from
|
8
8
|
@on = options.on
|
@@ -26,7 +26,7 @@ class XeroCLI::Commands::Transfer < XeroCLI::Commands::Base
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def write_to_terminal
|
29
|
-
output = ["Transfer #{
|
29
|
+
output = ["Transfer #{transfer}"]
|
30
30
|
output << "from #{from}"
|
31
31
|
output << "to #{to}"
|
32
32
|
output << "on #{format_date(on)}" if on
|
data/lib/xero_cli/constants.rb
CHANGED
data/lib/xero_cli/helper.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
module XeroCLI
|
2
2
|
module Helper
|
3
|
-
def money_in_cents(string_amount)
|
4
|
-
return if string_amount.nil?
|
5
|
-
(string_amount.to_f * 100).to_i
|
6
|
-
end
|
7
|
-
|
8
3
|
def parse_datetime(option)
|
9
|
-
DateTime.parse(option) if option
|
4
|
+
DateTime.parse(option).to_time.to_i if option
|
10
5
|
end
|
11
6
|
end
|
12
7
|
end
|
data/lib/xero_cli/options.rb
CHANGED
@@ -8,11 +8,7 @@ module XeroCLI
|
|
8
8
|
@options = options
|
9
9
|
end
|
10
10
|
|
11
|
-
%w[spend receive transfer].each do |key|
|
12
|
-
define_method(key) { money_in_cents(options[key.to_sym]) }
|
13
|
-
end
|
14
|
-
|
15
|
-
%w[help set_guid get_guid show_guid show_accounts to on as from balance].each do |key|
|
11
|
+
%w[help set_guid get_guid show_guid show_accounts to on as from balance spend receive transfer].each do |key|
|
16
12
|
define_method(key) { options[key.to_sym] }
|
17
13
|
end
|
18
14
|
|
@@ -1,15 +1,21 @@
|
|
1
1
|
module XeroCLI
|
2
2
|
module Templates
|
3
3
|
class Transaction
|
4
|
-
def self.attributes(amount, type, user_name, bank_name,
|
4
|
+
def self.attributes(amount, type, user_name, bank_name, account_code, date)
|
5
5
|
{
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
date: date,
|
7
|
+
type: type,
|
8
|
+
is_reconciled: false,
|
9
|
+
line_items: {
|
10
|
+
description: 'Transaction created manually',
|
11
|
+
quantity: 1,
|
12
|
+
unit_amount: amount,
|
13
|
+
account_code: account_code || XeroCLI::Constants::DEFAULT_CATEGORY_CODE
|
14
|
+
},
|
15
|
+
contact: {
|
16
|
+
name: user_name
|
17
|
+
},
|
18
|
+
bank_name: bank_name
|
13
19
|
}
|
14
20
|
end
|
15
21
|
end
|
@@ -4,10 +4,10 @@ module XeroCLI
|
|
4
4
|
def self.attributes(amount, from_bank_name, to_bank_name, date)
|
5
5
|
xero_date = date ? date.to_time : Time.now
|
6
6
|
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
date: xero_date.to_i,
|
8
|
+
amount: amount,
|
9
|
+
from_bank_name: from_bank_name,
|
10
|
+
to_bank_name: to_bank_name
|
11
11
|
}
|
12
12
|
end
|
13
13
|
end
|
data/lib/xero_cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xero-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xenon Ventures
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- bin/xero
|
81
81
|
- lib/xero_api.rb
|
82
82
|
- lib/xero_cli.rb
|
83
|
+
- lib/xero_cli/accounts_storage.rb
|
83
84
|
- lib/xero_cli/commands.rb
|
84
85
|
- lib/xero_cli/commands/accounts.rb
|
85
86
|
- lib/xero_cli/commands/balance.rb
|
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.6.12
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
122
|
summary: Because real operators take command.
|