Class: Quanto::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/quanto/client.rb,
lib/quanto/entries.rb

Constant Summary collapse

API_VERSION =
"1"
QUANTO_URL =
"http://quanto.herokuapp.com"

Instance Method Summary collapse

Constructor Details

#initialize(consumer_key, consumer_secret, options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/quanto/client.rb', line 10

def initialize(consumer_key, consumer_secret, options = {})
  @consumer =
    OAuth2::Client.new(consumer_key, consumer_secret, site: QUANTO_URL )

  @token = options[:access_token]
end

Instance Method Details

#activate_pluginObject

Activate the current plugin. This should only be done once credentials have been obtained. Returns the url for the current plugin.



24
25
26
27
# File 'lib/quanto/entries.rb', line 24

def activate_plugin
  attributes = post('/activations')
  attributes["url"]
end

#authorized?Boolean

Returns true if the user is authorized to make requests to quanto This means that the application has acquired a valid access token and access token secret.

Returns:

  • (Boolean)


19
20
21
# File 'lib/quanto/client.rb', line 19

def authorized?
  !@token.nil?
end

#connected?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/quanto/client.rb', line 23

def connected?
  !@access_token.nil?
end

#metricsObject



29
30
31
# File 'lib/quanto/entries.rb', line 29

def metrics
  get('/plugin/metrics')
end

#plugin_urlObject

Make a GET request for the URL for the authenticated plugin. Returns the plugin URL as a string.



16
17
18
19
# File 'lib/quanto/entries.rb', line 16

def plugin_url
  attributes = get('/plugin')
  attributes["url"]
end

#record_entry(value, metric_name, opts = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/quanto/entries.rb', line 5

def record_entry(value, metric_name, opts={})
  entry  = {
    metric: metric_name,
    value: value,
    date: opts[:date] || Time.zone.now.to_date.to_s
  }
  post('/entries', entry: entry)
end