xero-cli 0.0.1
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 +7 -0
- data/README.MD +42 -0
- data/Rakefile +34 -0
- data/bin/xero +12 -0
- data/lib/xero_api.rb +59 -0
- data/lib/xero_cli/commands/accounts.rb +18 -0
- data/lib/xero_cli/commands/balance.rb +21 -0
- data/lib/xero_cli/commands/base.rb +19 -0
- data/lib/xero_cli/commands/receive.rb +40 -0
- data/lib/xero_cli/commands/spend.rb +40 -0
- data/lib/xero_cli/commands/transfer.rb +39 -0
- data/lib/xero_cli/commands.rb +90 -0
- data/lib/xero_cli/constants.rb +7 -0
- data/lib/xero_cli/credentials.rb +19 -0
- data/lib/xero_cli/helper.rb +12 -0
- data/lib/xero_cli/options.rb +23 -0
- data/lib/xero_cli/options_parser.rb +103 -0
- data/lib/xero_cli/templates/transaction.rb +17 -0
- data/lib/xero_cli/templates/transfer.rb +15 -0
- data/lib/xero_cli/version.rb +3 -0
- data/lib/xero_cli.rb +36 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fa2b61c97b3d54deb7a2b2c75d4dd8ab2d050377ec65c0f1fa48dfb459166b7
|
4
|
+
data.tar.gz: 825b789d43fa3f43d798de84e556402b242d1d557349f337e3fc4b629a4e6034
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7dda2fd40d5e6b127f5ccd8514b06a9d83a38e7f7ec6a78ea08b121f42626423a00f3b904d82a980d4c730f9404981eb8f5d5497631b89dab1a2457120166f7
|
7
|
+
data.tar.gz: ca81c58f55d93b154623886cee42308b573c043cceb3f02e57bd37ca6623208dd88e3bb44929ac9ed1f07a37b8b33085192bef273bd489b8e5d983f85bee9eb6
|
data/README.MD
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Usage: xero [OPTIONS]
|
2
|
+
|
3
|
+
Commands
|
4
|
+
|
5
|
+
xero --set 'YOUR_XERO_GUID' // saves you GUID to json file
|
6
|
+
xero --guid // shows current GUID
|
7
|
+
xero --get-guid // opens browser where you can get your GUID
|
8
|
+
xero --accounts // shows all available accounts
|
9
|
+
xero --accounts BANK // shows all accounts with type 'BANK'
|
10
|
+
|
11
|
+
xero --receive 45.67 --from 'Contact name' --to 'Bank Account Name' // '--to' is optional, uses Stripe account if not set
|
12
|
+
xero --spend 45.67 --from 'Bank Account Name' --to 'Contact name' // '--from' is optional, uses Stripe account if not set
|
13
|
+
--as 'Category Account Name' // sets Category for transaction, uses 'Sales' category if not set
|
14
|
+
--on 'dd-MM-yyyy' // sets the Date for transaction, uses 'Time.now' if not set
|
15
|
+
|
16
|
+
xero --transfer 1000 --from 'Stripe Merchant Account' --to 'Bank Account Name' // transfers money from one bank to another
|
17
|
+
|
18
|
+
xero --balance 'My Bank' // shows current balance
|
19
|
+
|
20
|
+
Options
|
21
|
+
|
22
|
+
-s, --set GUID Set GUID
|
23
|
+
-g, --guid Show current GUID
|
24
|
+
--get-guid Open browser to get GUID
|
25
|
+
-a, --accounts [TYPE] Show available accounts
|
26
|
+
-h, --help help
|
27
|
+
--spend AMOUNT Amount in dollars (e.g. 456.78)
|
28
|
+
--receive AMOUNT Amount in dollars (e.g. 456.78)
|
29
|
+
--transfer AMOUNT Amount in dollars (e.g. 456.78)
|
30
|
+
--balance BANK_NAME Bank name
|
31
|
+
--on DATE Time in format dd-mm-yyyy
|
32
|
+
--as TYPE Category account name
|
33
|
+
--from NAME Sender`s name (Bank or Contact)
|
34
|
+
--to NAME Receiver`s name (Bank or Contact)
|
35
|
+
|
36
|
+
|
37
|
+
# Building the GEM
|
38
|
+
gem install bundler
|
39
|
+
bundle install
|
40
|
+
rake build
|
41
|
+
rake install # Use locally
|
42
|
+
gem push pkg/... # Publish
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Straasio'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.libs << 'test'
|
24
|
+
t.pattern = 'test/**/*_test.rb'
|
25
|
+
t.verbose = false
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: :test
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec)
|
33
|
+
rescue LoadError
|
34
|
+
end
|
data/bin/xero
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENV_FILE = '.env'.freeze
|
4
|
+
unless File.exist?(ENV_FILE)
|
5
|
+
File.open(ENV_FILE, 'w') { |file| file.write('XERO_CONNECTOR_URL=') }
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'dotenv/load'
|
9
|
+
unless ARGV[0] == '-h' || ARGV[0] == '--help'
|
10
|
+
raise Exception, 'Please set XERO_CONNECTOR_URL in .env' if ENV['XERO_CONNECTOR_URL'].empty?
|
11
|
+
end
|
12
|
+
require 'xero_cli'
|
data/lib/xero_api.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class XeroAPI
|
4
|
+
def initialize(xero_guid)
|
5
|
+
@xero_guid = xero_guid
|
6
|
+
end
|
7
|
+
|
8
|
+
def accounts(type = nil)
|
9
|
+
return cached_accounts if type.nil?
|
10
|
+
cached_accounts.find_all { |account| account.type == type }
|
11
|
+
rescue StandardError # Handles unauthorized case
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
|
15
|
+
def new_transaction(transaction_data, category_code)
|
16
|
+
post('/transactions/new', data: transaction_data, category_code: category_code)
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_invoice(invoice_data, category_code)
|
20
|
+
post('/invoices/new', data: invoice_data, category_code: category_code)
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_transfer(transfer_data)
|
24
|
+
post('/transfers/new', data: transfer_data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def balance(bank_name)
|
28
|
+
post('/balance', data: { bank_name: bank_name }).body
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :xero_guid
|
34
|
+
|
35
|
+
def cached_accounts
|
36
|
+
@cached_accounts ||= get('/accounts/').map do |account_hash|
|
37
|
+
OpenStruct.new(account_hash)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def post(path, body)
|
42
|
+
HTTParty.post(
|
43
|
+
request_url(path),
|
44
|
+
body: body.merge(xero_guid: xero_guid).to_json,
|
45
|
+
headers: { 'Content-Type' => 'application/json' }
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def get(path, query = {})
|
50
|
+
HTTParty.get(
|
51
|
+
request_url(path),
|
52
|
+
query: query.merge(guid: xero_guid)
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_url(path)
|
57
|
+
ENV['XERO_CONNECTOR_URL'] + path
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class XeroCLI::Commands::Accounts < XeroCLI::Commands::Base
|
2
|
+
def initialize(options)
|
3
|
+
@show_accounts = options.show_accounts
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
accounts = get_account(show_accounts == 'ALL' ? nil : show_accounts)
|
8
|
+
ap accounts
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
attr_reader :show_accounts
|
14
|
+
|
15
|
+
def get_account(type)
|
16
|
+
xero_api.accounts(type)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class XeroCLI::Commands::Balance < XeroCLI::Commands::Base
|
2
|
+
def initialize(options)
|
3
|
+
@bank_name = options.balance
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
balance = get_balance(bank_name)
|
8
|
+
result = JSON.parse(balance)['balance']
|
9
|
+
ap "#{bank_name}: #{result}"
|
10
|
+
rescue StandardError
|
11
|
+
ap "Couldn't find bank with name '#{bank_name}'"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :bank_name
|
17
|
+
|
18
|
+
def get_balance(bank_name)
|
19
|
+
xero_api.balance(bank_name)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class XeroCLI::Commands::Base
|
2
|
+
def read_guid
|
3
|
+
@read_guid ||= XeroCLI::Credentials.read_guid
|
4
|
+
end
|
5
|
+
|
6
|
+
def xero_api
|
7
|
+
@xero_api ||= XeroAPI.new(read_guid)
|
8
|
+
rescue StandardError
|
9
|
+
raise Exception, 'Please set XERO_CONNECTOR_URL' if ENV['XERO_CONNECTOR_URL'].empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def money_to_cents(amount)
|
13
|
+
amount / 100.0
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_date(on)
|
17
|
+
on.strftime('%d-%m-%Y')
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class XeroCLI::Commands::Receive < XeroCLI::Commands::Base
|
2
|
+
TRANSACTION_TYPE = 'RECEIVE'.freeze
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
@receive = options.receive
|
6
|
+
@to = options.to
|
7
|
+
@from = options.from
|
8
|
+
@on = options.on
|
9
|
+
@as = options.as
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
check_exceptions
|
14
|
+
transaction_attributes = XeroCLI::Templates::Transaction.attributes(receive, TRANSACTION_TYPE, from, to, as, on)
|
15
|
+
create_transaction(transaction_attributes)
|
16
|
+
write_to_terminal
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :receive, :to, :from, :on, :as
|
22
|
+
|
23
|
+
def check_exceptions
|
24
|
+
raise Exception, 'Amount should positive' if receive.negative? || receive.zero?
|
25
|
+
raise Exception, 'Please add "--from NAME"' if from.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_to_terminal
|
29
|
+
output = ["Received #{money_to_cents(receive)}"]
|
30
|
+
output << "from #{from}"
|
31
|
+
output << "to #{to || XeroCLI::Constants::STRIPE_BANK_NAME}"
|
32
|
+
output << "as #{as}" if as
|
33
|
+
output << "on #{format_date(on)}" if on
|
34
|
+
ap output.join(' ')
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_transaction(json)
|
38
|
+
xero_api.new_transaction(json, nil)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class XeroCLI::Commands::Spend < XeroCLI::Commands::Base
|
2
|
+
TRANSACTION_TYPE = 'SPEND'.freeze
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
@spend = options.spend
|
6
|
+
@to = options.to
|
7
|
+
@from = options.from
|
8
|
+
@on = options.on
|
9
|
+
@as = options.as
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
check_exceptions
|
14
|
+
transaction_attributes = XeroCLI::Templates::Transaction.attributes(spend, TRANSACTION_TYPE, to, from, as, on)
|
15
|
+
create_transaction(transaction_attributes)
|
16
|
+
write_to_terminal
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :spend, :to, :from, :on, :as
|
22
|
+
|
23
|
+
def check_exceptions
|
24
|
+
raise Exception, 'Amount should positive' if spend.negative? || spend.zero?
|
25
|
+
raise Exception, 'Please add "--to NAME"' if to.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_to_terminal
|
29
|
+
output = ["Spent #{money_to_cents(spend)}"]
|
30
|
+
output << "from #{from || XeroCLI::Constants::STRIPE_BANK_NAME}"
|
31
|
+
output << "to #{to}"
|
32
|
+
output << "as #{as}" if as
|
33
|
+
output << "on #{format_date(on)}" if on
|
34
|
+
ap output.join(' ')
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_transaction(json)
|
38
|
+
xero_api.new_transaction(json, nil)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class XeroCLI::Commands::Transfer < XeroCLI::Commands::Base
|
2
|
+
TRANSACTION_TYPE = 'RECEIVE'.freeze
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
@transfer = options.transfer
|
6
|
+
@to = options.to
|
7
|
+
@from = options.from
|
8
|
+
@on = options.on
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
check_exceptions
|
13
|
+
transfer_attributes = XeroCLI::Templates::Transfer.attributes(transfer, from, to, on)
|
14
|
+
create_transfer(transfer_attributes)
|
15
|
+
write_to_terminal
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :transfer, :to, :from, :on
|
21
|
+
|
22
|
+
def check_exceptions
|
23
|
+
raise Exception, 'Amount should positive' if transfer.negative? || transfer.zero?
|
24
|
+
raise Exception, 'Please add "--from NAME"' if from.nil?
|
25
|
+
raise Exception, 'Please add "--to NAME"' if to.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_to_terminal
|
29
|
+
output = ["Transfer #{money_to_cents(transfer)}"]
|
30
|
+
output << "from #{from}"
|
31
|
+
output << "to #{to}"
|
32
|
+
output << "on #{format_date(on)}" if on
|
33
|
+
ap output.join(' ')
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_transfer(json)
|
37
|
+
xero_api.new_transfer(json)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
class Commands
|
3
|
+
attr_reader :options, :xero
|
4
|
+
|
5
|
+
def initialize(options, xero)
|
6
|
+
@options = options
|
7
|
+
@xero = xero
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform
|
11
|
+
help if options.help
|
12
|
+
set_guid if options.set_guid
|
13
|
+
show_guid if options.show_guid
|
14
|
+
show_accounts if options.show_accounts
|
15
|
+
get_guid if options.get_guid
|
16
|
+
spend if options.spend
|
17
|
+
receive if options.receive
|
18
|
+
transfer if options.transfer
|
19
|
+
balance if options.balance
|
20
|
+
default
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def help
|
26
|
+
puts xero
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_guid
|
31
|
+
XeroCLI::Credentials.set(options.set_guid)
|
32
|
+
ap "Xero GUID set to #{read_guid}"
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_guid
|
37
|
+
ap read_guid
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_guid
|
42
|
+
system('start', XeroCLI::Constants::XERO_CONNECTOR_ADDRESS)
|
43
|
+
system('xdg-open', XeroCLI::Constants::XERO_CONNECTOR_ADDRESS)
|
44
|
+
system('open', XeroCLI::Constants::XERO_CONNECTOR_ADDRESS)
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def show_accounts
|
49
|
+
accounts = XeroCLI::Commands::Accounts.new(options)
|
50
|
+
accounts.perform
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
|
54
|
+
def spend
|
55
|
+
spend = XeroCLI::Commands::Spend.new(options)
|
56
|
+
spend.perform
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def receive
|
61
|
+
receive = XeroCLI::Commands::Receive.new(options)
|
62
|
+
receive.perform
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
|
66
|
+
def transfer
|
67
|
+
transfer = XeroCLI::Commands::Transfer.new(options)
|
68
|
+
transfer.perform
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def balance
|
73
|
+
balance = XeroCLI::Commands::Balance.new(options)
|
74
|
+
balance.perform
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
|
78
|
+
def default
|
79
|
+
puts 'Please use "xero -h" or "xero --help" to check the available commands.'
|
80
|
+
end
|
81
|
+
|
82
|
+
def read_guid
|
83
|
+
@read_guid ||= XeroCLI::Credentials.read_guid
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_account(type)
|
87
|
+
xero_api.accounts(type)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
class Credentials
|
3
|
+
JSON_FILE = 'xero_credentials.json'.freeze
|
4
|
+
|
5
|
+
def self.set(guid)
|
6
|
+
File.open(JSON_FILE, 'w+') do |file|
|
7
|
+
file.write({ 'xero_guid' => guid }.to_json)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.read_guid
|
12
|
+
file = File.read(JSON_FILE)
|
13
|
+
data_hash = JSON.parse(file)
|
14
|
+
data_hash['xero_guid']
|
15
|
+
rescue StandardError
|
16
|
+
'GUID is not set'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
class Options
|
3
|
+
include XeroCLI::Helper
|
4
|
+
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
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|
|
16
|
+
define_method(key) { options[key.to_sym] }
|
17
|
+
end
|
18
|
+
|
19
|
+
def on
|
20
|
+
parse_datetime(options[:on])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
class OptionsParser
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@options = {}
|
7
|
+
@opt = OptionParser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def xero
|
11
|
+
banner
|
12
|
+
separators
|
13
|
+
binds
|
14
|
+
opt
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :opt
|
20
|
+
|
21
|
+
def banner
|
22
|
+
opt.banner = 'Usage: xero [OPTIONS]'
|
23
|
+
end
|
24
|
+
|
25
|
+
def separators
|
26
|
+
opt.separator 'Requires'
|
27
|
+
opt.separator ''
|
28
|
+
opt.separator ' XERO_CONNECTOR_URL must be set in .env // e.g. XERO_CONNECTOR_URL=http://google.com'
|
29
|
+
opt.separator ''
|
30
|
+
opt.separator 'Commands'
|
31
|
+
opt.separator ''
|
32
|
+
opt.separator " xero --set 'YOUR_XERO_GUID' // saves you GUID to json file"
|
33
|
+
opt.separator ' xero --guid // shows current GUID'
|
34
|
+
opt.separator ' xero --get-guid // opens browser where you can get your GUID'
|
35
|
+
opt.separator ' xero --accounts // shows all available accounts'
|
36
|
+
opt.separator " xero --accounts BANK // shows all accounts with type 'BANK'"
|
37
|
+
opt.separator ''
|
38
|
+
opt.separator " xero --receive 45.67 --from 'Contact name' --to 'Bank Account Name' // '--to' is optional, uses Stripe account if not set"
|
39
|
+
opt.separator " xero --spend 45.67 --from 'Bank Account Name' --to 'Contact name' // '--from' is optional, uses Stripe account if not set"
|
40
|
+
opt.separator " --as 'Category Account Name' // sets Category for transaction, uses 'Sales' category if not set"
|
41
|
+
opt.separator " --on 'dd-MM-yyyy' // sets the Date for transaction, uses 'Time.now' if not set"
|
42
|
+
opt.separator ''
|
43
|
+
opt.separator " xero --transfer 1000 --from 'Stripe Merchant Account' --to 'Bank Account Name' // transfers money from one bank to another"
|
44
|
+
opt.separator ''
|
45
|
+
opt.separator 'Options'
|
46
|
+
end
|
47
|
+
|
48
|
+
def binds
|
49
|
+
opt.on('-s', '--set GUID', 'Set GUID') do |set_guid|
|
50
|
+
options[:set_guid] = set_guid
|
51
|
+
end
|
52
|
+
|
53
|
+
opt.on('-g', '--guid', 'Show current GUID') do |show_guid|
|
54
|
+
options[:show_guid] = show_guid
|
55
|
+
end
|
56
|
+
|
57
|
+
opt.on('--get-guid', 'Open browser to get GUID') do |get_guid|
|
58
|
+
options[:get_guid] = get_guid
|
59
|
+
end
|
60
|
+
|
61
|
+
opt.on('-a', '--accounts [TYPE]', 'Show available accounts') do |show_accounts|
|
62
|
+
options[:show_accounts] = 'ALL'
|
63
|
+
options[:show_accounts] = show_accounts if show_accounts
|
64
|
+
end
|
65
|
+
|
66
|
+
opt.on('-h', '--help', 'help') do |help|
|
67
|
+
options[:help] = help
|
68
|
+
end
|
69
|
+
|
70
|
+
opt.on('--spend AMOUNT', 'Amount in dollars (e.g. 456.78)') do |spend|
|
71
|
+
options[:spend] = spend
|
72
|
+
end
|
73
|
+
|
74
|
+
opt.on('--receive AMOUNT', 'Amount in dollars (e.g. 456.78)') do |receive|
|
75
|
+
options[:receive] = receive
|
76
|
+
end
|
77
|
+
|
78
|
+
opt.on('--transfer AMOUNT', 'Amount in dollars (e.g. 456.78)') do |transfer|
|
79
|
+
options[:transfer] = transfer
|
80
|
+
end
|
81
|
+
|
82
|
+
opt.on('--balance BANK_NAME', 'bank name [under construct]') do |balance|
|
83
|
+
options[:balance] = balance
|
84
|
+
end
|
85
|
+
|
86
|
+
opt.on('--on DATE', 'Time in format dd-mm-yyyy') do |on|
|
87
|
+
options[:on] = on
|
88
|
+
end
|
89
|
+
|
90
|
+
opt.on('--as TYPE', 'Category account name') do |as|
|
91
|
+
options[:as] = as
|
92
|
+
end
|
93
|
+
|
94
|
+
opt.on('--from NAME', 'Sender`s name (Bank or Contact)') do |from|
|
95
|
+
options[:from] = from
|
96
|
+
end
|
97
|
+
|
98
|
+
opt.on('--to NAME', 'Receiver`s name (Bank or Contact)') do |to|
|
99
|
+
options[:to] = to
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
module Templates
|
3
|
+
class Transaction
|
4
|
+
def self.attributes(amount, type, user_name, bank_name, category_name, date)
|
5
|
+
{
|
6
|
+
'amount' => amount,
|
7
|
+
'description' => 'Transaction created manually',
|
8
|
+
'customer_name' => user_name,
|
9
|
+
'type' => type,
|
10
|
+
'bank_name' => bank_name || XeroCLI::Constants::STRIPE_BANK_NAME,
|
11
|
+
'category_name' => category_name || XeroCLI::Constants::DEFAULT_CATEGORY_NAME,
|
12
|
+
'date' => date
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module XeroCLI
|
2
|
+
module Templates
|
3
|
+
class Transfer
|
4
|
+
def self.attributes(amount, from_bank_name, to_bank_name, date)
|
5
|
+
xero_date = date ? date.to_time : Time.now
|
6
|
+
{
|
7
|
+
'date' => xero_date.to_i,
|
8
|
+
'amount' => amount,
|
9
|
+
'from_bank_name' => from_bank_name,
|
10
|
+
'to_bank_name' => to_bank_name
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/xero_cli.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'json'
|
5
|
+
require 'date'
|
6
|
+
require 'awesome_print'
|
7
|
+
|
8
|
+
require_relative '../lib/xero_api'
|
9
|
+
require_relative '../lib/xero_cli/constants'
|
10
|
+
require_relative '../lib/xero_cli/helper'
|
11
|
+
require_relative '../lib/xero_cli/options_parser'
|
12
|
+
require_relative '../lib/xero_cli/options'
|
13
|
+
require_relative '../lib/xero_cli/credentials'
|
14
|
+
require_relative '../lib/xero_cli/commands'
|
15
|
+
require_relative '../lib/xero_cli/commands/base'
|
16
|
+
require_relative '../lib/xero_cli/commands/spend'
|
17
|
+
require_relative '../lib/xero_cli/commands/receive'
|
18
|
+
require_relative '../lib/xero_cli/commands/transfer'
|
19
|
+
require_relative '../lib/xero_cli/commands/accounts'
|
20
|
+
require_relative '../lib/xero_cli/commands/balance'
|
21
|
+
require_relative '../lib/xero_cli/templates/transaction'
|
22
|
+
require_relative '../lib/xero_cli/templates/transfer'
|
23
|
+
|
24
|
+
module XeroCLI
|
25
|
+
def self.run
|
26
|
+
options_parser = XeroCLI::OptionsParser.new
|
27
|
+
xero = options_parser.xero
|
28
|
+
xero.parse!
|
29
|
+
|
30
|
+
options = XeroCLI::Options.new(options_parser.options)
|
31
|
+
commands = XeroCLI::Commands.new(options, xero)
|
32
|
+
commands.perform
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
XeroCLI.run
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xero-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xenon Ventures
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.15.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.15.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: It's not time to make a change, just relax, take it easy. You're still
|
84
|
+
young; that's your fault. There's so much you have to know.
|
85
|
+
email:
|
86
|
+
- support@xenon.io
|
87
|
+
executables:
|
88
|
+
- xero
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- README.MD
|
93
|
+
- Rakefile
|
94
|
+
- bin/xero
|
95
|
+
- lib/xero_api.rb
|
96
|
+
- lib/xero_cli.rb
|
97
|
+
- lib/xero_cli/commands.rb
|
98
|
+
- lib/xero_cli/commands/accounts.rb
|
99
|
+
- lib/xero_cli/commands/balance.rb
|
100
|
+
- lib/xero_cli/commands/base.rb
|
101
|
+
- lib/xero_cli/commands/receive.rb
|
102
|
+
- lib/xero_cli/commands/spend.rb
|
103
|
+
- lib/xero_cli/commands/transfer.rb
|
104
|
+
- lib/xero_cli/constants.rb
|
105
|
+
- lib/xero_cli/credentials.rb
|
106
|
+
- lib/xero_cli/helper.rb
|
107
|
+
- lib/xero_cli/options.rb
|
108
|
+
- lib/xero_cli/options_parser.rb
|
109
|
+
- lib/xero_cli/templates/transaction.rb
|
110
|
+
- lib/xero_cli/templates/transfer.rb
|
111
|
+
- lib/xero_cli/version.rb
|
112
|
+
homepage: http://xenon.io
|
113
|
+
licenses:
|
114
|
+
- Copyright Xenon Ventures
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.7.3
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Because real operators take command.
|
136
|
+
test_files: []
|