restfulie 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,41 @@
1
+ module Restfulie
2
+ module Common
3
+ module Representation
4
+ module Atom
5
+ class Category < XML
6
+ def initialize(options_or_obj)
7
+ if options_or_obj.kind_of?(Hash)
8
+ @doc = Nokogiri::XML::Document.new()
9
+ options_or_obj = create_element("category", options_or_obj)
10
+ end
11
+ super(options_or_obj)
12
+ end
13
+
14
+ def term
15
+ @doc["term"]
16
+ end
17
+
18
+ def term=(value)
19
+ @doc["term"] = value
20
+ end
21
+
22
+ def scheme
23
+ @doc["scheme"]
24
+ end
25
+
26
+ def scheme=(value)
27
+ @doc["scheme"] = value
28
+ end
29
+
30
+ def label
31
+ @doc["label"]
32
+ end
33
+
34
+ def label=(value)
35
+ @doc["label"] = value
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,107 +1,59 @@
1
- module Restfulie::Common::Representation::Atom
2
-
3
- class Entry < Base
4
-
5
- def initialize(xml_obj = nil)
6
- @source = nil
7
- super(xml_obj)
8
- @reserved = Base::ATOM_ATTRIBUTES[:entry][:required] + Base::ATOM_ATTRIBUTES[:entry][:recommended] + Base::ATOM_ATTRIBUTES[:entry][:optional]
9
- end
10
-
11
- #text
12
- def content
13
- text("content")
14
- end
15
-
16
- def content=(value)
17
- set_text("content", value)
18
- end
19
-
20
- #text
21
- def summary
22
- text("summary")
23
- end
24
-
25
- def summary=(value)
26
- set_text("summary", value)
27
- end
28
-
29
- #rfc 3339
30
- def published
31
- value = text("published")
32
- Time.parse(value) unless value.nil?
33
- end
34
-
35
- def published=(value)
36
- set_text("published", value)
37
- end
38
-
39
- # comp: id, title, udpated, rights (optional)
40
- def source
41
- unless @source
42
- @doc.xpath("xmlns:source").each do |source|
43
- @source = Generator.new(source)
44
- end
45
- end
1
+ module Restfulie
2
+ module Common
3
+ module Representation
4
+ module Atom
5
+ class Entry < Base
6
+ def initialize(xml_obj = nil)
7
+ @source = nil
8
+ super(xml_obj)
9
+ @reserved = Base::ATOM_ATTRIBUTES[:entry][:required] + Base::ATOM_ATTRIBUTES[:entry][:recommended] + Base::ATOM_ATTRIBUTES[:entry][:optional]
10
+ end
11
+
12
+ # text
13
+ def content
14
+ text("content")
15
+ end
46
16
 
47
- return source
48
- end
49
-
50
- def source=(obj)
51
- @source = obj
52
- end
53
- end
54
-
55
- class Source < XML
56
- def initialize(options_or_obj)
57
- if options_or_obj.kind_of?(Hash)
58
- @doc = Nokogiri::XML::Document.new()
59
- node = @doc.create_element("source")
60
- node.add_namespace_definition(nil, "http://www.w3.org/2005/Atom")
61
- node.parent = @doc
62
- super(node)
63
- options_or_obj.each do |key,value|
64
- self.send("#{key}=".to_sym, value)
17
+ def content=(value)
18
+ set_text("content", value)
19
+ end
20
+
21
+ # text
22
+ def summary
23
+ text("summary")
24
+ end
25
+
26
+ def summary=(value)
27
+ set_text("summary", value)
28
+ end
29
+
30
+ # rfc 3339
31
+ def published
32
+ value = text("published")
33
+ Time.parse(value) unless value.nil?
34
+ end
35
+
36
+ def published=(value)
37
+ set_text("published", value)
38
+ end
39
+
40
+ # comp: id, title, udpated, rights (optional)
41
+ def source
42
+ unless @source
43
+ @doc.xpath("xmlns:source").each do |source|
44
+ @source = Generator.new(source)
45
+ end
46
+ end
47
+
48
+ return source
49
+ end
50
+
51
+ def source=(obj)
52
+ @source = obj
53
+ end
65
54
  end
66
- else
67
- super(options_or_obj)
68
55
  end
69
56
  end
70
-
71
- def id
72
- text("id")
73
- end
74
-
75
- def id=(value)
76
- set_text("id", value)
77
- end
78
-
79
- # text
80
- def title
81
- text("title")
82
- end
83
-
84
- def title=(value)
85
- set_text("title", value)
86
- end
87
-
88
- def updated
89
- value = text("updated")
90
- Time.parse(value) unless value.nil?
91
- end
92
-
93
- def updated=(value)
94
- set_text("updated", value)
95
- end
96
-
97
- # text
98
- def rights
99
- text("rights")
100
- end
101
-
102
- def rights=(value)
103
- set_text("rights", value)
104
- end
105
57
  end
106
58
  end
107
59
 
@@ -0,0 +1,43 @@
1
+ module Restfulie
2
+ module Common
3
+ module Representation
4
+ module Atom
5
+ # Create a new Representation::Atom object using a +string_or_io+
6
+ # object.
7
+ #
8
+ # Examples
9
+ # xml = IO.read("spec/units/lib/atoms/full_atom.xml")
10
+ # atom = Restfulie::Common::Representation::Atom.new(xml)
11
+ class Factory
12
+ # RelaxNG file to validate atom
13
+ RELAXNG_ATOM = File.join(File.dirname(__FILE__), 'atom.rng')
14
+
15
+ if Nokogiri::VERSION_INFO["libxml"]["loaded"] < "2.7.7"
16
+ puts "WARNING! In order to use schema validation on atom representations you need libxml version 2.7.7 or superior loaded in your system."
17
+ SCHEMA = nil
18
+ else
19
+ SCHEMA = ::Nokogiri::XML::RelaxNG(File.open(RELAXNG_ATOM))
20
+ end
21
+
22
+ def self.create(string_or_io)
23
+ doc = string_or_io.kind_of?(Nokogiri::XML::Document) ? string_or_io : Nokogiri::XML(string_or_io)
24
+
25
+ if SCHEMA && !(errors = SCHEMA.validate(doc)).empty?
26
+ raise AtomInvalid.new("Invalid Atom: "+ errors.join(", "))
27
+ end
28
+
29
+ case doc.root.name
30
+ when "feed"
31
+ Restfulie::Common::Representation::Atom::Feed.new(doc)
32
+ when "entry"
33
+ Restfulie::Common::Representation::Atom::Entry.new(doc)
34
+ end
35
+ end
36
+ end
37
+
38
+ class AtomInvalid < StandardError
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,106 +1,110 @@
1
- module Restfulie::Common::Representation::Atom
2
-
3
- class Feed < Base
4
-
5
- def initialize(xml_obj = nil)
6
- @generator = nil
7
- @entries = nil
8
- super(xml_obj)
9
- @reserved = Base::ATOM_ATTRIBUTES[:feed][:required] + Base::ATOM_ATTRIBUTES[:feed][:recommended] + Base::ATOM_ATTRIBUTES[:feed][:optional] + [:entry]
10
- end
11
-
12
- def entries
13
- unless @entries
14
- @entries = TagCollection.new(@doc)
15
- @doc.xpath("xmlns:entry").each do |entry|
16
- @entries << Entry.new(entry)
17
- end
18
- end
1
+ module Restfulie
2
+ module Common
3
+ module Representation
4
+ module Atom
5
+ class Feed < Base
6
+ def initialize(xml_obj = nil)
7
+ @generator = nil
8
+ @entries = nil
9
+ super(xml_obj)
10
+ @reserved = Base::ATOM_ATTRIBUTES[:feed][:required] + Base::ATOM_ATTRIBUTES[:feed][:recommended] + Base::ATOM_ATTRIBUTES[:feed][:optional] + [:entry]
11
+ end
12
+
13
+ def entries
14
+ unless @entries
15
+ @entries = TagCollection.new(@doc)
16
+ @doc.xpath("xmlns:entry").each do |entry|
17
+ @entries << Entry.new(entry)
18
+ end
19
+ end
20
+
21
+ return @entries
22
+ end
23
+
24
+ # comp: attr: uri, version (optionals); content (mandatory)
25
+ def generator
26
+ unless @generator
27
+ @doc.xpath("xmlns:generator").each do |generator|
28
+ @generator = Generator.new(generator)
29
+ end
30
+ end
31
+
32
+ return generator
33
+ end
34
+
35
+ def generator=(obj)
36
+ @generator = obj
37
+ end
38
+
39
+ # simple text
40
+ def icon
41
+ text("icon")
42
+ end
19
43
 
20
- return @entries
21
- end
22
-
23
- # comp: attr: uri, version (optionals); content (mandatory)
24
- def generator
25
- unless @generator
26
- @doc.xpath("xmlns:generator").each do |generator|
27
- @generator = Generator.new(generator)
28
- end
29
- end
44
+ def icon=(value)
45
+ set_text("icon", value)
46
+ end
47
+
48
+ # simple text
49
+ def logo
50
+ text("logo")
51
+ end
30
52
 
31
- return generator
32
- end
33
-
34
- def generator=(obj)
35
- @generator = obj
36
- end
37
-
38
- # simple text
39
- def icon
40
- text("icon")
41
- end
42
-
43
- def icon=(value)
44
- set_text("icon", value)
45
- end
46
-
47
- # simple text
48
- def logo
49
- text("logo")
50
- end
51
-
52
- def logo=(value)
53
- set_text("logo", value)
54
- end
55
-
56
- # text
57
- def subtitle
58
- text("subtitle")
59
- end
60
-
61
- def subtitle=(value)
62
- set_text("subtitle", value)
63
- end
64
- end
65
-
66
- class Generator < XML
67
- def initialize(options_or_obj)
68
- if options_or_obj.kind_of?(Hash)
69
- @doc = Nokogiri::XML::Document.new()
70
- node = @doc.create_element("generator")
71
- node.add_namespace_definition(nil, "http://www.w3.org/2005/Atom")
72
- node.parent = @doc
73
- super(node)
74
- options_or_obj.each do |key,value|
75
- self.send("#{key}=".to_sym, value)
53
+ def logo=(value)
54
+ set_text("logo", value)
55
+ end
56
+
57
+ # text
58
+ def subtitle
59
+ text("subtitle")
60
+ end
61
+
62
+ def subtitle=(value)
63
+ set_text("subtitle", value)
64
+ end
65
+ end
66
+
67
+ class Generator < XML
68
+ def initialize(options_or_obj)
69
+ if options_or_obj.kind_of?(Hash)
70
+ @doc = Nokogiri::XML::Document.new()
71
+ node = @doc.create_element("generator")
72
+ node.add_namespace_definition(nil, "http://www.w3.org/2005/Atom")
73
+ node.parent = @doc
74
+ super(node)
75
+ options_or_obj.each do |key,value|
76
+ self.send("#{key}=".to_sym, value)
77
+ end
78
+ else
79
+ super(options_or_obj)
80
+ end
81
+ end
82
+
83
+ def content
84
+ @doc.content
85
+ end
86
+
87
+ def content=(value)
88
+ @doc.content = value
89
+ end
90
+
91
+ def uri
92
+ @doc["uri"]
93
+ end
94
+
95
+ def uri=(value)
96
+ @doc["uri"] = value
97
+ end
98
+
99
+ def version
100
+ @doc["version"]
101
+ end
102
+
103
+ def version=(value)
104
+ @doc["version"] = value
105
+ end
76
106
  end
77
- else
78
- super(options_or_obj)
79
107
  end
80
108
  end
81
-
82
- def content
83
- @doc.content
84
- end
85
-
86
- def content=(value)
87
- @doc.content = value
88
- end
89
-
90
- def uri
91
- @doc["uri"]
92
- end
93
-
94
- def uri=(value)
95
- @doc["uri"] = value
96
- end
97
-
98
- def version
99
- @doc["version"]
100
- end
101
-
102
- def version=(value)
103
- @doc["version"] = value
104
- end
105
109
  end
106
110
  end