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,6 +1,6 @@
1
1
  class Restfulie::Client::Feature::ThrowError
2
- def execute(flow, request, result_so_far, env)
3
- result = flow.continue(request, result_so_far, env)
2
+ def execute(flow, request, env)
3
+ result = flow.continue(request, env)
4
4
  if result.kind_of? Exception
5
5
  Restfulie::Common::Logger.logger.error(result)
6
6
  raise Restfulie::Client::HTTP::Error::ServerNotAvailableError.new(request, Restfulie::Client::HTTP::Response.new(request.verb, request.path, 503, nil, {}), result )
@@ -0,0 +1,39 @@
1
+ module Restfulie::Client::HTTP
2
+
3
+ # Adds support to extracting and navigating through a link in the representation header.
4
+ module LinkHeader
5
+
6
+ def links
7
+ r = link_header_to_array
8
+ Medie::Xml::Links.new(r)
9
+ end
10
+
11
+ def link(rel)
12
+ links[rel]
13
+ end
14
+
15
+ private
16
+
17
+ def link_header_to_array
18
+ links = self["link"][0].split(",")
19
+ links.map do |link|
20
+ string_to_hash(link)
21
+ end
22
+ end
23
+
24
+ def string_to_hash(l)
25
+ c = l[/<[^>]*/]
26
+ uri = c[1..c.size]
27
+ rest = l[/;.*/]
28
+ rel = extract(rest, "rel")
29
+ type = extract(rest, "type")
30
+ { "href" => uri, "rel" => rel, "type" => type }
31
+ end
32
+
33
+ def extract(from, what)
34
+ found = Regexp.new("#{what}=\"([^\"]*)\"").match(from)
35
+ found ? found[1] : nil
36
+ end
37
+
38
+ end
39
+ end
@@ -4,7 +4,7 @@ module Restfulie::Client::HTTP
4
4
 
5
5
  def resource
6
6
  type = headers['content-type'] || response['Content-Type']
7
- representation = Restfulie::Common::Converter.content_type_for(type[0]) || Restfulie::Common::Representation::Generic.new
7
+ representation = Medie.registry.for(type[0])
8
8
  representation.unmarshal(response.body)
9
9
  end
10
10
 
@@ -13,7 +13,7 @@ module Restfulie::Client::HTTP
13
13
  end
14
14
 
15
15
  def headers
16
- response.to_hash
16
+ response.to_hash.extend(::Restfulie::Client::HTTP::LinkHeader)
17
17
  end
18
18
 
19
19
  def results_from(request, response)
@@ -0,0 +1,39 @@
1
+ module Restfulie
2
+ module Client
3
+ class StackNavigator
4
+
5
+ def initialize(stack)
6
+ @stack = stack.dup
7
+ end
8
+
9
+ def continue(request, env)
10
+ current = @stack.pop
11
+ if current.nil?
12
+ return nil
13
+ end
14
+ filter = instantiator.new(current[:type], current[:args])
15
+ Restfulie::Common::Logger.logger.debug "invoking filter #{filter.class.name} with #{request} at #{env}"
16
+ filter.execute(self.dup, request, env)
17
+ end
18
+
19
+ def instantiator
20
+ BasicInstantiator.new
21
+ end
22
+
23
+ def dup
24
+ StackNavigator.new(@stack)
25
+ end
26
+
27
+ end
28
+
29
+ class BasicInstantiator
30
+ def new(type, args)
31
+ if type.instance_method(:initialize).arity==1
32
+ type.new(args)
33
+ else
34
+ type.new
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,16 +11,14 @@ module Restfulie
11
11
  autoload :Cache, 'restfulie/client/cache'
12
12
  autoload :Feature, 'restfulie/client/feature'
13
13
  autoload :Dsl, 'restfulie/client/dsl'
14
+ autoload :StackNavigator, 'restfulie/client/stack_navigator'
14
15
 
15
16
  mattr_accessor :cache_provider, :cache_store
16
17
 
17
18
  Restfulie::Client.cache_store = ActiveSupport::Cache::MemoryStore.new
18
- Restfulie::Client.cache_provider = Restfulie::Client::Cache::Basic.new
19
+ Restfulie::Client.cache_provider = Restfulie::Client::Cache::Fake.new
19
20
 
20
21
  end
21
22
  end
22
23
 
23
- require 'restfulie/client/ext/http_ext'
24
- require 'restfulie/client/ext/atom_ext'
25
- require 'restfulie/client/ext/json_ext'
26
-
24
+ require 'restfulie/client/ext'
@@ -2,17 +2,16 @@ require 'net/http'
2
2
  require 'uri'
3
3
 
4
4
  require 'rubygems'
5
- require 'active_support'
6
- require 'action_controller'
5
+ require 'tokamak'
6
+ require 'medie'
7
7
 
8
8
  module Restfulie
9
+
10
+ # Code common to both client and server side is contained in the common module.
9
11
  module Common
10
12
  autoload :Error, 'restfulie/common/error'
11
- autoload :Links, 'restfulie/common/links'
12
13
  autoload :Logger, 'restfulie/common/logger'
13
- autoload :Representation, 'restfulie/common/representation'
14
- autoload :Converter, 'restfulie/common/converter'
15
14
  end
15
+
16
16
  end
17
17
 
18
- require 'restfulie/common/core_ext'
@@ -8,7 +8,7 @@ module Restfulie
8
8
  base.responder = Restfulie::Server::ActionController::RestfulResponder
9
9
  base.extend(Restfulie::Server::ActionController::Base::ClassMethods)
10
10
  # Atom representation is added by default
11
- Restfulie::Server::ActionController::ParamsParser.register('application/atom+xml', Restfulie::Common::Converter::Atom)
11
+ Restfulie::Server::ActionController::ParamsParser.register('application/atom+xml', Tokamak::Atom)
12
12
  end
13
13
 
14
14
  module ClassMethods
@@ -1,32 +1,6 @@
1
1
  # Introspective methods to assist in the conversion of collections in other formats.
2
2
  class Array
3
- def to_atom(options={}, &block)
4
- raise "Not all elements respond to to_atom" unless all? { |e| e.respond_to? :to_atom }
5
- options = options.dup
6
-
7
- if options.delete :only_self_link
8
- options[:skip_associations_links] = true
9
- options[:skip_attributes] = true
10
- end
11
-
12
- feed = Restfulie::Common::Representation::Atom::Feed.new
13
- # TODO: Define better feed attributes
14
- # Array#to_s can return a very long string
15
- feed.title = "Collection of #{map {|i| i.class.name }.uniq.to_sentence}"
16
- feed.updated = updated_at
17
- feed.published = published_at
18
- # TODO: this id does not comply with Rest standards yet
19
- feed.id = hash
20
-
21
- each do |element|
22
- feed.entries << element.to_atom(options)
23
- end
24
-
25
- yield feed if block_given?
26
-
27
- feed
28
- end
29
-
3
+
30
4
  # Return max update date for items in collection, for it uses the updated_at of items.
31
5
  #
32
6
  #==Example:
@@ -0,0 +1,6 @@
1
+ if defined? ::ActionView and ::ActionController
2
+ require 'tokamak/hook/rails'
3
+ # TODO autoloading, should be optional
4
+ Tokamak::Builder::Xml
5
+ Tokamak::Builder::Json
6
+ end
@@ -5,21 +5,22 @@ module Restfulie
5
5
  module Server
6
6
  autoload :Configuration, 'restfulie/server/configuration'
7
7
  autoload :ActionController, 'restfulie/server/action_controller'
8
- autoload :ActionView, 'restfulie/server/action_view'
9
8
  autoload :Controller, 'restfulie/server/controller'
10
9
  end
11
10
  end
12
11
 
12
+ require 'restfulie/server/tokamak'
13
13
  require 'restfulie/server/core_ext'
14
- Restfulie::Server::ActionView::TemplateHandlers.activate!
15
14
 
16
- class ActionController::Base
17
- def self.restfulie
18
- include Restfulie::Server::ActionController::Base
19
- end
15
+ if defined? ::ActionController
16
+ class ActionController::Base
17
+ def self.restfulie
18
+ include Restfulie::Server::ActionController::Base
19
+ end
20
20
 
21
- def self.use_trait(&block)
22
- Respondie::Builder.new("Restfulie::Server::ActionController::Trait::$trait$", self).instance_eval(&block)
23
- end
21
+ def self.use_trait(&block)
22
+ Respondie::Builder.new("Restfulie::Server::ActionController::Trait::$trait$", self).instance_eval(&block)
23
+ end
24
24
 
25
- end
25
+ end
26
+ end
@@ -4,7 +4,7 @@ module Restfulie
4
4
  MINOR = 0
5
5
  TINY = 0
6
6
 
7
- STRING = [MAJOR, MINOR, TINY].join('.') + ".beta1"
7
+ STRING = [MAJOR, MINOR, TINY].join('.') + ".beta4"
8
8
 
9
9
  # Restfulie's version
10
10
  def self.to_s
metadata CHANGED
@@ -1,28 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restfulie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 299253597
5
- prerelease: true
4
+ hash: 62196363
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - beta1
11
- version: 1.0.0.beta1
10
+ - beta
11
+ - 4
12
+ version: 1.0.0.beta4
12
13
  platform: ruby
13
14
  authors:
14
- - Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon, Several contributors
15
+ - Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon, and many more!
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-10-31 00:00:00 -02:00
20
+ date: 2011-01-06 00:00:00 -02:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
- name: nokogiri
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ type: :runtime
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
28
  - - ">="
@@ -33,44 +33,12 @@ dependencies:
33
33
  - 4
34
34
  - 2
35
35
  version: 1.4.2
36
- type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: actionpack
36
+ requirement: *id001
40
37
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 7
47
- segments:
48
- - 2
49
- - 3
50
- - 2
51
- version: 2.3.2
52
- type: :runtime
53
- version_requirements: *id002
38
+ name: nokogiri
54
39
  - !ruby/object:Gem::Dependency
55
- name: activesupport
56
- prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 7
63
- segments:
64
- - 2
65
- - 3
66
- - 2
67
- version: 2.3.2
68
40
  type: :runtime
69
- version_requirements: *id003
70
- - !ruby/object:Gem::Dependency
71
- name: json_pure
72
- prerelease: false
73
- requirement: &id004 !ruby/object:Gem::Requirement
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
74
42
  none: false
75
43
  requirements:
76
44
  - - ">="
@@ -81,8 +49,9 @@ dependencies:
81
49
  - 2
82
50
  - 4
83
51
  version: 1.2.4
84
- type: :runtime
85
- version_requirements: *id004
52
+ requirement: *id002
53
+ prerelease: false
54
+ name: json_pure
86
55
  description:
87
56
  email: guilherme.silveira@caelum.com.br
88
57
  executables: []
@@ -101,18 +70,21 @@ files:
101
70
  - lib/restfulie/client/configuration.rb
102
71
  - lib/restfulie/client/dsl.rb
103
72
  - lib/restfulie/client/entry_point.rb
104
- - lib/restfulie/client/ext/atom_ext.rb
105
73
  - lib/restfulie/client/ext/http_ext.rb
106
- - lib/restfulie/client/ext/json_ext.rb
74
+ - lib/restfulie/client/ext/link_ext.rb
75
+ - lib/restfulie/client/ext/open_search_ext.rb
76
+ - lib/restfulie/client/ext.rb
107
77
  - lib/restfulie/client/feature/base.rb
108
78
  - lib/restfulie/client/feature/base_request.rb
109
79
  - lib/restfulie/client/feature/cache.rb
80
+ - lib/restfulie/client/feature/conneg_when_unaccepted.rb
110
81
  - lib/restfulie/client/feature/enhance_response.rb
111
82
  - lib/restfulie/client/feature/follow_request.rb
112
83
  - lib/restfulie/client/feature/history.rb
113
84
  - lib/restfulie/client/feature/history_request.rb
114
85
  - lib/restfulie/client/feature/open_search/pattern_matcher.rb
115
86
  - lib/restfulie/client/feature/open_search.rb
87
+ - lib/restfulie/client/feature/retry_when_unavailable.rb
116
88
  - lib/restfulie/client/feature/serialize_body.rb
117
89
  - lib/restfulie/client/feature/setup_header.rb
118
90
  - lib/restfulie/client/feature/throw_error.rb
@@ -120,6 +92,7 @@ files:
120
92
  - lib/restfulie/client/feature.rb
121
93
  - lib/restfulie/client/http/cache.rb
122
94
  - lib/restfulie/client/http/error.rb
95
+ - lib/restfulie/client/http/link_header.rb
123
96
  - lib/restfulie/client/http/response_holder.rb
124
97
  - lib/restfulie/client/http.rb
125
98
  - lib/restfulie/client/master_delegator.rb
@@ -133,50 +106,10 @@ files:
133
106
  - lib/restfulie/client/mikyung/then_condition.rb
134
107
  - lib/restfulie/client/mikyung/when_condition.rb
135
108
  - lib/restfulie/client/mikyung.rb
109
+ - lib/restfulie/client/stack_navigator.rb
136
110
  - lib/restfulie/client.rb
137
- - lib/restfulie/common/converter/atom/base.rb
138
- - lib/restfulie/common/converter/atom/builder.rb
139
- - lib/restfulie/common/converter/atom/helpers.rb
140
- - lib/restfulie/common/converter/atom.rb
141
- - lib/restfulie/common/converter/form_url_encoded.rb
142
- - lib/restfulie/common/converter/json/base.rb
143
- - lib/restfulie/common/converter/json/builder.rb
144
- - lib/restfulie/common/converter/json/helpers.rb
145
- - lib/restfulie/common/converter/json.rb
146
- - lib/restfulie/common/converter/open_search/descriptor.rb
147
- - lib/restfulie/common/converter/open_search.rb
148
- - lib/restfulie/common/converter/values.rb
149
- - lib/restfulie/common/converter/xml/base.rb
150
- - lib/restfulie/common/converter/xml/builder.rb
151
- - lib/restfulie/common/converter/xml/helpers.rb
152
- - lib/restfulie/common/converter/xml/link.rb
153
- - lib/restfulie/common/converter/xml/links.rb
154
- - lib/restfulie/common/converter/xml.rb
155
- - lib/restfulie/common/converter.rb
156
- - lib/restfulie/common/core_ext/hash.rb
157
- - lib/restfulie/common/core_ext.rb
158
111
  - lib/restfulie/common/error.rb
159
- - lib/restfulie/common/links.rb
160
112
  - lib/restfulie/common/logger.rb
161
- - lib/restfulie/common/representation/atom/base.rb
162
- - lib/restfulie/common/representation/atom/category.rb
163
- - lib/restfulie/common/representation/atom/entry.rb
164
- - lib/restfulie/common/representation/atom/factory.rb
165
- - lib/restfulie/common/representation/atom/feed.rb
166
- - lib/restfulie/common/representation/atom/link.rb
167
- - lib/restfulie/common/representation/atom/person.rb
168
- - lib/restfulie/common/representation/atom/source.rb
169
- - lib/restfulie/common/representation/atom/tag_collection.rb
170
- - lib/restfulie/common/representation/atom/xml.rb
171
- - lib/restfulie/common/representation/atom.rb
172
- - lib/restfulie/common/representation/generic.rb
173
- - lib/restfulie/common/representation/json/base.rb
174
- - lib/restfulie/common/representation/json/keys_as_methods.rb
175
- - lib/restfulie/common/representation/json/link.rb
176
- - lib/restfulie/common/representation/json/link_collection.rb
177
- - lib/restfulie/common/representation/json.rb
178
- - lib/restfulie/common/representation/links.rb
179
- - lib/restfulie/common/representation.rb
180
113
  - lib/restfulie/common.rb
181
114
  - lib/restfulie/server/action_controller/base.rb
182
115
  - lib/restfulie/server/action_controller/params_parser.rb
@@ -187,14 +120,11 @@ files:
187
120
  - lib/restfulie/server/action_controller/trait/save_prior_to_create.rb
188
121
  - lib/restfulie/server/action_controller/trait.rb
189
122
  - lib/restfulie/server/action_controller.rb
190
- - lib/restfulie/server/action_view/helpers.rb
191
- - lib/restfulie/server/action_view/template_handlers/tokamak.rb
192
- - lib/restfulie/server/action_view/template_handlers.rb
193
- - lib/restfulie/server/action_view.rb
194
123
  - lib/restfulie/server/configuration.rb
195
124
  - lib/restfulie/server/controller.rb
196
125
  - lib/restfulie/server/core_ext/array.rb
197
126
  - lib/restfulie/server/core_ext.rb
127
+ - lib/restfulie/server/tokamak.rb
198
128
  - lib/restfulie/server.rb
199
129
  - lib/restfulie/version.rb
200
130
  - lib/restfulie.rb
@@ -203,7 +133,6 @@ files:
203
133
  - LICENSE
204
134
  - Rakefile
205
135
  - README.textile
206
- - lib/restfulie/common/representation/atom/atom.rng
207
136
  has_rdoc: true
208
137
  homepage: http://restfulie.caelumobjects.com
209
138
  licenses: []
@@ -236,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
165
  requirements: []
237
166
 
238
167
  rubyforge_project:
239
- rubygems_version: 1.3.7
168
+ rubygems_version: 1.4.1
240
169
  signing_key:
241
170
  specification_version: 3
242
171
  summary: Hypermedia aware resource based library in ruby (client side) and ruby on rails (server side).
@@ -1,14 +0,0 @@
1
- # Atom links now can be followed
2
- module Restfulie
3
- module Common
4
- module Representation
5
- module Atom
6
- class Link
7
- def follow
8
- Restfulie.at(href).as(type)
9
- end
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,16 +0,0 @@
1
- # inject new behavior in Atom instances to enable easily access to link relationships.
2
- module Restfulie
3
- module Common
4
- module Representation
5
- class Json
6
- class Link
7
- def follow
8
- r = Restfulie.at(href)
9
- r = r.as(type) if type
10
- r
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,91 +0,0 @@
1
- require 'active_support/core_ext/hash/conversions'
2
-
3
- module Restfulie
4
- module Common
5
- module Converter
6
- module Atom
7
- module Base
8
- module ClassMethods
9
- mattr_reader :media_type_name
10
- @@media_type_name = 'application/atom+xml'
11
-
12
- mattr_reader :headers
13
- @@headers = {
14
- :get => { 'Accept' => media_type_name },
15
- :post => { 'Content-Type' => media_type_name }
16
- }
17
-
18
- mattr_reader :recipes
19
- @@recipes = {}
20
-
21
- def helper
22
- Restfulie::Common::Converter::Atom::Helpers
23
- end
24
-
25
- def describe_recipe(recipe_name, options={}, &block)
26
- raise 'Undefined recipe' unless block_given?
27
- raise 'Undefined recipe_name' unless recipe_name
28
- @@recipes[recipe_name] = block
29
- end
30
-
31
- def to_atom(obj = nil, options = {}, &block)
32
- # just instantiate the string with the atom factory
33
- return Restfulie::Common::Representation::Atom::Factory.create(obj) if obj.kind_of?(String)
34
-
35
- if block_given?
36
- recipe = block
37
- elsif options[:recipe]
38
- recipe = @@recipes[options[:recipe]]
39
- else
40
- return obj if obj.respond_to?(:atom_type) && (obj.atom_type == "feed" || obj.atom_type == "entry")
41
- raise Restfulie::Common::Error::ConverterError.new("Recipe required")
42
- end
43
-
44
- # execute with the builder if a recipe is set (even if the obj is an atom)
45
- options[:atom_type] ||= obj.respond_to?(:each) ? :feed : :entry
46
- raise Restfulie::Common::Error::ConverterError.new("Undefined atom type #{options[:atom_type]}") unless [:entry,:feed].include?(options[:atom_type])
47
-
48
- # Create representation and proxy
49
- builder = Builder.new(options[:atom_type], obj)
50
-
51
- # Check recipe arity size before calling it
52
- recipe.call(*[builder, obj, options][0,recipe.arity])
53
-
54
- builder.representation
55
- end
56
-
57
- alias_method :unmarshal, :to_atom
58
-
59
- def to_hash(obj)
60
- return obj if obj.kind_of?(Hash)
61
-
62
- xml = nil
63
-
64
- if obj.kind_of?(::String)
65
- xml = obj
66
- elsif obj.respond_to?(:to_xml)
67
- xml = obj.to_xml
68
- end
69
-
70
- Hash.from_xml(xml).with_indifferent_access unless xml.nil?
71
- end
72
-
73
-
74
- def to_s(obj)
75
- return obj if obj.kind_of?(String)
76
- if obj.respond_to?(:to_xml)
77
- obj.to_xml.to_s
78
- else
79
- obj.to_s
80
- end
81
- end
82
-
83
- def marshal(obj, options = nil)
84
- to_atom(obj, options).to_xml
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end