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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 7637c960ba23b86ca3e889c91c057f0a31939c45293efca3a1682edfec9566d5
4
- data.tar.gz: 7d95c1c8fd3ee6c81a12450e34e5617922e4601825646501b669561c5e191bac
2
+ SHA1:
3
+ metadata.gz: 3fa43c4c67c9638663ea8ae28f0719ab66f7895b
4
+ data.tar.gz: 5df056a65e8371f199a95335fb78e139d0b4c51f
5
5
  SHA512:
6
- metadata.gz: 4b83e6dd789eb09151576ac12f1d4641b2cb5fe6b06347ef592761d7b30a5c4dbf42e2fdad47ebca5a52f37eaac61ac1ecd41fd578de9f66a1059ec903ddf545
7
- data.tar.gz: e0b14545466efa035f8dad30cdc0d8af68ab41e050682ba906e4a3c62003e258e1cf31b68cf7299167d9e080bdf05312283295912f162e412257a4da13495942
6
+ metadata.gz: 333361104b7aced7143ddd72e161ebb1ecd24fe9439d60d014b0dc621cf4d3f5d9eae7a2a41e54793e6fdab8cd662f78913b61297c9cde8b9c13839316eb2482
7
+ data.tar.gz: 33ba21c0e134bc0b5aa43268091efacd24a7936aace642189d7080ae991db443d902b1ae48248d67755946fe8369377324513911db6460172d21d963d3ac8c6e
@@ -15,12 +15,12 @@ class XeroAPI
15
15
  []
16
16
  end
17
17
 
18
- def new_transaction(transaction_data, category_code)
19
- post('/transactions/new', data: transaction_data, category_code: category_code)
18
+ def new_transaction(transaction_data)
19
+ post('/transactions/new', data: transaction_data)
20
20
  end
21
21
 
22
- def new_invoice(invoice_data, category_code)
23
- post('/invoices/new', data: invoice_data, category_code: category_code)
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
- post('/balance', data: { bank_name: bank_name }).body
31
+ get('/balance', { bank_name: bank_name }).body
32
32
  end
33
33
 
34
34
  private
@@ -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
@@ -5,6 +5,7 @@ class XeroCLI::Commands::Accounts < XeroCLI::Commands::Base
5
5
 
6
6
  def perform
7
7
  accounts = get_account(show_accounts == 'ALL' ? nil : show_accounts)
8
+ XeroCLI::AccountsStorage.set(accounts.map(&:to_h))
8
9
  ap accounts
9
10
  end
10
11
 
@@ -14,6 +14,6 @@ class XeroCLI::Commands::Base
14
14
  end
15
15
 
16
16
  def format_date(on)
17
- on.strftime('%d-%m-%Y')
17
+ Time.at(on).strftime('%d-%m-%Y')
18
18
  end
19
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
- transaction_attributes = XeroCLI::Templates::Transaction.attributes(receive, TRANSACTION_TYPE, from, to, as, on)
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 #{money_to_cents(receive)}"]
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, nil)
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
- transaction_attributes = XeroCLI::Templates::Transaction.attributes(spend, TRANSACTION_TYPE, to, from, as, on)
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 #{money_to_cents(spend)}"]
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, nil)
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 #{money_to_cents(transfer)}"]
29
+ output = ["Transfer #{transfer}"]
30
30
  output << "from #{from}"
31
31
  output << "to #{to}"
32
32
  output << "on #{format_date(on)}" if on
@@ -2,6 +2,6 @@ module XeroCLI
2
2
  class Constants
3
3
  XERO_CONNECTOR_ADDRESS = 'http://xero.accountdock.com/partner/tokens/new'.freeze
4
4
  STRIPE_BANK_NAME = 'Stripe Merchant Account'.freeze
5
- DEFAULT_CATEGORY_NAME = 'Sales'.freeze
5
+ DEFAULT_CATEGORY_CODE = 200
6
6
  end
7
7
  end
@@ -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
@@ -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, category_name, date)
4
+ def self.attributes(amount, type, user_name, bank_name, account_code, date)
5
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
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
- 'date' => xero_date.to_i,
8
- 'amount' => amount,
9
- 'from_bank_name' => from_bank_name,
10
- 'to_bank_name' => to_bank_name
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
@@ -1,3 +1,3 @@
1
1
  module XeroCLI
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
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.2
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-02-08 00:00:00.000000000 Z
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.7.3
119
+ rubygems_version: 2.6.12
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: Because real operators take command.