sixarm_ruby_action_dispatch_response_json 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3778f1bb04235e11c9354bde441af79d8834307
4
- data.tar.gz: a94d817ee2ecb30354679d7e0450fdd625e20f41
3
+ metadata.gz: bf380b36e269eb228cd8b6afddc517ec607f3302
4
+ data.tar.gz: ec2f7d822c315270756d6025ebeaf128f4f98c73
5
5
  SHA512:
6
- metadata.gz: 60dee97688053bf1d42b286d32bea2f213f6bc92f20b3c6f06f5c0fc5c576fac6e53a40c27d0b283df7e7a7d8030db4833067d9c15cb76eaa1558f296374bd9d
7
- data.tar.gz: 7993720cf93d1f2d1e8e1a81b5765416561cc57910d56d59e4df603dd55a422dce2c5b1b9b899f7da07c6aa9f023a26d568ac022b6905ff4cd1cb3450a0aa939
6
+ metadata.gz: ce83680bd0c5ffcb27d30ff013a3d09e871aaad3058b417bc7d11ff63763ba3b37e6da962b3404f77a0db75c5f1a1c9217ca51950269037dd764fad2ce962afc
7
+ data.tar.gz: 31d494fc2a4d9ac5434c5aa88adcbd6bd9f66a8ab0e777a03133b9e0652d37a8b6858a41ef443a9ce9ae559d602412eb1aa9cdebdc1870a2d491bc8635be3f70
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -11,16 +11,31 @@
11
11
 
12
12
  ## Introduction
13
13
 
14
- Add ActionPack Response#json method.
14
+ This gem extends ActionPack Response with JSON API methods.
15
15
 
16
- So instead of this:
16
+ You can replace this:
17
17
 
18
- JSON.parse(response.body)
18
+ JSON.parse(response.body)
19
19
 
20
- You can write this:
20
+ With this:
21
21
 
22
- JSON.parse(response.json)
22
+ response.json
23
23
 
24
+ You can replace these:
25
+
26
+ response.json["data"]
27
+ response.json["errors"]
28
+ response.json["linked"]
29
+ response.json["links"]
30
+ response.json["meta"]
31
+
32
+ With these:
33
+
34
+ response.data
35
+ response.errors
36
+ response.linked
37
+ response.links
38
+ response.meta
24
39
 
25
40
  For docs go to <http://sixarm.com/sixarm_ruby_action_dispatch_response_json/doc>
26
41
 
@@ -35,7 +50,7 @@ Install:
35
50
 
36
51
  Bundler:
37
52
 
38
- gem "sixarm_ruby_action_dispatch_response_json", ">=1.0.0", "<2"
53
+ gem "sixarm_ruby_action_dispatch_response_json", ">=1.1.0", "<2"
39
54
 
40
55
  Require:
41
56
 
@@ -57,6 +72,7 @@ To install with high security:
57
72
 
58
73
  ## Changes
59
74
 
75
+ * 2015-02-19 1.1.0 Add response methods for top level JSON API
60
76
  * 2015-02-12 1.0.0 Create
61
77
 
62
78
 
@@ -11,12 +11,38 @@ module ActionDispatch
11
11
 
12
12
  # Returns the response body as JSON.
13
13
  def json
14
- JSON.parse(body)
14
+ @json ||= JSON.parse(body)
15
15
  end
16
16
 
17
17
  # Allows you to manually set or override the response body as JSON.
18
18
  def json=(json)
19
19
  self.body=json
20
+ @json = nil
21
+ end
22
+
23
+ # Returns the response json "data" field.
24
+ def data
25
+ json["data"]
26
+ end
27
+
28
+ # Returns the response json "errors" field.
29
+ def errors
30
+ json["errors"]
31
+ end
32
+
33
+ # Returns the response json "linked" field.
34
+ def linked
35
+ json["linked"]
36
+ end
37
+
38
+ # Returns the response json "links" field.
39
+ def links
40
+ json["links"]
41
+ end
42
+
43
+ # Returns the response json "meta" field.
44
+ def meta
45
+ json["meta"]
20
46
  end
21
47
 
22
48
  end
@@ -23,4 +23,43 @@ describe "ActionDispatchResponseJSONTest" do
23
23
  end
24
24
  end
25
25
 
26
+ describe "with typical JSON API structure" do
27
+
28
+ before do
29
+ @resp = ActionDispatch::Response.new
30
+ @resp.body = '{"data":{"a":"b"},"errors":{"c":"d"},"linked":{"e":"f"},"links":{"g":"h"},"meta":{"i":"j"}}'
31
+ end
32
+
33
+ describe "#data" do
34
+ it "gets the data field" do
35
+ @resp.data.must_equal({"a"=>"b"})
36
+ end
37
+ end
38
+
39
+ describe "#errors" do
40
+ it "gets the errors field" do
41
+ @resp.errors.must_equal({"c"=>"d"})
42
+ end
43
+ end
44
+
45
+ describe "#linked" do
46
+ it "gets the linked field" do
47
+ @resp.linked.must_equal({"e"=>"f"})
48
+ end
49
+ end
50
+
51
+ describe "#links" do
52
+ it "gets the links field" do
53
+ @resp.links.must_equal({"g"=>"h"})
54
+ end
55
+ end
56
+
57
+ describe "#meta" do
58
+ it "gets the meta field" do
59
+ @resp.meta.must_equal({"i"=>"j"})
60
+ end
61
+ end
62
+
63
+ end
64
+
26
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sixarm_ruby_action_dispatch_response_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SixArm
@@ -30,7 +30,7 @@ cert_chain:
30
30
  sWRVEyjnjnNuAeLP9zv43IDXjS22L2efhap7IOinYjcecpfXJgQaU+6BFAY4sdkQ
31
31
  S1STYSfs3qySBxxAeEyZTw==
32
32
  -----END CERTIFICATE-----
33
- date: 2015-02-12 00:00:00.000000000 Z
33
+ date: 2015-02-19 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description: Convert response.body to response.json
36
36
  email: sixarm@sixarm.com
metadata.gz.sig CHANGED
Binary file