Class: Moneylovercli::Commands::Wallets

Inherits:
Moneylovercli::Command show all
Defined in:
lib/moneylovercli/commands/wallets.rb

Instance Method Summary collapse

Methods inherited from Moneylovercli::Command

#command, #config, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(options) ⇒ Wallets

Returns a new instance of Wallets.



12
13
14
15
# File 'lib/moneylovercli/commands/wallets.rb', line 12

def initialize(options)
  super
  @options = options
end

Instance Method Details

#execute(_input: $stdin, output: $stdout) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/moneylovercli/commands/wallets.rb', line 17

def execute(_input: $stdin, output: $stdout)
  config = YAML.load_file('config.yml')
  access_token = config['access_token']
  wallets = Moneylovercli::Api::Wallet.new(token: access_token)
    .list
    .parsed_response

  output.puts TTY::Table.new(
    %w[ID Name],
    wallets['data'].map { |data| [data['_id'], data['name']] }
  )
end