Class: Intrinio::CommandLine
- Inherits:
-
SuperDocopt::Base
- Object
- SuperDocopt::Base
- Intrinio::CommandLine
- Defined in:
- lib/intrinio/command_line.rb
Overview
Handles the command line interface
Instance Attribute Summary collapse
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #before_execute ⇒ Object
- #get ⇒ Object
- #intrinio ⇒ Object
- #pretty ⇒ Object
- #save ⇒ Object
- #see ⇒ Object
-
#translate_params(pairs) ⇒ Object
Convert a params array like [key:value, key:value] to a hash like value, key: value.
- #url ⇒ Object
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
13 14 15 |
# File 'lib/intrinio/command_line.rb', line 13 def csv @csv end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/intrinio/command_line.rb', line 13 def file @file end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
13 14 15 |
# File 'lib/intrinio/command_line.rb', line 13 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/intrinio/command_line.rb', line 13 def path @path end |
Instance Method Details
#before_execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/intrinio/command_line.rb', line 15 def before_execute @path = args['PATH'] @params = translate_params args['PARAMS'] @file = args['FILE'] @csv = args['--csv'] if intrinio_auth.empty? raise Intrinio::MissingAuth, "Missing Authentication\nPlease set INTRINIO_AUTH=username:password" end end |
#get ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/intrinio/command_line.rb', line 26 def get if csv puts intrinio.get_csv path, params else payload = intrinio.get! path, params puts payload.response.body end end |
#intrinio ⇒ Object
69 70 71 |
# File 'lib/intrinio/command_line.rb', line 69 def intrinio @intrinio ||= intrinio! end |
#pretty ⇒ Object
44 45 46 47 |
# File 'lib/intrinio/command_line.rb', line 44 def pretty payload = intrinio.get path, params puts JSON.pretty_generate payload end |
#save ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/intrinio/command_line.rb', line 35 def save if csv success = intrinio.save_csv file, path, params else success = intrinio.save file, path, params end puts success ? "Saved #{file}" : "Saving failed" end |
#see ⇒ Object
49 50 51 |
# File 'lib/intrinio/command_line.rb', line 49 def see ap intrinio.get path, params end |
#translate_params(pairs) ⇒ Object
Convert a params array like [key:value, key:value] to a hash like value, key: value
59 60 61 62 63 64 65 66 67 |
# File 'lib/intrinio/command_line.rb', line 59 def translate_params(pairs) result = {} return result if pairs.empty? pairs.each do |pair| key, value = pair.split ':' result[key.to_sym] = value end result end |
#url ⇒ Object
53 54 55 |
# File 'lib/intrinio/command_line.rb', line 53 def url puts intrinio.url path, params end |