Class: Usergrid::Client
- Inherits:
-
Object
- Object
- Usergrid::Client
- Defined in:
- lib/usergrid/user.rb,
lib/usergrid/client.rb
Instance Method Summary collapse
- #access_token ⇒ Object
- #base_uri ⇒ Object
- #create_user(params) ⇒ Object
- #get(url) ⇒ Object
- #headers_hash ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(url, params) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/usergrid/client.rb', line 9 def initialize( = {}) @app = [:app] @key = [:key] @secret = [:secret] end |
Instance Method Details
#access_token ⇒ Object
15 16 17 |
# File 'lib/usergrid/client.rb', line 15 def access_token @access_token ||= HTTParty.get("#{base_uri}/token?grant_type=client_credentials&client_id=#{@key}&client_secret=#{@secret}").parsed_response["access_token"] end |
#base_uri ⇒ Object
19 20 21 |
# File 'lib/usergrid/client.rb', line 19 def base_uri "http://api.usergrid.com/#{@app}" end |
#create_user(params) ⇒ Object
8 9 10 |
# File 'lib/usergrid/user.rb', line 8 def create_user params post("/users", params) end |
#get(url) ⇒ Object
23 24 25 |
# File 'lib/usergrid/client.rb', line 23 def get url HTTParty.get("#{base_uri}#{url}", :headers => headers_hash) end |
#headers_hash ⇒ Object
32 33 34 |
# File 'lib/usergrid/client.rb', line 32 def headers_hash {"Authorization" => "Bearer #{access_token}"} end |
#post(url, params) ⇒ Object
27 28 29 30 |
# File 'lib/usergrid/client.rb', line 27 def post url, params = {:body => params.to_json, :headers => {"Content-Type" => "application/json"}} HTTParty.post("#{base_uri}#{url}", ) end |
#users ⇒ Object
4 5 6 |
# File 'lib/usergrid/user.rb', line 4 def users get("/users") end |