rest_resource 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/rest_resource/resource.rb +1 -1
- data/lib/rest_resource/version.rb +1 -1
- data/spec/rest_resource/resource_spec.rb +17 -5
- metadata +3 -3
data/README.md
CHANGED
@@ -10,7 +10,7 @@ The gem provides a basic CRUD operation to the resources. It is basically rest-c
|
|
10
10
|
The goal of this gem is to provide a minimum CRUD client interface for the RESTful web services. It doesn't make the API to be ActiveRecord like. Rather, it lets the users have the full control on the resources, especially on the error handling.
|
11
11
|
|
12
12
|
## USAGE
|
13
|
-
Given you need to fetch user from a web service. You can write:
|
13
|
+
Given that you need to fetch user from a web service. You can write:
|
14
14
|
|
15
15
|
class User < RestResource::Resource
|
16
16
|
class << self
|
@@ -19,7 +19,7 @@ Given you need to fetch user from a web service. You can write:
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def resource_name
|
22
|
-
"
|
22
|
+
"users"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -30,7 +30,7 @@ To use it, you can just do:
|
|
30
30
|
|
31
31
|
user = User.create :name => "Leslie Cheung", :login => "singer"
|
32
32
|
|
33
|
-
Both
|
33
|
+
Both operations assume your web service controller returns a json string which can be initialized into an object.
|
34
34
|
|
35
35
|
##Contributors
|
36
36
|
* Yi Wen
|
@@ -24,7 +24,7 @@ module RestResource
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def initialize(params={})
|
27
|
-
params_hash = ActiveSupport::JSON.decode params
|
27
|
+
params_hash = (params.is_a?(String)) ? ActiveSupport::JSON.decode(params) : params
|
28
28
|
@attributes = params_hash
|
29
29
|
(class << self; self; end).class_eval do
|
30
30
|
params_hash.each_pair do |method_name, value|
|
@@ -44,11 +44,23 @@ module RestResource
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe ".new" do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
context "when the params is a string" do
|
48
|
+
let(:params) { ActiveSupport::JSON.encode( {"attr1" => "val1", "attr2" => "val2"} ) }
|
49
|
+
let(:resource) {klass.new(params)}
|
50
|
+
{"attr1" => "val1", "attr2" => "val2"}.each_pair do |attr, val|
|
51
|
+
it "should generate '#{attr}' method and return '#{val}'" do
|
52
|
+
resource.send(attr).should == val
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the params is a hash" do
|
58
|
+
let(:params) { {"attr1" => "val1", "attr2" => "val2"} }
|
59
|
+
let(:resource) {klass.new(params)}
|
60
|
+
{"attr1" => "val1", "attr2" => "val2"}.each_pair do |attr, val|
|
61
|
+
it "should generate '#{attr}' method and return '#{val}'" do
|
62
|
+
resource.send(attr).should == val
|
63
|
+
end
|
52
64
|
end
|
53
65
|
end
|
54
66
|
|
metadata
CHANGED