restfulie 1.0.0.beta1 → 1.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/Gemfile +8 -10
  2. data/Gemfile.lock +59 -85
  3. data/README.textile +22 -57
  4. data/Rakefile +1 -3
  5. data/lib/restfulie/client/cache/basic.rb +7 -5
  6. data/lib/restfulie/client/cache/restrictions.rb +2 -0
  7. data/lib/restfulie/client/dsl.rb +7 -22
  8. data/lib/restfulie/client/entry_point.rb +1 -1
  9. data/lib/restfulie/client/ext/link_ext.rb +11 -0
  10. data/lib/restfulie/client/ext/open_search_ext.rb +26 -0
  11. data/lib/restfulie/client/ext.rb +3 -0
  12. data/lib/restfulie/client/feature/base_request.rb +2 -2
  13. data/lib/restfulie/client/feature/cache.rb +2 -2
  14. data/lib/restfulie/client/feature/conneg_when_unaccepted.rb +25 -0
  15. data/lib/restfulie/client/feature/enhance_response.rb +2 -2
  16. data/lib/restfulie/client/feature/follow_request.rb +2 -2
  17. data/lib/restfulie/client/feature/history_request.rb +2 -2
  18. data/lib/restfulie/client/feature/retry_when_unavailable.rb +25 -0
  19. data/lib/restfulie/client/feature/serialize_body.rb +7 -4
  20. data/lib/restfulie/client/feature/setup_header.rb +2 -2
  21. data/lib/restfulie/client/feature/throw_error.rb +2 -2
  22. data/lib/restfulie/client/http/link_header.rb +39 -0
  23. data/lib/restfulie/client/http/response_holder.rb +2 -2
  24. data/lib/restfulie/client/stack_navigator.rb +39 -0
  25. data/lib/restfulie/client.rb +3 -5
  26. data/lib/restfulie/common.rb +5 -6
  27. data/lib/restfulie/server/action_controller/base.rb +1 -1
  28. data/lib/restfulie/server/core_ext/array.rb +1 -27
  29. data/lib/restfulie/server/tokamak.rb +6 -0
  30. data/lib/restfulie/server.rb +11 -10
  31. data/lib/restfulie/version.rb +1 -1
  32. metadata +24 -95
  33. data/lib/restfulie/client/ext/atom_ext.rb +0 -14
  34. data/lib/restfulie/client/ext/json_ext.rb +0 -16
  35. data/lib/restfulie/common/converter/atom/base.rb +0 -91
  36. data/lib/restfulie/common/converter/atom/builder.rb +0 -111
  37. data/lib/restfulie/common/converter/atom/helpers.rb +0 -17
  38. data/lib/restfulie/common/converter/atom.rb +0 -12
  39. data/lib/restfulie/common/converter/form_url_encoded.rb +0 -16
  40. data/lib/restfulie/common/converter/json/base.rb +0 -87
  41. data/lib/restfulie/common/converter/json/builder.rb +0 -102
  42. data/lib/restfulie/common/converter/json/helpers.rb +0 -17
  43. data/lib/restfulie/common/converter/json.rb +0 -12
  44. data/lib/restfulie/common/converter/open_search/descriptor.rb +0 -32
  45. data/lib/restfulie/common/converter/open_search.rb +0 -16
  46. data/lib/restfulie/common/converter/values.rb +0 -33
  47. data/lib/restfulie/common/converter/xml/base.rb +0 -63
  48. data/lib/restfulie/common/converter/xml/builder.rb +0 -113
  49. data/lib/restfulie/common/converter/xml/helpers.rb +0 -17
  50. data/lib/restfulie/common/converter/xml/link.rb +0 -30
  51. data/lib/restfulie/common/converter/xml/links.rb +0 -21
  52. data/lib/restfulie/common/converter/xml.rb +0 -14
  53. data/lib/restfulie/common/converter.rb +0 -43
  54. data/lib/restfulie/common/core_ext/hash.rb +0 -18
  55. data/lib/restfulie/common/core_ext.rb +0 -1
  56. data/lib/restfulie/common/links.rb +0 -9
  57. data/lib/restfulie/common/representation/atom/atom.rng +0 -597
  58. data/lib/restfulie/common/representation/atom/base.rb +0 -142
  59. data/lib/restfulie/common/representation/atom/category.rb +0 -41
  60. data/lib/restfulie/common/representation/atom/entry.rb +0 -59
  61. data/lib/restfulie/common/representation/atom/factory.rb +0 -43
  62. data/lib/restfulie/common/representation/atom/feed.rb +0 -110
  63. data/lib/restfulie/common/representation/atom/link.rb +0 -68
  64. data/lib/restfulie/common/representation/atom/person.rb +0 -48
  65. data/lib/restfulie/common/representation/atom/source.rb +0 -59
  66. data/lib/restfulie/common/representation/atom/tag_collection.rb +0 -38
  67. data/lib/restfulie/common/representation/atom/xml.rb +0 -90
  68. data/lib/restfulie/common/representation/atom.rb +0 -20
  69. data/lib/restfulie/common/representation/generic.rb +0 -22
  70. data/lib/restfulie/common/representation/json/base.rb +0 -27
  71. data/lib/restfulie/common/representation/json/keys_as_methods.rb +0 -74
  72. data/lib/restfulie/common/representation/json/link.rb +0 -29
  73. data/lib/restfulie/common/representation/json/link_collection.rb +0 -23
  74. data/lib/restfulie/common/representation/json.rb +0 -13
  75. data/lib/restfulie/common/representation/links.rb +0 -11
  76. data/lib/restfulie/common/representation.rb +0 -3
  77. data/lib/restfulie/server/action_view/helpers.rb +0 -50
  78. data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +0 -21
  79. data/lib/restfulie/server/action_view/template_handlers.rb +0 -30
  80. data/lib/restfulie/server/action_view.rb +0 -10
@@ -1,20 +0,0 @@
1
- require 'nokogiri'
2
-
3
- module Restfulie
4
- module Common
5
- module Representation
6
- module Atom
7
- autoload :Factory, 'restfulie/common/representation/atom/factory'
8
- autoload :XML, 'restfulie/common/representation/atom/xml'
9
- autoload :Base, 'restfulie/common/representation/atom/base'
10
- autoload :TagCollection, 'restfulie/common/representation/atom/tag_collection'
11
- autoload :Link, 'restfulie/common/representation/atom/link'
12
- autoload :Person, 'restfulie/common/representation/atom/person'
13
- autoload :Category, 'restfulie/common/representation/atom/category'
14
- autoload :Feed, 'restfulie/common/representation/atom/feed'
15
- autoload :Entry, 'restfulie/common/representation/atom/entry'
16
- autoload :Source, 'restfulie/common/representation/atom/source'
17
- end
18
- end
19
- end
20
- end
@@ -1,22 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- # Unknown representation's unmarshalling on the client side
5
- class Generic
6
-
7
- # Because there is no media type registered, return the content itself
8
- def unmarshal(content)
9
- def content.links
10
- []
11
- end
12
- content
13
- end
14
-
15
- def marshal(string, rel)
16
- string
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- class Json
5
- module Base
6
- module ClassMethods
7
-
8
- # creates a json unmarshalled version of this object
9
- def create(obj = nil)
10
- @json = {}
11
- return @json.extend(KeysAsMethods) unless obj
12
-
13
- if obj.kind_of?(Hash) || obj.kind_of?(Array)
14
- @json = obj
15
- else
16
- @json = ::JSON.parse(obj)
17
- end
18
-
19
- @json.extend(KeysAsMethods)
20
- end
21
-
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,74 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- class Json
5
- module KeysAsMethods
6
- def self.extended(base)
7
- [:type, :id].each { |m| base.__free_method__(m) }
8
- end
9
-
10
- def [](key)
11
- __normalize__(super(key))
12
- end
13
-
14
- def []=(key, value)
15
- super(key,value)
16
- end
17
-
18
- def to_s
19
- super.to_json
20
- end
21
-
22
- def method_missing(name, *args)
23
- method_name = name.to_s
24
- if method_name.last == '='
25
- self[method_name.chop] = args[0]
26
- else
27
- self[method_name]
28
- end
29
- end
30
-
31
- # if you have a key that is also a method (such as Array#size)
32
- # you can use this to free the method and use the method obj.size
33
- # to access the value of key "size".
34
- # you still can access the old method with __[method_name]__
35
- def __free_method__(sym)
36
- if self.__metaclass__.method_defined?(sym) && !respond_to?("__#{sym}__")
37
- self.__metaclass__.send(:alias_method, "__#{sym}__", sym)
38
- end
39
- self.__metaclass__.send(:define_method, sym) { method_missing(sym.to_s) }
40
- self
41
- end
42
-
43
- def __metaclass__
44
- class << self; self; end
45
- end
46
-
47
- include Restfulie::Common::Links
48
-
49
- # easy accessors to links
50
- def links
51
- some_links = self["link"]
52
- return nil unless some_links
53
- some_links = [some_links] unless some_links.kind_of? Array
54
- LinkCollection.new(some_links)
55
- end
56
-
57
- private
58
-
59
- def __normalize__(value)
60
- case value
61
- when Hash
62
- value.extend(KeysAsMethods)
63
- when Array
64
- value.map { |v| __normalize__(v) }
65
- else
66
- value
67
- end
68
- value
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,29 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- class Json
5
- class Link
6
- def initialize(obj)
7
- @obj = obj
8
- end
9
-
10
- def type
11
- @obj.type
12
- end
13
-
14
- def href
15
- @obj.href
16
- end
17
-
18
- def rel
19
- @obj.rel
20
- end
21
-
22
- def method_missing(symbol, *args, &block)
23
- @obj.send(symbol, *args, &block)
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,23 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- class Json
5
- class LinkCollection
6
- def initialize(parent_node)
7
- @node = parent_node
8
- end
9
-
10
- def method_missing(symbol, *args, &block)
11
- linkset = @node.select {|link| link.rel == symbol.to_s }
12
- linkset.map! { |link| Link.new(link) }
13
- unless linkset.empty?
14
- linkset.size == 1 ? linkset.first : linkset
15
- else
16
- nil
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- class Json
5
- autoload :Base, 'restfulie/common/representation/json/base'
6
- autoload :KeysAsMethods, 'restfulie/common/representation/json/keys_as_methods'
7
- autoload :Link, 'restfulie/common/representation/json/link'
8
- autoload :LinkCollection, 'restfulie/common/representation/json/link_collection'
9
- extend Base::ClassMethods
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- module Restfulie
2
- module Common
3
- module Representation
4
- module Links
5
- def self.extract_link_header(links)
6
- links.collect {|link| "<#{link.href}>; rel=#{link.rel}"}.join(', ')
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,3 +0,0 @@
1
- module Restfulie::Common::Representation
2
- Dir["#{File.dirname(__FILE__)}/representation/*.rb"].each {|f| autoload File.basename(f)[0..-4].camelize.to_sym, f }
3
- end
@@ -1,50 +0,0 @@
1
- module Restfulie
2
- module Server
3
- module ActionView
4
- module Helpers
5
- # Load a partial template to execute in describe
6
- #
7
- # For example:
8
- #
9
- # Passing the current context to partial in template:
10
- #
11
- # member(@album) do |member, album|
12
- # partial('member', binding)
13
- # end
14
- #
15
- # in partial:
16
- #
17
- # member.links << link(:rel => :artists, :href => album_artists_url(album))
18
- #
19
- # Or passing local variables assing
20
- #
21
- # collection(@albums) do |collection|
22
- # collection.members do |member, album|
23
- # partial("member", :locals => {:member => member, :album => album})
24
- # end
25
- # end
26
- #
27
- def partial(partial_path, caller_binding = nil)
28
- # Create a context to assing variables
29
- if caller_binding.kind_of?(Hash)
30
- Proc.new do
31
- extend @restfulie_type_helpers
32
- context = eval("(class << self; self; end)", binding)
33
-
34
- unless caller_binding[:locals].nil?
35
- caller_binding[:locals].each do |k, v|
36
- context.send(:define_method, k.to_sym) { v }
37
- end
38
- end
39
-
40
- partial(partial_path, binding)
41
- end.call
42
- else
43
- template = _pick_partial_template(partial_path)
44
- eval(template.source, caller_binding, template.path)
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,21 +0,0 @@
1
- module Restfulie
2
- module Server
3
- module ActionView
4
- module TemplateHandlers
5
- class Tokamak < ::ActionView::TemplateHandler
6
- include ::ActionView::TemplateHandlers::Compilable
7
-
8
- def compile(template)
9
- "@restfulie_type_helpers = Restfulie::Common::Converter.content_type_for(self.response.content_type).helper; " +
10
- "extend @restfulie_type_helpers; " +
11
- "extend Restfulie::Server::ActionView::Helpers; " +
12
- "code_block = lambda { #{template.source} };" +
13
- "builder = code_block.call; " +
14
- "self.response.headers['Link'] = Restfulie::Common::Representation::Links.extract_link_header(builder.links) if builder.respond_to?(:links); " +
15
- "builder.to_s"
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- module Restfulie
2
- module Server
3
- module ActionView
4
- module TemplateHandlers #:nodoc:
5
- autoload :Tokamak, 'restfulie/server/action_view/template_handlers/tokamak'
6
-
7
- def self.template_registry
8
- if defined? ::ActionView::Template and
9
- ::ActionView::Template.respond_to?(:register_template_handler)
10
- ::ActionView::Template
11
- else
12
- ::ActionView::Base
13
- end
14
- end
15
-
16
- # It is needed to explicitly call 'activate!' to install the Tokamak
17
- # template handler
18
- def self.activate!
19
- template_registry.register_template_handler(:tokamak,
20
- Restfulie::Server::ActionView::TemplateHandlers::Tokamak)
21
-
22
- # TODO unsure if it can be removed. check feedback prior to 1.0.0
23
- # if defined?(::ActionController::Base) && ::ActionController::Base.respond_to?(:exempt_from_layout)
24
- # ::ActionController::Base.exempt_from_layout :tokamak
25
- # end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,10 +0,0 @@
1
- if defined? ::ActionView and ::ActionController
2
- module Restfulie #:nodoc:
3
- module Server #:nodoc:
4
- module ActionView #:nodoc:
5
- autoload :TemplateHandlers, 'restfulie/server/action_view/template_handlers'
6
- autoload :Helpers, 'restfulie/server/action_view/helpers'
7
- end
8
- end
9
- end
10
- end