restfulie 0.1.0.beta1 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/README.textile +87 -99
  2. data/Rakefile +14 -109
  3. data/lib/restfulie.rb +183 -23
  4. metadata +12 -197
  5. data/Gemfile +0 -28
  6. data/Gemfile.lock +0 -128
  7. data/LICENSE +0 -17
  8. data/lib/restfulie/client.rb +0 -26
  9. data/lib/restfulie/client/base.rb +0 -36
  10. data/lib/restfulie/client/cache.rb +0 -11
  11. data/lib/restfulie/client/cache/basic.rb +0 -76
  12. data/lib/restfulie/client/cache/fake.rb +0 -15
  13. data/lib/restfulie/client/cache/http_ext.rb +0 -123
  14. data/lib/restfulie/client/cache/restrictions.rb +0 -13
  15. data/lib/restfulie/client/configuration.rb +0 -67
  16. data/lib/restfulie/client/dsl.rb +0 -66
  17. data/lib/restfulie/client/entry_point.rb +0 -61
  18. data/lib/restfulie/client/ext/atom_ext.rb +0 -14
  19. data/lib/restfulie/client/ext/http_ext.rb +0 -22
  20. data/lib/restfulie/client/ext/json_ext.rb +0 -16
  21. data/lib/restfulie/client/feature.rb +0 -5
  22. data/lib/restfulie/client/feature/base.rb +0 -75
  23. data/lib/restfulie/client/feature/base_request.rb +0 -35
  24. data/lib/restfulie/client/feature/cache.rb +0 -16
  25. data/lib/restfulie/client/feature/enhance_response.rb +0 -12
  26. data/lib/restfulie/client/feature/follow_request.rb +0 -41
  27. data/lib/restfulie/client/feature/history.rb +0 -26
  28. data/lib/restfulie/client/feature/history_request.rb +0 -19
  29. data/lib/restfulie/client/feature/open_search.rb +0 -21
  30. data/lib/restfulie/client/feature/open_search/pattern_matcher.rb +0 -25
  31. data/lib/restfulie/client/feature/serialize_body.rb +0 -32
  32. data/lib/restfulie/client/feature/setup_header.rb +0 -22
  33. data/lib/restfulie/client/feature/throw_error.rb +0 -41
  34. data/lib/restfulie/client/feature/verb.rb +0 -119
  35. data/lib/restfulie/client/http.rb +0 -7
  36. data/lib/restfulie/client/http/cache.rb +0 -28
  37. data/lib/restfulie/client/http/error.rb +0 -77
  38. data/lib/restfulie/client/http/response_holder.rb +0 -29
  39. data/lib/restfulie/client/master_delegator.rb +0 -31
  40. data/lib/restfulie/client/mikyung.rb +0 -15
  41. data/lib/restfulie/client/mikyung/concatenator.rb +0 -18
  42. data/lib/restfulie/client/mikyung/core.rb +0 -70
  43. data/lib/restfulie/client/mikyung/languages.rb +0 -11
  44. data/lib/restfulie/client/mikyung/languages/german.rb +0 -24
  45. data/lib/restfulie/client/mikyung/languages/portuguese.rb +0 -23
  46. data/lib/restfulie/client/mikyung/rest_process_model.rb +0 -191
  47. data/lib/restfulie/client/mikyung/steady_state_walker.rb +0 -38
  48. data/lib/restfulie/client/mikyung/then_condition.rb +0 -39
  49. data/lib/restfulie/client/mikyung/when_condition.rb +0 -57
  50. data/lib/restfulie/common.rb +0 -18
  51. data/lib/restfulie/common/converter.rb +0 -43
  52. data/lib/restfulie/common/converter/atom.rb +0 -12
  53. data/lib/restfulie/common/converter/atom/base.rb +0 -91
  54. data/lib/restfulie/common/converter/atom/builder.rb +0 -111
  55. data/lib/restfulie/common/converter/atom/helpers.rb +0 -17
  56. data/lib/restfulie/common/converter/json.rb +0 -12
  57. data/lib/restfulie/common/converter/json/base.rb +0 -87
  58. data/lib/restfulie/common/converter/json/builder.rb +0 -102
  59. data/lib/restfulie/common/converter/json/helpers.rb +0 -17
  60. data/lib/restfulie/common/converter/open_search.rb +0 -16
  61. data/lib/restfulie/common/converter/open_search/descriptor.rb +0 -32
  62. data/lib/restfulie/common/converter/values.rb +0 -33
  63. data/lib/restfulie/common/converter/xml.rb +0 -14
  64. data/lib/restfulie/common/converter/xml/base.rb +0 -63
  65. data/lib/restfulie/common/converter/xml/builder.rb +0 -113
  66. data/lib/restfulie/common/converter/xml/helpers.rb +0 -17
  67. data/lib/restfulie/common/converter/xml/link.rb +0 -30
  68. data/lib/restfulie/common/converter/xml/links.rb +0 -21
  69. data/lib/restfulie/common/core_ext.rb +0 -1
  70. data/lib/restfulie/common/core_ext/hash.rb +0 -18
  71. data/lib/restfulie/common/error.rb +0 -19
  72. data/lib/restfulie/common/links.rb +0 -9
  73. data/lib/restfulie/common/logger.rb +0 -19
  74. data/lib/restfulie/common/representation.rb +0 -3
  75. data/lib/restfulie/common/representation/atom.rb +0 -20
  76. data/lib/restfulie/common/representation/atom/atom.rng +0 -597
  77. data/lib/restfulie/common/representation/atom/base.rb +0 -142
  78. data/lib/restfulie/common/representation/atom/category.rb +0 -41
  79. data/lib/restfulie/common/representation/atom/entry.rb +0 -59
  80. data/lib/restfulie/common/representation/atom/factory.rb +0 -43
  81. data/lib/restfulie/common/representation/atom/feed.rb +0 -110
  82. data/lib/restfulie/common/representation/atom/link.rb +0 -68
  83. data/lib/restfulie/common/representation/atom/person.rb +0 -48
  84. data/lib/restfulie/common/representation/atom/source.rb +0 -59
  85. data/lib/restfulie/common/representation/atom/tag_collection.rb +0 -38
  86. data/lib/restfulie/common/representation/atom/xml.rb +0 -90
  87. data/lib/restfulie/common/representation/generic.rb +0 -22
  88. data/lib/restfulie/common/representation/json.rb +0 -13
  89. data/lib/restfulie/common/representation/json/base.rb +0 -27
  90. data/lib/restfulie/common/representation/json/keys_as_methods.rb +0 -74
  91. data/lib/restfulie/common/representation/json/link.rb +0 -29
  92. data/lib/restfulie/common/representation/json/link_collection.rb +0 -23
  93. data/lib/restfulie/common/representation/links.rb +0 -11
  94. data/lib/restfulie/server.rb +0 -25
  95. data/lib/restfulie/server/action_controller.rb +0 -11
  96. data/lib/restfulie/server/action_controller/base.rb +0 -48
  97. data/lib/restfulie/server/action_controller/params_parser.rb +0 -100
  98. data/lib/restfulie/server/action_controller/patch.rb +0 -6
  99. data/lib/restfulie/server/action_controller/restful_responder.rb +0 -12
  100. data/lib/restfulie/server/action_controller/trait.rb +0 -9
  101. data/lib/restfulie/server/action_controller/trait/cacheable.rb +0 -81
  102. data/lib/restfulie/server/action_controller/trait/created.rb +0 -17
  103. data/lib/restfulie/server/action_view.rb +0 -10
  104. data/lib/restfulie/server/action_view/helpers.rb +0 -50
  105. data/lib/restfulie/server/action_view/template_handlers.rb +0 -30
  106. data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +0 -21
  107. data/lib/restfulie/server/configuration.rb +0 -24
  108. data/lib/restfulie/server/controller.rb +0 -74
  109. data/lib/restfulie/server/core_ext.rb +0 -1
  110. data/lib/restfulie/server/core_ext/array.rb +0 -61
  111. data/lib/restfulie/version.rb +0 -14
@@ -1,111 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Atom
5
- class Builder
6
- attr_accessor :atom_type
7
- def initialize(atom_type, obj)
8
- @doc = Nokogiri::XML::Document.new
9
- @obj = obj
10
- @parent = @doc.create_element(atom_type.to_s)
11
- @parent.add_namespace_definition(nil, "http://www.w3.org/2005/Atom")
12
- @parent.parent = @doc
13
- end
14
-
15
- def values(options = {}, &block)
16
- options.each do |key,value|
17
- attr = key.to_s
18
- if attr =~ /^xmlns(:\w+)?$/
19
- ns = attr.split(":", 2)[1]
20
- @parent.add_namespace_definition(ns, value)
21
- end
22
- end
23
- yield Values.new(self)
24
- end
25
-
26
- def members(options = {}, &block)
27
- collection = options[:collection] || @obj
28
- raise Error::BuilderError.new("Members method require a collection to execute") unless collection.respond_to?(:each)
29
- collection.each do |member|
30
- entry = @doc.create_element("entry")
31
- entry.parent = @parent
32
- @parent = entry
33
- block.call(self, member)
34
- @parent = entry.parent
35
- end
36
- end
37
-
38
- def link(relationship, uri, options = {})
39
- options["rel"] = relationship.to_s
40
- options["href"] = uri
41
- options["type"] ||= "application/atom+xml"
42
- insert_value("link", nil, options)
43
- end
44
-
45
- def insert_value(name, prefix, *args, &block)
46
- node = create_element(name.to_s, prefix, *args)
47
- node.parent = @parent
48
- if block_given?
49
- @parent = node
50
- block.call
51
- @parent = node.parent
52
- end
53
- end
54
-
55
- def representation
56
- Representation::Atom::Factory.create(@doc)
57
- end
58
-
59
- private
60
-
61
- def create_element(node, prefix, *args)
62
- node = @doc.create_element(node) do |n|
63
- if prefix
64
- if namespace = prefix_valid?(prefix)
65
- # Adding namespace prefix
66
- n.namespace = namespace
67
- namespace = nil
68
- end
69
- end
70
-
71
- args.each do |arg|
72
- case arg
73
- # Adding XML attributes
74
- when Hash
75
- arg.each { |k,v|
76
- key = k.to_s
77
- if key =~ /^xmlns(:\w+)?$/
78
- ns_name = key.split(":", 2)[1]
79
- n.add_namespace_definition(ns_name, v)
80
- next
81
- end
82
- n[k.to_s] = v.to_s
83
- }
84
- # Adding XML node content
85
- else
86
- arg.kind_of?(Time) || arg.kind_of?(DateTime) ? content = arg.xmlschema : content = arg
87
- n.content = content
88
- end
89
- end
90
- end
91
- end
92
-
93
- def prefix_valid?(prefix)
94
- ns = @parent.namespace_definitions.find { |x| x.prefix == prefix.to_s }
95
-
96
- unless ns
97
- @parent.ancestors.each do |a|
98
- next if a == @doc
99
- ns = a.namespace_definitions.find { |x| x.prefix == prefix.to_s }
100
- break if ns
101
- end
102
- end
103
-
104
- return ns
105
- #TODO: raise ArgumentError, "Namespace #{prefix} has not been defined" if wanted
106
- end
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,17 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Atom
5
- module Helpers
6
- def collection(obj, *args, &block)
7
- Restfulie::Common::Converter::Atom.to_atom(obj, :atom_type => :feed, &block)
8
- end
9
-
10
- def member(obj, *args, &block)
11
- Restfulie::Common::Converter::Atom.to_atom(obj, :atom_type => :entry, &block)
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,12 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Json
5
- autoload :Base, 'restfulie/common/converter/json/base'
6
- autoload :Builder, 'restfulie/common/converter/json/builder'
7
- autoload :Helpers, 'restfulie/common/converter/json/helpers'
8
- extend Base::ClassMethods
9
- end
10
- end
11
- end
12
- end
@@ -1,87 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Json
5
- module Base
6
- module ClassMethods
7
- mattr_reader :media_type_name
8
- @@media_type_name = 'application/json'
9
-
10
- mattr_reader :headers
11
- @@headers = {
12
- :get => { 'Accept' => media_type_name },
13
- :post => { 'Content-Type' => media_type_name }
14
- }
15
-
16
- mattr_reader :recipes
17
- @@recipes = {}
18
-
19
- def describe_recipe(recipe_name, options={}, &block)
20
- raise 'Undefined recipe' unless block_given?
21
- raise 'Undefined recipe_name' unless recipe_name
22
- @@recipes[recipe_name] = block
23
- end
24
-
25
- def to_json(obj = nil, options = {:root => {}}, &block)
26
- # just instantiate the string with the atom factory
27
- return Restfulie::Common::Representation::Json.create(obj) if obj.kind_of?(String)
28
-
29
- if block_given?
30
- recipe = block
31
- else
32
- recipe = options[:recipe]
33
- end
34
-
35
- # Check if the object is already an json
36
- unless recipe
37
- if obj.kind_of?(Hash) || obj.kind_of?(Array)
38
- return Restfulie::Common::Representation::Json.create(obj)
39
- else
40
- raise Restfulie::Common::Error::ConverterError.new("Recipe required")
41
- end
42
- end
43
-
44
- # Get recipe already described
45
- recipe = @@recipes[recipe] unless recipe.respond_to?(:call)
46
-
47
- # Create representation and proxy
48
- builder = Restfulie::Common::Converter::Json::Builder.new(obj, (options[:root] || {}))
49
-
50
- # Check recipe arity size before calling it
51
- recipe.call(*[builder, obj, options][0,recipe.arity])
52
-
53
- builder.representation
54
- end
55
-
56
- alias_method :unmarshal, :to_json
57
-
58
- def to_hash(obj)
59
- return obj if obj.kind_of?(Hash) || obj.kind_of?(Array)
60
-
61
- if obj.kind_of?(::String)
62
- Restfulie::Common::Representation::Json.create(obj)
63
- else
64
- raise Restfulie::Common::Error::ConverterError.new("It was not possible to convert this object to a Hash")
65
- end
66
- end
67
-
68
- def to_s(obj)
69
- return obj if obj.kind_of?(String)
70
- Restfulie::Common::Representation::Json.create(obj).to_s
71
- end
72
-
73
- def marshal(obj, options = nil)
74
- return obj if obj.kind_of? String
75
- to_json(obj, options).to_json
76
- end
77
-
78
- # returns the current helper
79
- def helper
80
- Helpers
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
@@ -1,102 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Json
5
- class Builder
6
- def initialize(obj, initial_obj = {})
7
- @doc = initial_obj
8
- @obj = obj
9
- @current = @doc
10
- end
11
-
12
- def values(options = nil, &block)
13
- yield Values.new(self)
14
- end
15
-
16
- def members(options = {}, &block)
17
- collection = options[:collection] || @obj
18
- raise Error::BuilderError.new("Members method require a collection to execute") unless collection.respond_to?(:each)
19
- root = options[:root] || Restfulie::Common::Converter.root_element_for(collection)
20
-
21
- collection.each do |member|
22
- node = {}
23
-
24
- parent = @current
25
- @current = node
26
- block.call(self, member)
27
- @current = parent
28
-
29
- add_to_current(root, node)
30
- end
31
- end
32
-
33
- def link(relationship, uri, options = {})
34
- options["rel"] = relationship.to_s
35
- options["href"] = uri
36
- options["type"] ||= "application/json"
37
- insert_value("link", nil, options)
38
- end
39
-
40
- def insert_value(name, prefix, *args, &block)
41
- node = create_element(block_given?, *args)
42
-
43
- if block_given?
44
- parent = @current
45
- @current = node
46
- block.call
47
- @current = parent
48
- end
49
-
50
- add_to_current(name, node)
51
- end
52
-
53
- def representation
54
- Representation::Json.create(@doc).to_json
55
- end
56
-
57
- private
58
-
59
- def create_element(has_block, *args)
60
- vals = []
61
- hashes = []
62
-
63
- args.each do |arg|
64
- arg.kind_of?(Hash) ? hashes << arg : vals << arg
65
- end
66
-
67
- if hashes.empty?
68
- # only simple values
69
- unless vals.empty?
70
- vals = vals.first if vals.size == 1
71
- node = has_block ? {} : vals
72
- else
73
- node = has_block ? {} : nil
74
- end
75
- else
76
- # yes we have hashes
77
- node = {}
78
- hashes.each { |hash| node.merge!(hash) }
79
- unless vals.empty?
80
- vals = vals.first if vals.size == 1
81
- node = has_block ? {} : [node, vals]
82
- end
83
- node
84
- end
85
- end
86
-
87
- def add_to_current(name, value)
88
- if @current[name]
89
- if @current[name].kind_of?(Array)
90
- @current[name] << value
91
- else
92
- @current[name] = [@current[name], value]
93
- end
94
- else
95
- @current[name] = value
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,17 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Json
5
- module Helpers
6
- def collection(obj, *args, &block)
7
- Restfulie::Common::Converter::Json.to_json(obj, &block)
8
- end
9
-
10
- def member(obj, *args, &block)
11
- Restfulie::Common::Converter::Json.to_json(obj, &block)
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- module Restfulie
2
- module Common
3
- class Converter::OpenSearch#:nodoc:
4
- autoload :Descriptor, 'restfulie/common/converter/open_search/descriptor'
5
- end
6
- end
7
- end
8
-
9
- class Restfulie::Common::Converter::OpenSearch
10
-
11
- def self.unmarshal(xml)
12
- hash = Hash.from_xml(xml)
13
- descriptor = Descriptor.new(hash)
14
- end
15
-
16
- end
@@ -1,32 +0,0 @@
1
- class Restfulie::Common::Converter::OpenSearch::Descriptor
2
-
3
- def initialize(hash)
4
- @hash = hash["OpenSearchDescription"]
5
- end
6
-
7
- def urls
8
- uris = @hash["Url"]
9
- uris.kind_of?(Array) ? uris : [uris]
10
- end
11
-
12
- def use(content_type)
13
- uri = urls.find do |url|
14
- url["type"]==content_type
15
- end
16
- return nil if uri.nil?
17
-
18
- base_uri, params_pattern = extract_uri(uri)
19
- Restfulie.at(base_uri).accepts(content_type).open_search.with_pattern(params_pattern)
20
- end
21
-
22
- private
23
- def extract_uri(uri)
24
- uri = uri["template"]
25
- interrogation = uri.index("?")
26
- params = uri[interrogation+1..uri.size]
27
- base_uri = uri[0..interrogation-1]
28
- [base_uri, params]
29
- end
30
-
31
- end
32
-
@@ -1,33 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- # This is a Blank Slate class to support the renderization of the values block for Resource Representation Interfaces
5
- # Every Media type should implement a Builder with a insert_value method that renders the values block to a specific format
6
- class Values
7
- attr_accessor :builder
8
-
9
- # BlankSlate
10
- instance_methods.each do |m|
11
- undef_method m unless m.to_s =~ /\[\]|method_missing|respond_to\?|^__/
12
- end
13
-
14
- def initialize(builder)
15
- @builder = builder
16
- @current_prefix = nil
17
- end
18
-
19
- def [](prefix)
20
- @current_prefix = prefix
21
- self
22
- end
23
-
24
- def method_missing(symbol, *args, &block)
25
- name = symbol.to_s
26
- prefix = @current_prefix
27
- @current_prefix = nil
28
- @builder.insert_value(name, prefix, *args, &block)
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,14 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Converter
4
- module Xml
5
- autoload :Base, 'restfulie/common/converter/xml/base'
6
- autoload :Builder, 'restfulie/common/converter/xml/builder'
7
- autoload :Helpers, 'restfulie/common/converter/xml/helpers'
8
- autoload :Links, 'restfulie/common/converter/xml/links'
9
- autoload :Link, 'restfulie/common/converter/xml/link'
10
- extend Base::ClassMethods
11
- end
12
- end
13
- end
14
- end