Class: Wavefront::Client
- Inherits:
-
Object
- Object
- Wavefront::Client
- Defined in:
- lib/wavefront/client.rb,
lib/wavefront/client/version.rb
Constant Summary collapse
- DEFAULT_PERIOD_SECONDS =
600- DEFAULT_PATH =
'/chart/api'- DEFAULT_FORMAT =
:raw- FORMATS =
[ :raw, :ruby, :graphite, :highcharts ]
- GRANULARITIES =
%w( s m h d )- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(token, host = DEFAULT_HOST, debug = false) ⇒ Client
constructor
A new instance of Client.
- #query(query, granularity = 'm', options = {}) ⇒ Object
Constructor Details
#initialize(token, host = DEFAULT_HOST, debug = false) ⇒ Client
Returns a new instance of Client.
35 36 37 38 39 |
# File 'lib/wavefront/client.rb', line 35 def initialize(token, host=DEFAULT_HOST, debug=false) @headers = {'X-AUTH-TOKEN' => token} @base_uri = URI::HTTPS.build(:host => host, :path => DEFAULT_PATH) debug(debug) end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
33 34 35 |
# File 'lib/wavefront/client.rb', line 33 def base_uri @base_uri end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
33 34 35 |
# File 'lib/wavefront/client.rb', line 33 def headers @headers end |
Instance Method Details
#query(query, granularity = 'm', options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wavefront/client.rb', line 41 def query(query, granularity='m', ={}) [:end_time] ||= Time.now [:start_time] ||= [:end_time] - DEFAULT_PERIOD_SECONDS [:response_format] ||= DEFAULT_FORMAT [:prefix_length] ||= 1 [ [:start_time], [:end_time] ].each { |o| raise Wavefront::Exception::InvalidTimeFormat unless o.is_a?(Time) } raise Wavefront::Exception::InvalidGranularity unless GRANULARITIES.include?(granularity) raise Wavefront::Exception::InvalidResponseFormat unless FORMATS.include?([:response_format]) raise InvalidPrefixLength unless [:prefix_length].is_a?(Fixnum) args = {:params => {:q => query, :g => granularity, :n => 'Unknown', :s => [:start_time].to_i, :e => [:end_time].to_i}}.merge(@headers) response = RestClient.get @base_uri.to_s, args klass = Object.const_get('Wavefront').const_get('Response').const_get([:response_format].to_s.capitalize) return klass.new(response, ) end |