Class: Fredric::CommandLine
- Inherits:
-
SuperDocopt::Base
- Object
- SuperDocopt::Base
- Fredric::CommandLine
- Defined in:
- lib/fredric/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
- #fredric ⇒ Object
- #get ⇒ Object
- #pretty ⇒ Object
- #save ⇒ Object
- #see ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
13 14 15 |
# File 'lib/fredric/command_line.rb', line 13 def csv @csv end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/fredric/command_line.rb', line 13 def file @file end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
13 14 15 |
# File 'lib/fredric/command_line.rb', line 13 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/fredric/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/fredric/command_line.rb', line 15 def before_execute @path = args['PATH'] @params = translate_params args['PARAMS'] @file = args['FILE'] @csv = args['--csv'] unless api_key raise Fredric::MissingAuth, "Missing Authentication\nPlease set FRED_KEY=y0urAP1k3y" end end |
#fredric ⇒ Object
57 58 59 |
# File 'lib/fredric/command_line.rb', line 57 def fredric @fredric ||= fredric! end |
#get ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/fredric/command_line.rb', line 26 def get if csv puts fredric.get_csv path, params else payload = fredric.get! path, params puts payload.response.body end end |
#pretty ⇒ Object
44 45 46 47 |
# File 'lib/fredric/command_line.rb', line 44 def pretty payload = fredric.get path, params puts JSON.pretty_generate payload end |
#save ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/fredric/command_line.rb', line 35 def save if csv success = fredric.save_csv file, path, params else success = fredric.save file, path, params end puts success ? "Saved #{file}" : "Saving failed" end |
#see ⇒ Object
49 50 51 |
# File 'lib/fredric/command_line.rb', line 49 def see lp fredric.get path, params end |
#url ⇒ Object
53 54 55 |
# File 'lib/fredric/command_line.rb', line 53 def url puts fredric.url path, params end |