Class: Nasdaq::CommandLine

Inherits:
SuperDocopt::Base
  • Object
show all
Defined in:
lib/nasdaq/command_line.rb

Overview

Handles the command line interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#csvObject (readonly)

Returns the value of attribute csv.



12
13
14
# File 'lib/nasdaq/command_line.rb', line 12

def csv
  @csv
end

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/nasdaq/command_line.rb', line 12

def file
  @file
end

#paramsObject (readonly)

Returns the value of attribute params.



12
13
14
# File 'lib/nasdaq/command_line.rb', line 12

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/nasdaq/command_line.rb', line 12

def path
  @path
end

Instance Method Details

#before_executeObject



14
15
16
17
18
19
# File 'lib/nasdaq/command_line.rb', line 14

def before_execute
  @path   = args['PATH']
  @params = translate_params args['PARAMS']
  @file   = args['FILE']
  @csv    = args['--csv']
end

#getObject



21
22
23
24
25
26
27
28
# File 'lib/nasdaq/command_line.rb', line 21

def get
  if csv
    puts nasdaq.get_csv path, params
  else
    payload = nasdaq.get! path, params
    puts payload.response.body
  end
end

#nasdaqObject



52
53
54
# File 'lib/nasdaq/command_line.rb', line 52

def nasdaq
  @nasdaq ||= nasdaq!
end

#prettyObject



39
40
41
42
# File 'lib/nasdaq/command_line.rb', line 39

def pretty
  payload = nasdaq.get path, params
  puts JSON.pretty_generate payload
end

#saveObject



30
31
32
33
34
35
36
37
# File 'lib/nasdaq/command_line.rb', line 30

def save
  success = if csv
    nasdaq.save_csv file, path, params
  else
    nasdaq.save file, path, params
  end
  puts success ? "Saved #{file}" : 'Saving failed'
end

#seeObject



44
45
46
# File 'lib/nasdaq/command_line.rb', line 44

def see
  lp nasdaq.get path, params
end

#urlObject



48
49
50
# File 'lib/nasdaq/command_line.rb', line 48

def url
  puts nasdaq.url path, params
end