Class: Gfspark::App
- Inherits:
-
Object
- Object
- Gfspark::App
- Includes:
- Config, Connection, Graph, Term::ANSIColor
- Defined in:
- lib/gfspark/app.rb
Constant Summary
Constants included from Graph
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#options ⇒ Object
Returns the value of attribute options.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #execute ⇒ Object
- #fetch(api) ⇒ Object
-
#initialize(args) ⇒ App
constructor
A new instance of App.
Methods included from Graph
#bar, #period_title, #range_arg?, #render
Methods included from Connection
#connection, #fetch_json, #response_success?, #send_request
Methods included from Config
#detect_width_and_height!, #help, #load_default_settings, #load_default_settings_from_home, #load_default_settings_with_traversing_to_root, #opt_parser, #parse_options, #set_ssl_options!, #try_default, #try_path, #try_url
Constructor Details
#initialize(args) ⇒ App
Returns a new instance of App.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gfspark/app.rb', line 9 def initialize(args) @opt_parse_obj = opt_parser if args.nil? || args.empty? @valid = false return end @options = load_default_settings try_url(args) || try_path(args) || try_default(args) unless @url && @service && @section && @graph puts "Invalid Arguments" @valid = false return end detect_width_and_height! end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
7 8 9 |
# File 'lib/gfspark/app.rb', line 7 def debug @debug end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/gfspark/app.rb', line 7 def @options end |
#valid ⇒ Object
Returns the value of attribute valid.
7 8 9 |
# File 'lib/gfspark/app.rb', line 7 def valid @valid end |
Instance Method Details
#execute ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/gfspark/app.rb', line 30 def execute json = fetch(:xport) summary = fetch(:summary) render(json, summary) true end |
#fetch(api) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gfspark/app.rb', line 38 def fetch(api) url = "#{@url}/#{api.to_s}/#{@service}/#{@section}/#{@graph}" queries = {} queries[:t] = @options[:t] || "d" queries[:width] = @width queries[:from] = @options[:from] if @options[:from].nil? queries[:to] = @options[:to] if @options[:to].nil? json = fetch_json(url, {}, queries) end |