restfulie 0.8.0 → 0.8.1

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.
Files changed (102) hide show
  1. data/Gemfile +10 -5
  2. data/Rakefile +5 -2
  3. data/lib/restfulie.rb +10 -5
  4. data/lib/restfulie/client.rb +13 -9
  5. data/lib/restfulie/client/base.rb +24 -65
  6. data/lib/restfulie/client/configuration.rb +62 -64
  7. data/lib/restfulie/client/entry_point.rb +36 -0
  8. data/lib/restfulie/client/ext/atom_ext.rb +12 -0
  9. data/lib/restfulie/client/ext/http_ext.rb +22 -0
  10. data/lib/restfulie/client/ext/json_ext.rb +12 -0
  11. data/lib/restfulie/client/ext/xml_ext.rb +4 -0
  12. data/lib/restfulie/client/http.rb +25 -13
  13. data/lib/restfulie/client/http/cache.rb +22 -22
  14. data/lib/restfulie/client/http/error.rb +70 -70
  15. data/lib/restfulie/client/http/link_request_builder.rb +15 -0
  16. data/lib/restfulie/client/http/request_adapter.rb +209 -0
  17. data/lib/restfulie/client/http/request_builder.rb +107 -0
  18. data/lib/restfulie/client/http/request_builder_executor.rb +24 -0
  19. data/lib/restfulie/client/http/request_executor.rb +17 -0
  20. data/lib/restfulie/client/http/request_follow.rb +42 -0
  21. data/lib/restfulie/client/http/request_follow_executor.rb +10 -0
  22. data/lib/restfulie/client/http/request_history.rb +69 -0
  23. data/lib/restfulie/client/http/request_history_executor.rb +10 -0
  24. data/lib/restfulie/client/http/request_marshaller.rb +127 -0
  25. data/lib/restfulie/client/http/request_marshaller_executor.rb +10 -0
  26. data/lib/restfulie/client/http/response.rb +23 -0
  27. data/lib/restfulie/client/http/response_handler.rb +67 -0
  28. data/lib/restfulie/client/http/response_holder.rb +9 -0
  29. data/lib/restfulie/client/mikyung.rb +17 -14
  30. data/lib/restfulie/client/mikyung/concatenator.rb +15 -12
  31. data/lib/restfulie/client/mikyung/core.rb +65 -39
  32. data/lib/restfulie/client/mikyung/languages.rb +8 -26
  33. data/lib/restfulie/client/mikyung/languages/german.rb +24 -0
  34. data/lib/restfulie/client/mikyung/languages/portuguese.rb +23 -0
  35. data/lib/restfulie/client/mikyung/rest_process_model.rb +184 -107
  36. data/lib/restfulie/client/mikyung/steady_state_walker.rb +34 -28
  37. data/lib/restfulie/client/mikyung/then_condition.rb +33 -27
  38. data/lib/restfulie/client/mikyung/when_condition.rb +53 -49
  39. data/lib/restfulie/common.rb +7 -12
  40. data/lib/restfulie/common/converter.rb +20 -9
  41. data/lib/restfulie/common/converter/atom.rb +8 -83
  42. data/lib/restfulie/common/converter/atom/base.rb +89 -0
  43. data/lib/restfulie/common/converter/atom/builder.rb +101 -99
  44. data/lib/restfulie/common/converter/atom/helpers.rb +16 -8
  45. data/lib/restfulie/common/converter/json.rb +12 -0
  46. data/lib/restfulie/common/converter/json/base.rb +84 -0
  47. data/lib/restfulie/common/converter/json/builder.rb +102 -0
  48. data/lib/restfulie/common/converter/json/helpers.rb +17 -0
  49. data/lib/restfulie/common/converter/values.rb +30 -26
  50. data/lib/restfulie/common/converter/xml.rb +14 -0
  51. data/lib/restfulie/common/converter/xml/base.rb +61 -0
  52. data/lib/restfulie/common/converter/xml/builder.rb +112 -0
  53. data/lib/restfulie/common/converter/xml/helpers.rb +17 -0
  54. data/lib/restfulie/common/converter/xml/link.rb +25 -0
  55. data/lib/restfulie/common/converter/xml/links.rb +25 -0
  56. data/lib/restfulie/common/core_ext.rb +1 -5
  57. data/lib/restfulie/common/core_ext/hash.rb +12 -0
  58. data/lib/restfulie/common/error.rb +19 -0
  59. data/lib/restfulie/common/logger.rb +17 -9
  60. data/lib/restfulie/common/representation.rb +9 -10
  61. data/lib/restfulie/common/representation/atom.rb +15 -47
  62. data/lib/restfulie/common/representation/atom/base.rb +122 -365
  63. data/lib/restfulie/common/representation/atom/category.rb +41 -0
  64. data/lib/restfulie/common/representation/atom/entry.rb +52 -100
  65. data/lib/restfulie/common/representation/atom/factory.rb +43 -0
  66. data/lib/restfulie/common/representation/atom/feed.rb +103 -99
  67. data/lib/restfulie/common/representation/atom/link.rb +68 -0
  68. data/lib/restfulie/common/representation/atom/person.rb +48 -0
  69. data/lib/restfulie/common/representation/atom/source.rb +59 -0
  70. data/lib/restfulie/common/representation/atom/tag_collection.rb +38 -0
  71. data/lib/restfulie/common/representation/atom/xml.rb +95 -0
  72. data/lib/restfulie/common/representation/generic.rb +30 -29
  73. data/lib/restfulie/common/representation/json.rb +10 -22
  74. data/lib/restfulie/common/representation/json/base.rb +27 -0
  75. data/lib/restfulie/common/representation/json/keys_as_methods.rb +72 -0
  76. data/lib/restfulie/common/representation/json/link.rb +29 -0
  77. data/lib/restfulie/common/representation/json/link_collection.rb +23 -0
  78. data/lib/restfulie/common/representation/xml.rb +18 -227
  79. data/lib/restfulie/server.rb +9 -10
  80. data/lib/restfulie/server/action_controller.rb +10 -12
  81. data/lib/restfulie/server/action_controller/base.rb +18 -15
  82. data/lib/restfulie/server/action_controller/{routing/patch.rb → patch.rb} +0 -0
  83. data/lib/restfulie/server/action_controller/restful_responder.rb +43 -35
  84. data/lib/restfulie/server/action_view.rb +8 -6
  85. data/lib/restfulie/server/action_view/helpers.rb +47 -41
  86. data/lib/restfulie/server/action_view/template_handlers.rb +24 -12
  87. data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +17 -12
  88. data/lib/restfulie/server/configuration.rb +22 -19
  89. data/lib/restfulie/server/{restfulie_controller.rb → controller.rb} +1 -10
  90. data/lib/restfulie/server/core_ext.rb +1 -1
  91. data/lib/restfulie/version.rb +14 -0
  92. metadata +52 -16
  93. data/lib/restfulie/client/http/adapter.rb +0 -502
  94. data/lib/restfulie/client/http/atom_ext.rb +0 -4
  95. data/lib/restfulie/client/http/core_ext.rb +0 -6
  96. data/lib/restfulie/client/http/core_ext/http.rb +0 -19
  97. data/lib/restfulie/client/http/marshal.rb +0 -145
  98. data/lib/restfulie/client/http/xml_ext.rb +0 -7
  99. data/lib/restfulie/common/core_ext/proc.rb +0 -48
  100. data/lib/restfulie/common/errors.rb +0 -15
  101. data/lib/restfulie/server/action_controller/routing.rb +0 -12
  102. data/lib/restfulie/server/action_controller/routing/restful_route.rb +0 -14
@@ -1,375 +1,132 @@
1
- module Restfulie::Common::Representation::Atom
2
-
3
- class XML
4
- attr_accessor :doc
5
-
6
- def initialize(xml_obj = nil)
7
- if xml_obj
8
- xml_obj.kind_of?(Nokogiri::XML::Document) ? @doc = xml_obj.root : @doc = xml_obj
9
- else
10
- @doc = Nokogiri::XML::Document.new
11
- root_node = @doc.create_element(atom_type.to_s)
12
- root_node.add_namespace_definition(nil, "http://www.w3.org/2005/Atom")
13
- root_node.parent = @doc
14
- @doc = @doc.root
15
- end
16
- end
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
- # Adding XML node content
73
- else
74
- arg.kind_of?(Time) || arg.kind_of?(DateTime) ? content = arg.xmlschema : content = arg
75
- n.content = content
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
- return @authors
166
- end
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
- return @contributor
177
- end
178
-
179
- # It has one required attribute, href, and five optional attributes: rel, type, hreflang, title, and length
180
- def links
181
- unless @links
182
- @links = TagCollection.new(@doc) do |array, symbol, *args|
183
- linkset = array.select {|link| link.rel == symbol.to_s }
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
- return @links
196
- end
197
-
198
- def categories
199
- unless @categories
200
- @categories = TagCollection.new(@doc)
201
- @doc.xpath("xmlns:category").each do |category|
202
- @categories << Link.new(category)
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
- return @categories
207
- end
208
- end
209
-
210
- class TagCollection < ::Array
211
- def initialize(parent_node, &block)
212
- @node = parent_node
213
- @method_missing_block = block_given? ? block : nil
214
- super(0)
215
- end
216
-
217
- def <<(obj)
218
- obj = [obj] unless obj.kind_of?(Array)
219
- obj.each do |o|
220
- o.doc.parent = @node
221
- super(o)
222
- end
223
- end
224
-
225
- def delete(obj)
226
- if super(obj)
227
- obj.doc.unlink
228
- obj = nil
229
- end
230
- end
231
-
232
- def method_missing(symbol, *args, &block)
233
- if @method_missing_block
234
- @method_missing_block.call(self, symbol, *args)
235
- else
236
- super
237
- end
238
- end
239
- end
240
-
241
- class Link < XML
242
- def initialize(options_or_obj)
243
- if options_or_obj.kind_of?(Hash)
244
- @doc = Nokogiri::XML::Document.new()
245
- options_or_obj = create_element("link", options_or_obj)
246
- end
247
- super(options_or_obj)
248
- end
249
-
250
- def href
251
- @doc["href"]
252
- end
253
-
254
- def href=(value)
255
- @doc["href"] = value
256
- end
257
-
258
- def rel
259
- @doc["rel"]
260
- end
261
-
262
- def rel=(value)
263
- @doc["rel"] = value
264
- end
265
-
266
- alias_method :__type__, :type
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