sheep 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sheep.rb +2 -4
- data/lib/sheep/error.rb +6 -5
- data/lib/sheep/user.rb +8 -10
- data/lib/sheep/version.rb +1 -1
- data/sheep.gemspec +1 -1
- metadata +2 -2
data/lib/sheep.rb
CHANGED
@@ -14,10 +14,8 @@ module Sheep
|
|
14
14
|
|
15
15
|
def connection
|
16
16
|
@connection ||= Apis::Connection.new(:uri => 'http://api-tuppy-com.heroku.com/') do
|
17
|
-
|
18
|
-
|
19
|
-
use Sheep::ErrorResponse
|
20
|
-
end
|
17
|
+
use Sheep::ErrorResponse
|
18
|
+
use Apis::Middleware::Response::Json
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
data/lib/sheep/error.rb
CHANGED
@@ -10,17 +10,18 @@ module Sheep
|
|
10
10
|
@app = app
|
11
11
|
end
|
12
12
|
|
13
|
-
def call(
|
14
|
-
|
13
|
+
def call(env)
|
14
|
+
status, headers, body = @app.call(env)
|
15
|
+
case status
|
15
16
|
when 200, 201, 301, 302
|
16
|
-
@app.call(response) if @app
|
17
17
|
when 400
|
18
|
-
raise Sheep::BadRequest.new(
|
18
|
+
raise Sheep::BadRequest.new(body['error'] || body['errors'])
|
19
19
|
when 404
|
20
20
|
raise Sheep::NotFound
|
21
21
|
else
|
22
|
-
raise Sheep::UnknownError.new(
|
22
|
+
raise Sheep::UnknownError.new(body)
|
23
23
|
end
|
24
|
+
return status, headers, body
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
data/lib/sheep/user.rb
CHANGED
@@ -2,22 +2,22 @@ module Sheep
|
|
2
2
|
class User
|
3
3
|
class << self
|
4
4
|
def find(id)
|
5
|
-
new(Sheep.connection.get("/v1/users/#{id}")
|
5
|
+
new(Sheep.connection.get("/v1/users/#{id}")[2]['user'])
|
6
6
|
end
|
7
7
|
|
8
8
|
def create(attributes)
|
9
|
-
|
9
|
+
status, headers, body = Sheep.connection.post('/v1/users') do |request|
|
10
10
|
request.params = { :user => attributes }
|
11
11
|
request.params['client_id'] = Sheep.client_id
|
12
12
|
request.params['client_secret'] = Sheep.client_secret
|
13
13
|
end
|
14
14
|
# TODO: refactor this to use Authorized when it will be finished
|
15
|
-
Sheep.access_token =
|
16
|
-
new(Sheep.connection.get(
|
15
|
+
Sheep.access_token = body['access_token']
|
16
|
+
new(Sheep.connection.get(headers['Location'])[2]['user'])
|
17
17
|
end
|
18
18
|
|
19
19
|
def authorize!(username, password)
|
20
|
-
|
20
|
+
status, headers, body = Sheep.connection.post('/v1/oauth/access_token') do |request|
|
21
21
|
request.params['username'] = username
|
22
22
|
request.params['password'] = password
|
23
23
|
request.params['client_id'] = Sheep.client_id
|
@@ -25,15 +25,13 @@ module Sheep
|
|
25
25
|
request.params['grant_type'] = 'password'
|
26
26
|
end
|
27
27
|
# TODO: access_token should be in user object, not global
|
28
|
-
Sheep.access_token =
|
28
|
+
Sheep.access_token = body['access_token']
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def activities
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
response.body.map do |activity|
|
33
|
+
status, headers, body = Sheep.connection.get('/v1/activities', {}, {'Authorization' => "Bearer #{Sheep.access_token}"})
|
34
|
+
body.map do |activity|
|
37
35
|
Sheep::Activity.new(activity['activity'])
|
38
36
|
end
|
39
37
|
end
|
data/lib/sheep/version.rb
CHANGED
data/sheep.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency 'rspec', '>= 2.5'
|
23
23
|
s.add_development_dependency 'rack-test'
|
24
24
|
s.add_development_dependency 'sinatra'
|
25
|
-
s.add_dependency 'apis', '>= 0.
|
25
|
+
s.add_dependency 'apis', '>= 0.5.1.pre1'
|
26
26
|
s.add_dependency 'multi_json'
|
27
27
|
s.add_dependency 'yajl-ruby'
|
28
28
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sheep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Marjan Krekoten' (\xD0\x9C\xD0\xB0\xD1\x80'\xD1\x8F\xD0\xBD \xD0\x9A\xD1\x80\xD0\xB5\xD0\xBA\xD0\xBE\xD1\x82\xD0\xB5\xD0\xBD\xD1\x8C)"
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 0.5.1.pre1
|
57
57
|
type: :runtime
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|