Class: Usergrid::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/usergrid/user.rb,
lib/usergrid/client.rb

Instance Method Summary collapse

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(options = {})
  @app = options[:app]
  @key = options[:key]
  @secret = options[:secret]
end

Instance Method Details

#access_tokenObject



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_uriObject



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_hashObject



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
  options = {:body => params.to_json, :headers => {"Content-Type" => "application/json"}}
  HTTParty.post("#{base_uri}#{url}", options)
end

#usersObject



4
5
6
# File 'lib/usergrid/user.rb', line 4

def users
  get("/users")
end