restful_jsonp 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +27 -0
- data/lib/restful_jsonp/jsonp_responder.rb +4 -2
- data/restful_jsonp.gemspec +1 -1
- metadata +3 -3
data/README.markdown
CHANGED
@@ -10,6 +10,16 @@ desired method in a special `_method` parameter.
|
|
10
10
|
For example, to make a `PUT` request to `/users/1.json`, you would make a JSONP (`GET`) request to
|
11
11
|
`/users/1.json?_method=PUT`.
|
12
12
|
|
13
|
+
The plugin also adds a custom Responder for JSONP that automatically adds special behaviour to
|
14
|
+
`respond_with` (via a custom `display` method).
|
15
|
+
|
16
|
+
For JSONP requests handled with `respond_with`:
|
17
|
+
|
18
|
+
1. `:callback => param[:callback]` will be automatically added to the `render` options
|
19
|
+
2. Error `:status` codes (e.g. `:unprocessable_entity`) will be changed to `:accepted`,
|
20
|
+
since error responses cannot be handled by JSONP. To detect errors in JSONP responses
|
21
|
+
check for an `error` attribute in the returned data.
|
22
|
+
|
13
23
|
|
14
24
|
Installation
|
15
25
|
------------
|
@@ -25,6 +35,11 @@ Then add this to your Rails app's `Gemfile`:
|
|
25
35
|
Note that this only works for Rails 3. In principle you could try to swap in the RestfulJSONP::MethodOverride
|
26
36
|
middleware into a Rails 2.3+ app, but this has not been tested.
|
27
37
|
|
38
|
+
To enable the custom JSONP Responder, add this to your `ApplicationController` (or any
|
39
|
+
controller that you want to enable the responder for):
|
40
|
+
|
41
|
+
`self.responder = RestfulJSONP::JSONPResponder`
|
42
|
+
|
28
43
|
|
29
44
|
How it Works
|
30
45
|
------------
|
@@ -36,3 +51,15 @@ or `GET` request.
|
|
36
51
|
|
37
52
|
Note that this functionality is enabled for all requests, regardless of whether they are done
|
38
53
|
via JSONP or otherwise.
|
54
|
+
|
55
|
+
|
56
|
+
History
|
57
|
+
-------
|
58
|
+
|
59
|
+
##### 1.0.2
|
60
|
+
|
61
|
+
* Fixed error response processing in JSONPResponder
|
62
|
+
|
63
|
+
##### 1.0.0
|
64
|
+
|
65
|
+
* Initial release
|
@@ -8,13 +8,15 @@ module RestfulJSONP
|
|
8
8
|
# this is a JSONP request (note that JSONP is not done over XHR!)
|
9
9
|
|
10
10
|
jsonp_options = {}
|
11
|
+
|
12
|
+
status = given_options[:status] || options[:status]
|
11
13
|
|
12
14
|
if (resource.respond_to?(:errors) && !resource.errors.empty?) ||
|
13
|
-
(
|
15
|
+
(status && ![:ok, :created].include?(status))
|
14
16
|
jsonp_options[:status] = :accepted # we can't return an error HTTP response (e.g. 422 or 500) because it would be ignored :(
|
15
17
|
resource = {
|
16
18
|
:error => {
|
17
|
-
:status =>
|
19
|
+
:status => status,
|
18
20
|
:data => resource.to_json
|
19
21
|
}
|
20
22
|
}
|
data/restful_jsonp.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_jsonp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Zukowski
|