roar 0.12.3 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.markdown +8 -0
- data/README.markdown +3 -0
- data/lib/roar/representer/feature/http_verbs.rb +29 -10
- data/lib/roar/representer/json/hal.rb +28 -0
- data/lib/roar/version.rb +1 -1
- data/test/hal_json_test.rb +17 -0
- data/test/http_verbs_test.rb +18 -10
- data/test/test_helper.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d3ecc28432b3f2a039e743ea1503d71379cae06
|
4
|
+
data.tar.gz: dc4f0e29a6c0e62599809b02f700fa97b8971c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 096cf974e914065adc6bb7d098db53b9e4190a73402a3ae06be99a50e0ec7457186112ed5b78368d4c6a8d479c04f5832d86ac745a6907b1ab27fa0716909a81
|
7
|
+
data.tar.gz: e7e465c95e3430976763afd86e5fd2445f128a369eb11337ee456926b7631be92923af84155291359aad102570be14ec73dc2886a101caa0629f8cc09d552a8c
|
data/CHANGES.markdown
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 0.12.5
|
2
|
+
|
3
|
+
|
4
|
+
# 0.12.4
|
5
|
+
|
6
|
+
* The `HAL` module supports [CURIE links](https://github.com/mikekelly/hal_specification/blob/f937dbc9f9e1fa25be824834794407fdcb8f116f/hal_specification.md#curies) now using the `::curie` method.
|
7
|
+
* Allow old and new API in HttpVerbs#get and friends.
|
8
|
+
|
1
9
|
# 0.12.3
|
2
10
|
|
3
11
|
* Allow basic authentication with `basic_auth: [:admin, :password]`.
|
data/README.markdown
CHANGED
@@ -180,6 +180,7 @@ puts album.songs[1] #=> #<Song title="Roadblock">
|
|
180
180
|
|
181
181
|
The nesting of two representers can map composed object as you find them in many many APIs.
|
182
182
|
|
183
|
+
In case you're after virtual nesting, where a nested block in your document still maps to the same outer object, [check out the `::nested` method](https://github.com/apotonick/representable#document-nesting).
|
183
184
|
|
184
185
|
## Inline Representer
|
185
186
|
|
@@ -355,6 +356,8 @@ module SongRepresenter
|
|
355
356
|
end
|
356
357
|
```
|
357
358
|
|
359
|
+
Documentation for HAL can be found in the [API docs](http://rdoc.info/github/apotonick/roar/Roar/Representer/JSON/HAL).
|
360
|
+
|
358
361
|
### Hypermedia
|
359
362
|
|
360
363
|
Including the `Roar::Representer::JSON::HAL` module adds some more DSL methods to your module. It still allows using `::link` but treats them slightly different.
|
@@ -31,33 +31,36 @@ module Roar
|
|
31
31
|
|
32
32
|
# Serializes the object, POSTs it to +url+ with +format+, deserializes the returned document
|
33
33
|
# and updates properties accordingly.
|
34
|
-
def post(
|
35
|
-
|
34
|
+
def post(*args, &block)
|
35
|
+
options = handle_deprecated_args(serialize, *args)
|
36
|
+
response = http.post_uri(options, &block)
|
36
37
|
handle_response(response)
|
37
38
|
end
|
38
39
|
|
39
40
|
# GETs +url+ with +format+, deserializes the returned document and updates properties accordingly.
|
40
|
-
def get(
|
41
|
-
response = http.get_uri(
|
41
|
+
def get(*args, &block)
|
42
|
+
response = http.get_uri(*args, &block)
|
42
43
|
handle_response(response)
|
43
44
|
end
|
44
45
|
|
45
46
|
# Serializes the object, PUTs it to +url+ with +format+, deserializes the returned document
|
46
47
|
# and updates properties accordingly.
|
47
|
-
def put(
|
48
|
-
|
48
|
+
def put(*args, &block)
|
49
|
+
options = handle_deprecated_args(serialize, *args)
|
50
|
+
response = http.put_uri(options, &block)
|
49
51
|
handle_response(response)
|
50
52
|
self
|
51
53
|
end
|
52
54
|
|
53
|
-
def patch(
|
54
|
-
|
55
|
+
def patch(*args, &block)
|
56
|
+
options = handle_deprecated_args(serialize, *args)
|
57
|
+
response = http.patch_uri(options, &block)
|
55
58
|
handle_response(response)
|
56
59
|
self
|
57
60
|
end
|
58
61
|
|
59
|
-
def delete(
|
60
|
-
http.delete_uri(
|
62
|
+
def delete(*args, &block)
|
63
|
+
http.delete_uri(*args, &block)
|
61
64
|
self
|
62
65
|
end
|
63
66
|
|
@@ -70,6 +73,22 @@ module Roar
|
|
70
73
|
def http
|
71
74
|
transport_engine.new
|
72
75
|
end
|
76
|
+
|
77
|
+
def handle_deprecated_args(body, *args) # TODO: remove in 1.0.
|
78
|
+
options = args.first
|
79
|
+
|
80
|
+
if args.size > 1
|
81
|
+
warn %{DEPRECATION WARNING: #get, #post, #put, #delete and #patch no longer accept positional arguments. Please call them as follows:
|
82
|
+
get(uri: "http://localhost/songs", as: "application/json")
|
83
|
+
post(uri: "http://localhost/songs", as: "application/json")
|
84
|
+
Thank you and have a beautiful day.}
|
85
|
+
options = {:uri => args[0], :as => args[1]} if args.size == 2
|
86
|
+
options = {:uri => args[0], :as => args[2]}
|
87
|
+
end
|
88
|
+
|
89
|
+
options[:body] = body
|
90
|
+
options
|
91
|
+
end
|
73
92
|
end
|
74
93
|
end
|
75
94
|
end
|
@@ -9,6 +9,10 @@ module Roar::Representer
|
|
9
9
|
# Embedded resources can be specified when calling #property or +collection using the
|
10
10
|
# :embedded => true option.
|
11
11
|
#
|
12
|
+
# Link arrays can be defined using +::links+.
|
13
|
+
#
|
14
|
+
# CURIEs are specified with the - surprise - +::curie+ class method.
|
15
|
+
#
|
12
16
|
# Example:
|
13
17
|
#
|
14
18
|
# module OrderRepresenter
|
@@ -20,6 +24,18 @@ module Roar::Representer
|
|
20
24
|
# link :self do
|
21
25
|
# "http://orders/#{id}"
|
22
26
|
# end
|
27
|
+
#
|
28
|
+
# links :self do
|
29
|
+
# [{:lang => "en", :href => "http://en.hit"},
|
30
|
+
# {:lang => "de", :href => "http://de.hit"}]
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# curies do
|
34
|
+
# [{:name => :doc,
|
35
|
+
# :href => "//docs/{rel}",
|
36
|
+
# :templated => true}
|
37
|
+
# ]
|
38
|
+
# end
|
23
39
|
# end
|
24
40
|
#
|
25
41
|
# Renders to
|
@@ -184,6 +200,18 @@ module Roar::Representer
|
|
184
200
|
options[:array] = true # FIXME: we need to save this information somewhere.
|
185
201
|
link(options, &block)
|
186
202
|
end
|
203
|
+
|
204
|
+
# Add a CURIEs link section as defined in
|
205
|
+
#
|
206
|
+
# curies do
|
207
|
+
# [{:name => :doc,
|
208
|
+
# :href => "//docs/{rel}",
|
209
|
+
# :templated => true}
|
210
|
+
# ]
|
211
|
+
# end
|
212
|
+
def curies(&block)
|
213
|
+
links(:curies, &block)
|
214
|
+
end
|
187
215
|
end
|
188
216
|
end
|
189
217
|
end
|
data/lib/roar/version.rb
CHANGED
data/test/hal_json_test.rb
CHANGED
@@ -140,4 +140,21 @@ class LinkCollectionTest < MiniTest::Spec
|
|
140
140
|
subject.is_array?("prev").must_equal false
|
141
141
|
end
|
142
142
|
end
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
class HalCurieTest < MiniTest::Spec
|
147
|
+
representer!([Roar::Representer::JSON::HAL]) do
|
148
|
+
link "doc:self" do
|
149
|
+
"/"
|
150
|
+
end
|
151
|
+
|
152
|
+
curies do
|
153
|
+
[{:name => :doc,
|
154
|
+
:href => "//docs/{rel}",
|
155
|
+
:templated => true}]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
it { Object.new.extend(rpr).to_hash.must_equal({"_links"=>{"doc:self"=>{:href=>"/"}, "curies"=>[{:name=>:doc, :href=>"//docs/{rel}", :templated=>true}]}}) }
|
143
160
|
end
|
data/test/http_verbs_test.rb
CHANGED
@@ -38,6 +38,14 @@ class HttpVerbsTest < MiniTest::Spec
|
|
38
38
|
end
|
39
39
|
|
40
40
|
|
41
|
+
describe "deprecations" do
|
42
|
+
it "old #get API still works" do
|
43
|
+
@band.get("http://localhost:4567/bands/slayer", "application/json")
|
44
|
+
assert_equal ["Slayer", "Canadian Maple"], [@band.name, @band.label]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
41
49
|
describe "HttpVerbs.get" do
|
42
50
|
it "returns instance from incoming representation" do
|
43
51
|
band = @band.get("http://localhost:4567/bands/slayer", "application/json")
|
@@ -66,9 +74,8 @@ class HttpVerbsTest < MiniTest::Spec
|
|
66
74
|
|
67
75
|
describe "#get" do
|
68
76
|
it "updates instance with incoming representation" do
|
69
|
-
@band.get("http://localhost:4567/bands/slayer", "application/json")
|
70
|
-
assert_equal "Slayer", @band.name
|
71
|
-
assert_equal "Canadian Maple", @band.label
|
77
|
+
@band.get(:uri => "http://localhost:4567/bands/slayer", :as => "application/json")
|
78
|
+
assert_equal ["Slayer", "Canadian Maple"], [@band.name, @band.label]
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
@@ -77,7 +84,7 @@ class HttpVerbsTest < MiniTest::Spec
|
|
77
84
|
@band.name = "Strung Out"
|
78
85
|
assert_equal nil, @band.label
|
79
86
|
|
80
|
-
@band.post("http://localhost:4567/bands", "application/xml")
|
87
|
+
@band.post(:uri => "http://localhost:4567/bands", :as => "application/xml")
|
81
88
|
assert_equal "STRUNG OUT", @band.name
|
82
89
|
assert_equal nil, @band.label
|
83
90
|
end
|
@@ -87,7 +94,7 @@ class HttpVerbsTest < MiniTest::Spec
|
|
87
94
|
it "updates instance with incoming representation" do
|
88
95
|
@band.name = "Strung Out"
|
89
96
|
@band.label = "Fat Wreck"
|
90
|
-
@band.put("http://localhost:4567/bands/strungout", "application/xml")
|
97
|
+
@band.put(:uri => "http://localhost:4567/bands/strungout", :as => "application/xml")
|
91
98
|
assert_equal "STRUNG OUT", @band.name
|
92
99
|
assert_equal "FAT WRECK", @band.label
|
93
100
|
end
|
@@ -96,17 +103,18 @@ class HttpVerbsTest < MiniTest::Spec
|
|
96
103
|
describe "#patch" do
|
97
104
|
it 'does something' do
|
98
105
|
@band.label = 'Fat Mike'
|
99
|
-
@band.patch("http://localhost:4567/bands/strungout", "application/xml")
|
106
|
+
@band.patch(:uri => "http://localhost:4567/bands/strungout", :as => "application/xml")
|
100
107
|
assert_equal 'FAT MIKE', @band.label
|
101
108
|
end
|
102
109
|
end
|
103
110
|
|
104
111
|
describe "#delete" do
|
105
112
|
it 'does something' do
|
106
|
-
@band.delete("http://localhost:4567/bands/metallica", "application/xml")
|
113
|
+
@band.delete(:uri => "http://localhost:4567/bands/metallica", :as => "application/xml")
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
117
|
+
|
110
118
|
describe "HTTPS and Authentication" do
|
111
119
|
let (:song) { OpenStruct.new(:name => "bodyjar").extend(Roar::Representer::Feature::HttpVerbs, BandRepresenter) }
|
112
120
|
|
@@ -117,7 +125,7 @@ class HttpVerbsTest < MiniTest::Spec
|
|
117
125
|
describe "HTTPS: passing manually" do
|
118
126
|
verbs do |verb|
|
119
127
|
it "allows #{verb}" do
|
120
|
-
song.send(verb, "https://localhost:8443/bands/bodyjar", "application/json")
|
128
|
+
song.send(verb, :uri => "https://localhost:8443/bands/bodyjar", :as => "application/json")
|
121
129
|
|
122
130
|
if verb == "delete"
|
123
131
|
song.name.must_equal "bodyjar"
|
@@ -130,7 +138,7 @@ class HttpVerbsTest < MiniTest::Spec
|
|
130
138
|
|
131
139
|
describe "HTTPS+Basic Auth: passing manually" do
|
132
140
|
it "allows GET" do
|
133
|
-
song.get("https://localhost:8443/protected", "application/json", :basic_auth => [:admin, :password])
|
141
|
+
song.get(:uri => "https://localhost:8443/protected", :as => "application/json", :basic_auth => [:admin, :password])
|
134
142
|
|
135
143
|
song.name.must_equal "Bodyjar"
|
136
144
|
end
|
@@ -139,7 +147,7 @@ class HttpVerbsTest < MiniTest::Spec
|
|
139
147
|
|
140
148
|
describe "request customization" do
|
141
149
|
it "yields the request object" do
|
142
|
-
band.get("http://localhost:4567/cookies", "application/json") do |req|
|
150
|
+
band.get(:uri => "http://localhost:4567/cookies", :as => "application/json") do |req|
|
143
151
|
req.add_field("Cookie", "Yumyum")
|
144
152
|
end.name.must_equal "Bodyjar"
|
145
153
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: representable
|