restfulie 0.9.3 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +2 -2
  3. data/README.textile +4 -2
  4. data/Rakefile +12 -13
  5. data/lib/restfulie/client/base.rb +9 -2
  6. data/lib/restfulie/client/cache/basic.rb +6 -5
  7. data/lib/restfulie/client/cache/http_ext.rb +10 -8
  8. data/lib/restfulie/client/cache/restrictions.rb +1 -6
  9. data/lib/restfulie/client/dsl.rb +66 -0
  10. data/lib/restfulie/client/entry_point.rb +34 -9
  11. data/lib/restfulie/client/ext/atom_ext.rb +4 -2
  12. data/lib/restfulie/client/ext/json_ext.rb +5 -1
  13. data/lib/restfulie/client/feature/base.rb +75 -0
  14. data/lib/restfulie/client/feature/base_request.rb +35 -0
  15. data/lib/restfulie/client/feature/cache.rb +16 -0
  16. data/lib/restfulie/client/feature/enhance_response.rb +12 -0
  17. data/lib/restfulie/client/feature/follow_request.rb +41 -0
  18. data/lib/restfulie/client/feature/history.rb +26 -0
  19. data/lib/restfulie/client/feature/history_request.rb +19 -0
  20. data/lib/restfulie/client/feature/open_search/pattern_matcher.rb +25 -0
  21. data/lib/restfulie/client/feature/open_search.rb +21 -0
  22. data/lib/restfulie/client/feature/serialize_body.rb +32 -0
  23. data/lib/restfulie/client/feature/setup_header.rb +22 -0
  24. data/lib/restfulie/client/feature/throw_error.rb +41 -0
  25. data/lib/restfulie/client/feature/verb.rb +119 -0
  26. data/lib/restfulie/client/feature.rb +5 -0
  27. data/lib/restfulie/client/http/response_holder.rb +26 -6
  28. data/lib/restfulie/client/http.rb +1 -21
  29. data/lib/restfulie/client/master_delegator.rb +31 -0
  30. data/lib/restfulie/client/mikyung/core.rb +5 -4
  31. data/lib/restfulie/client/mikyung/steady_state_walker.rb +1 -1
  32. data/lib/restfulie/client/mikyung.rb +1 -8
  33. data/lib/restfulie/client.rb +3 -1
  34. data/lib/restfulie/common/converter/atom/base.rb +2 -0
  35. data/lib/restfulie/common/converter/form_url_encoded.rb +16 -0
  36. data/lib/restfulie/common/converter/json/base.rb +5 -2
  37. data/lib/restfulie/common/converter/open_search/descriptor.rb +32 -0
  38. data/lib/restfulie/common/converter/open_search.rb +16 -0
  39. data/lib/restfulie/common/converter/xml/base.rb +3 -1
  40. data/lib/restfulie/common/converter/xml/builder.rb +3 -2
  41. data/lib/restfulie/common/converter/xml/helpers.rb +4 -4
  42. data/lib/restfulie/common/converter/xml/link.rb +5 -0
  43. data/lib/restfulie/common/converter/xml/links.rb +1 -5
  44. data/lib/restfulie/common/converter.rb +25 -4
  45. data/lib/restfulie/common/core_ext/hash.rb +6 -0
  46. data/lib/restfulie/common/links.rb +9 -0
  47. data/lib/restfulie/common/representation/atom/base.rb +34 -33
  48. data/lib/restfulie/common/representation/atom/xml.rb +5 -10
  49. data/lib/restfulie/common/representation/generic.rb +0 -12
  50. data/lib/restfulie/common/representation/json/keys_as_methods.rb +2 -0
  51. data/lib/restfulie/common/representation.rb +2 -9
  52. data/lib/restfulie/common.rb +2 -1
  53. data/lib/restfulie/server/action_controller/trait/cacheable.rb +81 -0
  54. data/lib/restfulie/server/action_controller/trait/created.rb +17 -0
  55. data/lib/restfulie/server/action_controller/trait/save_prior_to_create.rb +13 -0
  56. data/lib/restfulie/server/action_controller/trait.rb +9 -0
  57. data/lib/restfulie/server/action_controller.rb +1 -5
  58. data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +1 -1
  59. data/lib/restfulie/server.rb +6 -0
  60. data/lib/restfulie/version.rb +4 -4
  61. data/lib/restfulie.rb +21 -3
  62. metadata +37 -26
  63. data/lib/restfulie/client/ext/xml_ext.rb +0 -4
  64. data/lib/restfulie/client/http/link_request_builder.rb +0 -16
  65. data/lib/restfulie/client/http/request_adapter.rb +0 -213
  66. data/lib/restfulie/client/http/request_builder.rb +0 -114
  67. data/lib/restfulie/client/http/request_builder_executor.rb +0 -24
  68. data/lib/restfulie/client/http/request_executor.rb +0 -17
  69. data/lib/restfulie/client/http/request_follow.rb +0 -42
  70. data/lib/restfulie/client/http/request_follow_executor.rb +0 -10
  71. data/lib/restfulie/client/http/request_history.rb +0 -71
  72. data/lib/restfulie/client/http/request_history_executor.rb +0 -10
  73. data/lib/restfulie/client/http/request_marshaller.rb +0 -129
  74. data/lib/restfulie/client/http/request_marshaller_executor.rb +0 -10
  75. data/lib/restfulie/client/http/response.rb +0 -23
  76. data/lib/restfulie/client/http/response_handler.rb +0 -67
  77. data/lib/restfulie/server/action_controller/cacheable_responder.rb +0 -77
  78. data/lib/restfulie/server/action_controller/created_responder.rb +0 -19
@@ -1,67 +0,0 @@
1
- module Restfulie
2
- module Client
3
- module HTTP #:nodoc:
4
- #=ResponseHandler
5
- # You can change instance registering a class according to the code.
6
- #
7
- #==Example
8
- #
9
- # class RequestExecutor
10
- # include RequestAdapter
11
- # def initialize(host)
12
- # self.host=host
13
- # end
14
- # end
15
- #
16
- # class FakeResponse < Restfulie::Client::HTTP::Response
17
- # end
18
- #
19
- # Restfulie::Client::HTTP::ResponseHandler.register(201,FakeResponse)
20
- # @re = Restfulie::Client::HTTP::RequestExecutor.new('http://restfulie.com')
21
- # puts @re.as('application/atom+xml').get!('/posts').class.to_i #=> FakeResponse
22
- #
23
- module ResponseHandler
24
- @@response_handlers = {}
25
- ##
26
- # :singleton-method:
27
- # Response handlers attribute reader
28
- # * code: HTTP status code
29
- def self.handlers(code)
30
- @@response_handlers[code]
31
- end
32
-
33
- ##
34
- # :singleton-method:
35
- # Use to register response handlers
36
- #
37
- # * <tt>code: HTTP status code</tt>
38
- # * <tt>response_class: Response class</tt>
39
- #
40
- #==Example:
41
- # class FakeResponse < ::Restfulie::Client::HTTP::Response
42
- # end
43
- #
44
- # Restfulie::Client::HTTP::ResponseHandler.register(200,FakeResponse)
45
- #
46
- def self.register(code,response_class)
47
- @@response_handlers[code] = response_class
48
- end
49
-
50
- ##
51
- # :singleton-method:
52
- # Request Adapter uses this method to choose response instance
53
- #
54
- # *<tt>method: :get,:post,:delete,:head,:put</tt>
55
- # *<tt>path: '/posts'</tt>
56
- # *<tt>http_response</tt>
57
- #
58
- def self.handle(method, path, http_response)
59
- response_class = @@response_handlers[http_response.code.to_i] || Response
60
- headers = {}
61
- http_response.header.each { |k, v| headers[k] = v }
62
- response_class.new( method, path, http_response.code.to_i, http_response.body, headers)
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,77 +0,0 @@
1
- class Expires
2
- def do_http_cache(responder)
3
- if responder.options[:expires_in]
4
- responder.controller.send :expires_in,responder.options[:expires_in]
5
- true
6
- else
7
- false
8
- end
9
- end
10
- end
11
-
12
- class LastModifieds
13
- # default implementation that will check whether caching can be applied
14
- def do_http_cache?(responder)
15
- responder.resources.flatten.select do |resource|
16
- resource.respond_to?(:updated_at)
17
- end &&
18
- responder.controller.response.last_modified.nil? &&
19
- !new_record?(responder)
20
- end
21
-
22
- def do_http_cache(responder)
23
- return false unless do_http_cache?(responder)
24
-
25
- timestamp = responder.resources.flatten.select do |resource|
26
- resource.respond_to?(:updated_at)
27
- end.map do |resource|
28
- (resource.updated_at || Time.now).utc
29
- end.max
30
-
31
- responder.controller.response.last_modified = timestamp if timestamp
32
- end
33
-
34
- def new_record?(responder)
35
- responder.resource.respond_to?(:new_record?) && responder.resource.new_record?
36
- end
37
-
38
- end
39
-
40
- module Restfulie
41
- module Server
42
- module ActionController
43
- module CacheableResponder
44
-
45
- CACHES = [::Expires.new, ::LastModifieds.new]
46
-
47
- def to_format
48
- cached = CACHES.inject(false) do |cached, cache|
49
- cached || cache.do_http_cache(self)
50
- end
51
- if ::ActionController::Base.perform_caching && !cached.nil?
52
- set_public_cache_control!
53
- head :not_modified if fresh = request.fresh?(controller.response)
54
- fresh
55
- else
56
- super
57
- end
58
- end
59
-
60
- private
61
-
62
- def set_public_cache_control!
63
- cache_control = cache_control_headers.split(",").map {|k| k.strip }
64
- cache_control.delete("private")
65
- cache_control.delete("no-cache")
66
- cache_control << "public"
67
- controller.response.headers["Cache-Control"] = cache_control.join(', ')
68
- end
69
-
70
- def cache_control_headers
71
- controller.response.headers["Cache-Control"] || ""
72
- end
73
-
74
- end
75
- end
76
- end
77
- end
@@ -1,19 +0,0 @@
1
- module Restfulie
2
- module Server
3
- module ActionController
4
-
5
- # Adds support to answering as a 201 when the resource has been just created
6
- module CreatedResponder
7
-
8
- def to_format
9
- if (options[:status] == 201) || (options[:status] == :created)
10
- head :status => 201, :location => controller.url_for(resource)
11
- else
12
- super
13
- end
14
- end
15
-
16
- end
17
- end
18
- end
19
- end