Class: Gfspark::App

Inherits:
Object
  • Object
show all
Includes:
Config, Connection, Graph, Term::ANSIColor
Defined in:
lib/gfspark/app.rb

Constant Summary

Constants included from Graph

Graph::BARS, Graph::RANGES

Instance Attribute Summary collapse

Instance Method Summary collapse

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!
  set_ssl_options!
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



7
8
9
# File 'lib/gfspark/app.rb', line 7

def debug
  @debug
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/gfspark/app.rb', line 7

def options
  @options
end

#validObject

Returns the value of attribute valid.



7
8
9
# File 'lib/gfspark/app.rb', line 7

def valid
  @valid
end

Instance Method Details

#executeObject



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