rest_resource 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -4
- data/lib/rest_resource/resource.rb +4 -0
- data/lib/rest_resource/version.rb +1 -1
- data/spec/rest_resource/resource_spec.rb +7 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -14,17 +14,21 @@ Given you need to fetch user from a web service. You can write:
|
|
14
14
|
|
15
15
|
class User < RestResource::Resource
|
16
16
|
class << self
|
17
|
-
def
|
18
|
-
|
17
|
+
def site
|
18
|
+
"http://www.example.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_name
|
22
|
+
"resources"
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
27
|
To use it, you can just do:
|
24
28
|
|
25
|
-
User.find 1
|
29
|
+
user = User.find 1
|
26
30
|
|
27
|
-
User.create :name => "Leslie Cheung", :login => "singer"
|
31
|
+
user = User.create :name => "Leslie Cheung", :login => "singer"
|
28
32
|
|
29
33
|
Both operation assume your web service controller returns a json string which can be initialized into an object.
|
30
34
|
|
@@ -6,9 +6,14 @@ module RestResource
|
|
6
6
|
let(:create_params) {{"attr1" => "val1"}}
|
7
7
|
let(:klass) {
|
8
8
|
Class.new(Resource) do
|
9
|
-
def self.
|
10
|
-
"http://www.example.com
|
9
|
+
def self.site
|
10
|
+
"http://www.example.com"
|
11
11
|
end
|
12
|
+
|
13
|
+
def self.resource_name
|
14
|
+
"resources"
|
15
|
+
end
|
16
|
+
|
12
17
|
end
|
13
18
|
}
|
14
19
|
|
metadata
CHANGED