usergrid 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/usergrid.rb +38 -5
- data/lib/usergrid/client.rb +0 -36
- data/lib/usergrid/version.rb +1 -1
- metadata +1 -2
- data/lib/usergrid/user.rb +0 -13
data/lib/usergrid.rb
CHANGED
@@ -1,10 +1,43 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
require "
|
3
|
-
require "./lib/usergrid/client"
|
2
|
+
require "usergrid/version"
|
4
3
|
|
5
4
|
module Usergrid
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
def initialize(options = {})
|
8
|
+
@app = options[:app]
|
9
|
+
@key = options[:key]
|
10
|
+
@secret = options[:secret]
|
11
|
+
end
|
12
|
+
|
13
|
+
def users
|
14
|
+
get("/users")
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_user params
|
18
|
+
post("/users", params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def access_token
|
22
|
+
@access_token ||= self.class.get("#{base_uri}/token?grant_type=client_credentials&client_id=#{@key}&client_secret=#{@secret}").parsed_response["access_token"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def base_uri
|
26
|
+
"http://api.usergrid.com/#{@app}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def get url
|
30
|
+
self.class.get("#{base_uri}#{url}", :headers => headers_hash)
|
31
|
+
end
|
32
|
+
|
33
|
+
def post url, params
|
34
|
+
options = {:body => params.to_json, :headers => {"Content-Type" => "application/json"}}
|
35
|
+
self.class.post("#{base_uri}#{url}", options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def headers_hash
|
39
|
+
{"Authorization" => "Bearer #{access_token}"}
|
40
|
+
end
|
9
41
|
end
|
42
|
+
|
10
43
|
end
|
data/lib/usergrid/client.rb
CHANGED
@@ -1,36 +0,0 @@
|
|
1
|
-
require './lib/usergrid/user'
|
2
|
-
|
3
|
-
module Usergrid
|
4
|
-
|
5
|
-
|
6
|
-
include HTTParty
|
7
|
-
|
8
|
-
class Client
|
9
|
-
def initialize(options = {})
|
10
|
-
@app = options[:app]
|
11
|
-
@key = options[:key]
|
12
|
-
@secret = options[:secret]
|
13
|
-
end
|
14
|
-
|
15
|
-
def access_token
|
16
|
-
@access_token ||= HTTParty.get("#{base_uri}/token?grant_type=client_credentials&client_id=#{@key}&client_secret=#{@secret}").parsed_response["access_token"]
|
17
|
-
end
|
18
|
-
|
19
|
-
def base_uri
|
20
|
-
"http://api.usergrid.com/#{@app}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def get url
|
24
|
-
HTTParty.get("#{base_uri}#{url}", :headers => headers_hash)
|
25
|
-
end
|
26
|
-
|
27
|
-
def post url, params
|
28
|
-
options = {:body => params.to_json, :headers => {"Content-Type" => "application/json"}}
|
29
|
-
HTTParty.post("#{base_uri}#{url}", options)
|
30
|
-
end
|
31
|
-
|
32
|
-
def headers_hash
|
33
|
-
{"Authorization" => "Bearer #{access_token}"}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/usergrid/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usergrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,7 +25,6 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- lib/usergrid.rb
|
27
27
|
- lib/usergrid/client.rb
|
28
|
-
- lib/usergrid/user.rb
|
29
28
|
- lib/usergrid/version.rb
|
30
29
|
- usergrid.gemspec
|
31
30
|
homepage: ''
|