acts_as_api 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/lib/acts_as_api.rb +6 -1
- data/lib/acts_as_api/rendering.rb +9 -1
- metadata +3 -3
data/History.txt
CHANGED
data/lib/acts_as_api.rb
CHANGED
@@ -16,12 +16,17 @@ require "acts_as_api/array"
|
|
16
16
|
# acts_as_api uses the default serializers of your rails app and doesn't
|
17
17
|
# force you into more dependencies.
|
18
18
|
module ActsAsApi
|
19
|
-
VERSION = '0.0.
|
19
|
+
VERSION = '0.0.2'
|
20
20
|
|
21
21
|
# The accepted response formats
|
22
22
|
# Default is +[:xml, :json]+
|
23
23
|
ACCEPTED_API_FORMATS = [:xml, :json]
|
24
24
|
|
25
|
+
# Holds references to formats that need
|
26
|
+
# to get added an additional root node
|
27
|
+
# with the name of the model.
|
28
|
+
ADD_ROOT_NODE_FOR = [:json]
|
29
|
+
|
25
30
|
end
|
26
31
|
|
27
32
|
# Attach ourselves to active record
|
@@ -29,10 +29,18 @@ module ActsAsApi
|
|
29
29
|
|
30
30
|
# set the name of the root node - pluralize for arrays
|
31
31
|
api_root_name = api_model.is_a?(Array) ? api_model.first.class.name.downcase.pluralize : api_model.class.name.downcase
|
32
|
+
|
32
33
|
output_params[:root] = api_root_name
|
33
34
|
|
35
|
+
api_response = api_model.as_api_response
|
36
|
+
|
37
|
+
if ActsAsApi::ADD_ROOT_NODE_FOR.include? api_format
|
38
|
+
api_response = { api_root_name.to_sym => api_response}
|
39
|
+
end
|
40
|
+
|
41
|
+
|
34
42
|
# create the Hash as response
|
35
|
-
output_params[api_format] =
|
43
|
+
output_params[api_format] = as_api_response
|
36
44
|
|
37
45
|
render output_params
|
38
46
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Christian B\xC3\xA4uerlein"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-01 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|