playnicely 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +25 -2
- data/lib/playnicely.rb +9 -1
- data/lib/playnicely/client.rb +6 -5
- data/lib/playnicely/version.rb +1 -1
- data/playnicely.gemspec +1 -1
- data/test/client_test.rb +20 -11
- data/test/helper.rb +2 -1
- metadata +10 -9
data/README.textile
CHANGED
@@ -8,8 +8,6 @@ h2. Installation
|
|
8
8
|
|
9
9
|
Details of how to install the client
|
10
10
|
|
11
|
-
(Once I get around to publishing the gem!)
|
12
|
-
|
13
11
|
@sudo gem install playnicely@
|
14
12
|
|
15
13
|
h2. Getting started
|
@@ -110,6 +108,31 @@ projects_id = client.user_projects(999, "id") # returns an integer
|
|
110
108
|
|
111
109
|
*Important note:* Only projects to which the authenticated user is also a member will be returned. If you require a complete list of all projects for a user, then you must authenticate as that user.
|
112
110
|
|
111
|
+
h3. Errors
|
112
|
+
|
113
|
+
*See the "error reference page":http://docs.playnice.ly/api/errors/ for more information*
|
114
|
+
|
115
|
+
<pre>
|
116
|
+
# now try again but wrap call and check exception content -- stupid shoulda!
|
117
|
+
begin
|
118
|
+
PlayNicely::Client.new('robbiehudson', 'password').project(1)
|
119
|
+
rescue PlayNicely::Error => e
|
120
|
+
puts "Error type: #{e.error_type}"
|
121
|
+
puts "Error message: #{e.error_message}"
|
122
|
+
end
|
123
|
+
</pre>
|
124
|
+
|
125
|
+
Will print the following:
|
126
|
+
|
127
|
+
<pre>
|
128
|
+
Error type: ApiPermissionError
|
129
|
+
Error message: User ID '2' does not have access to project ID '9999'
|
130
|
+
</pre>
|
131
|
+
|
132
|
+
h2. Testing
|
133
|
+
|
134
|
+
To run the tests just type @rake test@
|
135
|
+
|
113
136
|
h2. Contributing
|
114
137
|
|
115
138
|
Please feel free to fork this repository and make any changes you feel are necessary. We will be happy to accept pull requests that we feel will benefit other users of the client.
|
data/lib/playnicely.rb
CHANGED
@@ -15,9 +15,17 @@ module PlayNicely
|
|
15
15
|
def self.client; Client.new end
|
16
16
|
|
17
17
|
def_delegators :client, :project
|
18
|
-
class Error < StandardError
|
18
|
+
class Error < StandardError
|
19
|
+
attr_reader :error_message, :error_type
|
20
|
+
def initialize(type, error_message=nil)
|
21
|
+
@error_type = type
|
22
|
+
@error_message = error_message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class BadRequest < Error; end
|
19
26
|
class Unauthorized < Error; end
|
20
27
|
class NotFound < Error; end
|
28
|
+
class Forbidden < Error; end
|
21
29
|
class ClientError < Error; end
|
22
30
|
class ServerError < Error; end
|
23
31
|
end
|
data/lib/playnicely/client.rb
CHANGED
@@ -98,11 +98,12 @@ module PlayNicely
|
|
98
98
|
|
99
99
|
def self.handle_response(response)
|
100
100
|
case response.code
|
101
|
-
when
|
102
|
-
when
|
103
|
-
when
|
104
|
-
when
|
105
|
-
when 500
|
101
|
+
when 400; raise BadRequest.new Hashie::Mash.new(response)["type"], Hashie::Mash.new(response).error_message
|
102
|
+
when 401; raise Unauthorized.new Hashie::Mash.new(response)["type"], Hashie::Mash.new(response).error_message
|
103
|
+
when 403; raise Forbidden.new Hashie::Mash.new(response)["type"], Hashie::Mash.new(response).error_message
|
104
|
+
when 404; raise NotFound.new Hashie::Mash.new(response)["type"], Hashie::Mash.new(response).error_message
|
105
|
+
when 400...500; raise ClientError.new(Hashie::Mash.new(response)["type"], Hashie::Mash.new(response).error_message)
|
106
|
+
when 500...600; raise ServerError.new(Hashie::Mash.new(response)["type"], Hashie::Mash.new(response).error_message)
|
106
107
|
else; response
|
107
108
|
end
|
108
109
|
end
|
data/lib/playnicely/version.rb
CHANGED
data/playnicely.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.add_runtime_dependency('httparty', '~> 0.6.1')
|
10
10
|
s.add_runtime_dependency('json')
|
11
11
|
s.add_development_dependency('fakeweb', '~> 1.3')
|
12
|
-
s.add_development_dependency('
|
12
|
+
s.add_development_dependency('rspec', '~> 2.4.0')
|
13
13
|
s.add_development_dependency('mocha', '~> 0.9')
|
14
14
|
s.add_development_dependency('shoulda', '~> 2.11')
|
15
15
|
s.name = 'playnicely'
|
data/test/client_test.rb
CHANGED
@@ -9,16 +9,9 @@ class ClientTest < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
should "raise server error" do
|
11
11
|
stub_get("https://robbiehudson:wrong-password@api.playnice.ly/v1/project/1/show/?detail=compact", "server-error.json", ["500", "Unauthorized"])
|
12
|
-
lambda {PlayNicely::Client.new('robbiehudson', 'wrong-password').project(1)}.should raise_error(PlayNicely::ServerError)
|
13
|
-
|
14
|
-
|
15
|
-
begin
|
16
|
-
PlayNicely::Client.new('robbiehudson', 'wrong-password').project(1)
|
17
|
-
rescue PlayNicely::ServerError => e
|
18
|
-
e.message.should == "A description of the problem"
|
19
|
-
else
|
20
|
-
assert_true false
|
21
|
-
end
|
12
|
+
lambda {PlayNicely::Client.new('robbiehudson', 'wrong-password').project(1)}.should raise_error(PlayNicely::ServerError) { |error|
|
13
|
+
error.error_message.should == "A description of the problem"
|
14
|
+
}
|
22
15
|
end
|
23
16
|
|
24
17
|
should "raise client error" do
|
@@ -29,6 +22,22 @@ class ClientTest < Test::Unit::TestCase
|
|
29
22
|
should "raise not found error" do
|
30
23
|
stub_get("https://robbiehudson:wrong-password@api.playnice.ly/v1/project/1/show/?detail=compact", "server-error.json", ["404", "Unauthorized"])
|
31
24
|
lambda {PlayNicely::Client.new('robbiehudson', 'wrong-password').project(1)}.should raise_error(PlayNicely::NotFound)
|
32
|
-
end
|
25
|
+
end
|
26
|
+
|
27
|
+
should "raise forbidden error" do
|
28
|
+
stub_get("https://robbiehudson:wrong-password@api.playnice.ly/v1/project/1/show/?detail=compact", "server-error.json", ["403", "Unauthorized"])
|
29
|
+
lambda {PlayNicely::Client.new('robbiehudson', 'wrong-password').project(1)}.should raise_error(PlayNicely::Forbidden) { |error|
|
30
|
+
error.error_message.should == "A description of the problem"
|
31
|
+
error.error_type.should == "MessageTypeError"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
should "raise bad request error" do
|
36
|
+
stub_get("https://robbiehudson:wrong-password@api.playnice.ly/v1/project/1/show/?detail=compact", "server-error.json", ["400", "Unauthorized"])
|
37
|
+
lambda {PlayNicely::Client.new('robbiehudson', 'wrong-password').project(1)}.should raise_error(PlayNicely::BadRequest) { |error|
|
38
|
+
error.error_message.should == "A description of the problem"
|
39
|
+
error.error_type.should == "MessageTypeError"
|
40
|
+
}
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playnicely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rob Hudson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-23 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -80,18 +80,19 @@ dependencies:
|
|
80
80
|
type: :development
|
81
81
|
version_requirements: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: rspec
|
84
84
|
prerelease: false
|
85
85
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ~>
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
hash:
|
90
|
+
hash: 31
|
91
91
|
segments:
|
92
|
-
-
|
92
|
+
- 2
|
93
93
|
- 4
|
94
|
-
|
94
|
+
- 0
|
95
|
+
version: 2.4.0
|
95
96
|
type: :development
|
96
97
|
version_requirements: *id005
|
97
98
|
- !ruby/object:Gem::Dependency
|
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
197
|
requirements: []
|
197
198
|
|
198
199
|
rubyforge_project:
|
199
|
-
rubygems_version: 1.4.
|
200
|
+
rubygems_version: 1.4.2
|
200
201
|
signing_key:
|
201
202
|
specification_version: 3
|
202
203
|
summary: Wrapper for the PlayNicely API
|