Class: Quanto::Client
- Inherits:
-
Object
- Object
- Quanto::Client
- 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
-
#activate_plugin ⇒ Object
Activate the current plugin.
-
#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.
- #connected? ⇒ Boolean
-
#initialize(consumer_key, consumer_secret, options = {}) ⇒ Client
constructor
A new instance of Client.
- #metrics ⇒ Object
-
#plugin_url ⇒ Object
Make a GET request for the URL for the authenticated plugin.
- #record_entry(value, metric_name, opts = {}) ⇒ Object
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, = {}) @consumer = OAuth2::Client.new(consumer_key, consumer_secret, site: QUANTO_URL ) @token = [:access_token] end |
Instance Method Details
#activate_plugin ⇒ Object
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.
19 20 21 |
# File 'lib/quanto/client.rb', line 19 def !@token.nil? end |
#connected? ⇒ Boolean
23 24 25 |
# File 'lib/quanto/client.rb', line 23 def connected? !@access_token.nil? end |
#metrics ⇒ Object
29 30 31 |
# File 'lib/quanto/entries.rb', line 29 def metrics get('/plugin/metrics') end |
#plugin_url ⇒ Object
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 |