Class: Simperuby
- Inherits:
-
Object
- Object
- Simperuby
- Defined in:
- lib/simperuby.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #authorize(user, pass) ⇒ Object
- #create(user, pass) ⇒ Object
-
#initialize(params = {}) ⇒ Simperuby
constructor
A new instance of Simperuby.
Constructor Details
#initialize(params = {}) ⇒ Simperuby
Returns a new instance of Simperuby.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/simperuby.rb', line 7 def initialize(params={}) if params[:app_id] @app_id = params[:app_id] else raise 'You need to provide an :app_id' end if params[:api_key] @api_key = params[:api_key] else raise 'You need to provide an :api_key' end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/simperuby.rb', line 5 def access_token @access_token end |
Instance Method Details
#[](name) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/simperuby.rb', line 32 def [](name) if @access_token Bucket.new @app_id, @access_token, name else raise "You need to authorize client first, try authorize(user,pass)" end end |
#authorize(user, pass) ⇒ Object
26 27 28 29 30 |
# File 'lib/simperuby.rb', line 26 def (user,pass) res = JSON.parse RestClient.post "https://auth.simperium.com/1/#{@app_id}/authorize/", { 'username' => user, 'password' => pass }.to_json, { 'X-Simperium-API-Key' => @api_key } @access_token = res['access_token'] res end |
#create(user, pass) ⇒ Object
20 21 22 23 24 |
# File 'lib/simperuby.rb', line 20 def create(user,pass) res = JSON.parse RestClient.post "https://auth.simperium.com/1/#{@app_id}/create/", { 'username' => user, 'password' => pass }.to_json, { 'X-Simperium-API-Key' => @api_key } @access_token = res['access_token'] res end |