restfulie 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -5
- data/Rakefile +5 -2
- data/lib/restfulie.rb +10 -5
- data/lib/restfulie/client.rb +13 -9
- data/lib/restfulie/client/base.rb +24 -65
- data/lib/restfulie/client/configuration.rb +62 -64
- data/lib/restfulie/client/entry_point.rb +36 -0
- data/lib/restfulie/client/ext/atom_ext.rb +12 -0
- data/lib/restfulie/client/ext/http_ext.rb +22 -0
- data/lib/restfulie/client/ext/json_ext.rb +12 -0
- data/lib/restfulie/client/ext/xml_ext.rb +4 -0
- data/lib/restfulie/client/http.rb +25 -13
- data/lib/restfulie/client/http/cache.rb +22 -22
- data/lib/restfulie/client/http/error.rb +70 -70
- data/lib/restfulie/client/http/link_request_builder.rb +15 -0
- data/lib/restfulie/client/http/request_adapter.rb +209 -0
- data/lib/restfulie/client/http/request_builder.rb +107 -0
- data/lib/restfulie/client/http/request_builder_executor.rb +24 -0
- data/lib/restfulie/client/http/request_executor.rb +17 -0
- data/lib/restfulie/client/http/request_follow.rb +42 -0
- data/lib/restfulie/client/http/request_follow_executor.rb +10 -0
- data/lib/restfulie/client/http/request_history.rb +69 -0
- data/lib/restfulie/client/http/request_history_executor.rb +10 -0
- data/lib/restfulie/client/http/request_marshaller.rb +127 -0
- data/lib/restfulie/client/http/request_marshaller_executor.rb +10 -0
- data/lib/restfulie/client/http/response.rb +23 -0
- data/lib/restfulie/client/http/response_handler.rb +67 -0
- data/lib/restfulie/client/http/response_holder.rb +9 -0
- data/lib/restfulie/client/mikyung.rb +17 -14
- data/lib/restfulie/client/mikyung/concatenator.rb +15 -12
- data/lib/restfulie/client/mikyung/core.rb +65 -39
- data/lib/restfulie/client/mikyung/languages.rb +8 -26
- data/lib/restfulie/client/mikyung/languages/german.rb +24 -0
- data/lib/restfulie/client/mikyung/languages/portuguese.rb +23 -0
- data/lib/restfulie/client/mikyung/rest_process_model.rb +184 -107
- data/lib/restfulie/client/mikyung/steady_state_walker.rb +34 -28
- data/lib/restfulie/client/mikyung/then_condition.rb +33 -27
- data/lib/restfulie/client/mikyung/when_condition.rb +53 -49
- data/lib/restfulie/common.rb +7 -12
- data/lib/restfulie/common/converter.rb +20 -9
- data/lib/restfulie/common/converter/atom.rb +8 -83
- data/lib/restfulie/common/converter/atom/base.rb +89 -0
- data/lib/restfulie/common/converter/atom/builder.rb +101 -99
- data/lib/restfulie/common/converter/atom/helpers.rb +16 -8
- data/lib/restfulie/common/converter/json.rb +12 -0
- data/lib/restfulie/common/converter/json/base.rb +84 -0
- data/lib/restfulie/common/converter/json/builder.rb +102 -0
- data/lib/restfulie/common/converter/json/helpers.rb +17 -0
- data/lib/restfulie/common/converter/values.rb +30 -26
- data/lib/restfulie/common/converter/xml.rb +14 -0
- data/lib/restfulie/common/converter/xml/base.rb +61 -0
- data/lib/restfulie/common/converter/xml/builder.rb +112 -0
- data/lib/restfulie/common/converter/xml/helpers.rb +17 -0
- data/lib/restfulie/common/converter/xml/link.rb +25 -0
- data/lib/restfulie/common/converter/xml/links.rb +25 -0
- data/lib/restfulie/common/core_ext.rb +1 -5
- data/lib/restfulie/common/core_ext/hash.rb +12 -0
- data/lib/restfulie/common/error.rb +19 -0
- data/lib/restfulie/common/logger.rb +17 -9
- data/lib/restfulie/common/representation.rb +9 -10
- data/lib/restfulie/common/representation/atom.rb +15 -47
- data/lib/restfulie/common/representation/atom/base.rb +122 -365
- data/lib/restfulie/common/representation/atom/category.rb +41 -0
- data/lib/restfulie/common/representation/atom/entry.rb +52 -100
- data/lib/restfulie/common/representation/atom/factory.rb +43 -0
- data/lib/restfulie/common/representation/atom/feed.rb +103 -99
- data/lib/restfulie/common/representation/atom/link.rb +68 -0
- data/lib/restfulie/common/representation/atom/person.rb +48 -0
- data/lib/restfulie/common/representation/atom/source.rb +59 -0
- data/lib/restfulie/common/representation/atom/tag_collection.rb +38 -0
- data/lib/restfulie/common/representation/atom/xml.rb +95 -0
- data/lib/restfulie/common/representation/generic.rb +30 -29
- data/lib/restfulie/common/representation/json.rb +10 -22
- data/lib/restfulie/common/representation/json/base.rb +27 -0
- data/lib/restfulie/common/representation/json/keys_as_methods.rb +72 -0
- data/lib/restfulie/common/representation/json/link.rb +29 -0
- data/lib/restfulie/common/representation/json/link_collection.rb +23 -0
- data/lib/restfulie/common/representation/xml.rb +18 -227
- data/lib/restfulie/server.rb +9 -10
- data/lib/restfulie/server/action_controller.rb +10 -12
- data/lib/restfulie/server/action_controller/base.rb +18 -15
- data/lib/restfulie/server/action_controller/{routing/patch.rb → patch.rb} +0 -0
- data/lib/restfulie/server/action_controller/restful_responder.rb +43 -35
- data/lib/restfulie/server/action_view.rb +8 -6
- data/lib/restfulie/server/action_view/helpers.rb +47 -41
- data/lib/restfulie/server/action_view/template_handlers.rb +24 -12
- data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +17 -12
- data/lib/restfulie/server/configuration.rb +22 -19
- data/lib/restfulie/server/{restfulie_controller.rb → controller.rb} +1 -10
- data/lib/restfulie/server/core_ext.rb +1 -1
- data/lib/restfulie/version.rb +14 -0
- metadata +52 -16
- data/lib/restfulie/client/http/adapter.rb +0 -502
- data/lib/restfulie/client/http/atom_ext.rb +0 -4
- data/lib/restfulie/client/http/core_ext.rb +0 -6
- data/lib/restfulie/client/http/core_ext/http.rb +0 -19
- data/lib/restfulie/client/http/marshal.rb +0 -145
- data/lib/restfulie/client/http/xml_ext.rb +0 -7
- data/lib/restfulie/common/core_ext/proc.rb +0 -48
- data/lib/restfulie/common/errors.rb +0 -15
- data/lib/restfulie/server/action_controller/routing.rb +0 -12
- data/lib/restfulie/server/action_controller/routing/restful_route.rb +0 -14
@@ -1,375 +1,132 @@
|
|
1
|
-
module Restfulie
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# Tools
|
19
|
-
def css(*args)
|
20
|
-
@doc.css(*args)
|
21
|
-
end
|
22
|
-
|
23
|
-
def xpath(*args)
|
24
|
-
@doc.xpath(*args)
|
25
|
-
end
|
26
|
-
|
27
|
-
def atom_type
|
28
|
-
self.class.name.demodulize.downcase
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_xml
|
32
|
-
@doc.to_xml
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_s
|
36
|
-
to_xml
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def text(node_name)
|
42
|
-
(node = @doc.at_xpath("xmlns:#{node_name}")) ? node.content : nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def set_text(node_name, value)
|
46
|
-
unless (node = @doc.at_xpath("xmlns:#{node_name}"))
|
47
|
-
node = create_element(node_name, value)
|
48
|
-
node.parent = @doc
|
49
|
-
else
|
50
|
-
value = value.xmlschema if value.kind_of?(Time) || value.kind_of?(DateTime)
|
51
|
-
node.content = value
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def create_element(node, *args)
|
58
|
-
node = @doc.document.create_element(node) do |n|
|
59
|
-
args.each do |arg|
|
60
|
-
case arg
|
61
|
-
# Adding XML attributes
|
62
|
-
when Hash
|
63
|
-
arg.each { |k,v|
|
64
|
-
key = k.to_s
|
65
|
-
if key =~ /^xmlns(:\w+)?$/
|
66
|
-
ns_name = key.split(":", 2)[1]
|
67
|
-
n.add_namespace_definition(ns_name, v)
|
68
|
-
next
|
69
|
-
end
|
70
|
-
n[k.to_s] = v.to_s
|
1
|
+
module Restfulie
|
2
|
+
module Common
|
3
|
+
module Representation
|
4
|
+
module Atom
|
5
|
+
class Base < XML
|
6
|
+
ATOM_ATTRIBUTES = {
|
7
|
+
:feed => {
|
8
|
+
:required => [:id, :title, :updated],
|
9
|
+
:recommended => [:author, :link],
|
10
|
+
:optional => [:category, :contributor, :rights, :generator, :icon, :logo, :subtitle]
|
11
|
+
},
|
12
|
+
|
13
|
+
:entry => {
|
14
|
+
:required => [:id, :title, :updated],
|
15
|
+
:recommended => [:author, :link, :content, :summary],
|
16
|
+
:optional => [:category, :contributor, :rights, :published, :source]
|
71
17
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
18
|
+
}
|
19
|
+
|
20
|
+
def initialize(xml_obj = nil)
|
21
|
+
@authors = nil
|
22
|
+
@contributors = nil
|
23
|
+
@links = nil
|
24
|
+
@categories = nil
|
25
|
+
@reserved = []
|
26
|
+
super(xml_obj)
|
27
|
+
end
|
28
|
+
|
29
|
+
# lists all extension points available in this entry
|
30
|
+
def extensions
|
31
|
+
result = []
|
32
|
+
@doc.children.each do |e|
|
33
|
+
if e.element?
|
34
|
+
result << e unless @reserved.map(&:to_s).include?(e.node_name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return result
|
38
|
+
end
|
39
|
+
|
40
|
+
# simpletext
|
41
|
+
def id
|
42
|
+
text("id")
|
76
43
|
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
class Base < XML
|
85
|
-
|
86
|
-
ATOM_ATTRIBUTES = {
|
87
|
-
:feed => {
|
88
|
-
:required => [:id, :title, :updated],
|
89
|
-
:recommended => [:author, :link],
|
90
|
-
:optional => [:category, :contributor, :rights, :generator, :icon, :logo, :subtitle]
|
91
|
-
},
|
92
|
-
|
93
|
-
:entry => {
|
94
|
-
:required => [:id, :title, :updated],
|
95
|
-
:recommended => [:author, :link, :content, :summary],
|
96
|
-
:optional => [:category, :contributor, :rights, :published, :source]
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
def initialize(xml_obj = nil)
|
101
|
-
@authors = nil
|
102
|
-
@contributors = nil
|
103
|
-
@links = nil
|
104
|
-
@categories = nil
|
105
|
-
@reserved = []
|
106
|
-
super(xml_obj)
|
107
|
-
end
|
108
|
-
|
109
|
-
# lists all extension points available in this entry
|
110
|
-
def extensions
|
111
|
-
result = []
|
112
|
-
@doc.children.each do |e|
|
113
|
-
if e.element?
|
114
|
-
result << e unless @reserved.map(&:to_s).include?(e.node_name)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
return result
|
118
|
-
end
|
119
|
-
|
120
|
-
#simpletext
|
121
|
-
def id
|
122
|
-
text("id")
|
123
|
-
end
|
124
|
-
|
125
|
-
def id=(value)
|
126
|
-
set_text("id", value)
|
127
|
-
end
|
128
|
-
|
129
|
-
# text
|
130
|
-
def title
|
131
|
-
text("title")
|
132
|
-
end
|
133
|
-
|
134
|
-
def title=(value)
|
135
|
-
set_text("title", value)
|
136
|
-
end
|
137
|
-
|
138
|
-
def updated
|
139
|
-
value = text("updated")
|
140
|
-
Time.parse(value) unless value.nil?
|
141
|
-
end
|
142
|
-
|
143
|
-
def updated=(value)
|
144
|
-
set_text("updated", value)
|
145
|
-
end
|
146
|
-
|
147
|
-
# text
|
148
|
-
def rights
|
149
|
-
text("rights")
|
150
|
-
end
|
151
|
-
|
152
|
-
def rights=(value)
|
153
|
-
set_text("rights", value)
|
154
|
-
end
|
155
|
-
|
156
|
-
# Author have name, and optional uri and email, this describes a person
|
157
|
-
def authors
|
158
|
-
unless @authors
|
159
|
-
@authors = TagCollection.new(@doc)
|
160
|
-
@doc.xpath("xmlns:author").each do |author|
|
161
|
-
@authors << Person.new("author", author)
|
162
|
-
end
|
163
|
-
end
|
164
44
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
def contributors
|
169
|
-
unless @contributors
|
170
|
-
@contributors = TagCollection.new(@doc)
|
171
|
-
@doc.xpath("xmlns:author").each do |contributor|
|
172
|
-
@contributors << Person.new("contributor", contributor)
|
173
|
-
end
|
174
|
-
end
|
45
|
+
def id=(value)
|
46
|
+
set_text("id", value)
|
47
|
+
end
|
175
48
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
unless linkset.empty?
|
185
|
-
linkset.size == 1 ? linkset.first : linkset
|
186
|
-
else
|
187
|
-
nil
|
188
|
-
end
|
189
|
-
end
|
190
|
-
@doc.xpath("xmlns:link").each do |link|
|
191
|
-
@links << Link.new(link)
|
192
|
-
end
|
193
|
-
end
|
49
|
+
# text
|
50
|
+
def title
|
51
|
+
text("title")
|
52
|
+
end
|
53
|
+
|
54
|
+
def title=(value)
|
55
|
+
set_text("title", value)
|
56
|
+
end
|
194
57
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
204
|
-
end
|
58
|
+
def updated
|
59
|
+
value = text("updated")
|
60
|
+
Time.parse(value) unless value.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
def updated=(value)
|
64
|
+
set_text("updated", value)
|
65
|
+
end
|
205
66
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
def type
|
268
|
-
@doc["type"]
|
269
|
-
end
|
270
|
-
|
271
|
-
def type=(value)
|
272
|
-
@doc["type"] = value
|
273
|
-
end
|
274
|
-
|
275
|
-
def hreflang
|
276
|
-
@doc["hreflang"]
|
277
|
-
end
|
278
|
-
|
279
|
-
def hreflang=(value)
|
280
|
-
@doc["hreflang"] = value
|
281
|
-
end
|
282
|
-
|
283
|
-
def title
|
284
|
-
@doc["title"]
|
285
|
-
end
|
286
|
-
|
287
|
-
def title=(value)
|
288
|
-
@doc["title"] = value
|
289
|
-
end
|
290
|
-
|
291
|
-
def length
|
292
|
-
@doc["length"]
|
293
|
-
end
|
294
|
-
|
295
|
-
def length=(value)
|
296
|
-
@doc["length"] = value
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
class Person < XML
|
301
|
-
def initialize(node_type, options_or_obj)
|
302
|
-
if options_or_obj.kind_of?(Hash)
|
303
|
-
@doc = Nokogiri::XML::Document.new()
|
304
|
-
node = @doc.create_element(node_type)
|
305
|
-
node.add_namespace_definition(nil, "http://www.w3.org/2005/Atom")
|
306
|
-
node.parent = @doc
|
307
|
-
super(node)
|
308
|
-
options_or_obj.each do |key,value|
|
309
|
-
self.send("#{key}=".to_sym, value)
|
67
|
+
# text
|
68
|
+
def rights
|
69
|
+
text("rights")
|
70
|
+
end
|
71
|
+
|
72
|
+
def rights=(value)
|
73
|
+
set_text("rights", value)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Author have name, and optional uri and email, this describes a person
|
77
|
+
def authors
|
78
|
+
unless @authors
|
79
|
+
@authors = TagCollection.new(@doc)
|
80
|
+
@doc.xpath("xmlns:author").each do |author|
|
81
|
+
@authors << Person.new("author", author)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
return @authors
|
86
|
+
end
|
87
|
+
|
88
|
+
def contributors
|
89
|
+
unless @contributors
|
90
|
+
@contributors = TagCollection.new(@doc)
|
91
|
+
@doc.xpath("xmlns:author").each do |contributor|
|
92
|
+
@contributors << Person.new("contributor", contributor)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
return @contributor
|
97
|
+
end
|
98
|
+
|
99
|
+
# It has one required attribute, href, and five optional attributes: rel, type, hreflang, title, and length
|
100
|
+
def links
|
101
|
+
unless @links
|
102
|
+
@links = TagCollection.new(@doc) do |array, symbol, *args|
|
103
|
+
linkset = array.select {|link| link.rel == symbol.to_s }
|
104
|
+
unless linkset.empty?
|
105
|
+
linkset.size == 1 ? linkset.first : linkset
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
@doc.xpath("xmlns:link").each do |link|
|
111
|
+
@links << Link.new(link)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
return @links
|
116
|
+
end
|
117
|
+
|
118
|
+
def categories
|
119
|
+
unless @categories
|
120
|
+
@categories = TagCollection.new(@doc)
|
121
|
+
@doc.xpath("xmlns:category").each do |category|
|
122
|
+
@categories << Link.new(category)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
return @categories
|
127
|
+
end
|
310
128
|
end
|
311
|
-
else
|
312
|
-
super(options_or_obj)
|
313
129
|
end
|
314
130
|
end
|
315
|
-
|
316
|
-
def name
|
317
|
-
text("name")
|
318
|
-
end
|
319
|
-
|
320
|
-
def name=(value)
|
321
|
-
set_text("name", value)
|
322
|
-
end
|
323
|
-
|
324
|
-
def uri
|
325
|
-
text("uri")
|
326
|
-
end
|
327
|
-
|
328
|
-
def uri=(value)
|
329
|
-
set_text("uri", value)
|
330
|
-
end
|
331
|
-
|
332
|
-
def email
|
333
|
-
text("email")
|
334
|
-
end
|
335
|
-
|
336
|
-
def email=(value)
|
337
|
-
set_text("email", value)
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
class Category < XML
|
342
|
-
def initialize(options_or_obj)
|
343
|
-
if options_or_obj.kind_of?(Hash)
|
344
|
-
@doc = Nokogiri::XML::Document.new()
|
345
|
-
options_or_obj = create_element("category", options_or_obj)
|
346
|
-
end
|
347
|
-
super(options_or_obj)
|
348
|
-
end
|
349
|
-
|
350
|
-
def term
|
351
|
-
@doc["term"]
|
352
|
-
end
|
353
|
-
|
354
|
-
def term=(value)
|
355
|
-
@doc["term"] = value
|
356
|
-
end
|
357
|
-
|
358
|
-
def scheme
|
359
|
-
@doc["scheme"]
|
360
|
-
end
|
361
|
-
|
362
|
-
def scheme=(value)
|
363
|
-
@doc["scheme"] = value
|
364
|
-
end
|
365
|
-
|
366
|
-
def label
|
367
|
-
@doc["label"]
|
368
|
-
end
|
369
|
-
|
370
|
-
def label=(value)
|
371
|
-
@doc["label"] = value
|
372
|
-
end
|
373
131
|
end
|
374
|
-
|
375
|
-
end
|
132
|
+
end
|