restfulie 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/Gemfile +21 -0
  2. data/README.textile +10 -9
  3. data/Rakefile +12 -5
  4. data/lib/restfulie/client/base.rb +10 -6
  5. data/lib/restfulie/client/http/adapter.rb +48 -33
  6. data/lib/restfulie/client/http/atom_ext.rb +3 -68
  7. data/lib/restfulie/client/http/core_ext/http.rb +19 -0
  8. data/lib/restfulie/client/http/core_ext.rb +6 -0
  9. data/lib/restfulie/client/http/error.rb +3 -6
  10. data/lib/restfulie/client/http/marshal.rb +35 -49
  11. data/lib/restfulie/client/http/xml_ext.rb +7 -0
  12. data/lib/restfulie/client/http.rb +2 -2
  13. data/lib/restfulie/client/mikyung/concatenator.rb +15 -0
  14. data/lib/restfulie/client/mikyung/core.rb +44 -0
  15. data/lib/restfulie/client/mikyung/languages.rb +29 -0
  16. data/lib/restfulie/client/mikyung/rest_process_model.rb +114 -0
  17. data/lib/restfulie/client/mikyung/steady_state_walker.rb +32 -0
  18. data/lib/restfulie/client/mikyung/then_condition.rb +33 -0
  19. data/lib/restfulie/client/mikyung/when_condition.rb +53 -0
  20. data/lib/restfulie/client/mikyung.rb +19 -0
  21. data/lib/restfulie/client.rb +1 -0
  22. data/lib/restfulie/common/converter/atom/builder.rb +109 -0
  23. data/lib/restfulie/common/converter/atom/helpers.rb +9 -0
  24. data/lib/restfulie/common/converter/atom.rb +87 -0
  25. data/lib/restfulie/common/converter/values.rb +29 -0
  26. data/lib/restfulie/common/converter.rb +11 -0
  27. data/lib/restfulie/common/core_ext/proc.rb +48 -0
  28. data/lib/restfulie/common/core_ext.rb +5 -0
  29. data/lib/restfulie/common/errors.rb +6 -0
  30. data/lib/restfulie/common/representation/atom/atom.rng +597 -0
  31. data/lib/restfulie/common/representation/atom/base.rb +375 -0
  32. data/lib/restfulie/common/representation/atom/entry.rb +107 -0
  33. data/lib/restfulie/common/representation/atom/feed.rb +106 -0
  34. data/lib/restfulie/common/representation/atom.rb +43 -33
  35. data/lib/restfulie/common/representation/json.rb +1 -2
  36. data/lib/restfulie/common/representation/xml.rb +209 -23
  37. data/lib/restfulie/common/representation.rb +0 -1
  38. data/lib/restfulie/common.rb +2 -3
  39. data/lib/restfulie/server/action_controller/base.rb +21 -2
  40. data/lib/restfulie/server/action_controller/params_parser.rb +16 -16
  41. data/lib/restfulie/server/action_controller/restful_responder.rb +3 -3
  42. data/lib/restfulie/server/action_controller/routing/patch.rb +6 -0
  43. data/lib/restfulie/server/action_view/helpers.rb +8 -8
  44. data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +3 -2
  45. data/lib/restfulie/server/core_ext/array.rb +13 -12
  46. metadata +51 -34
  47. data/lib/restfulie/client/http/link.rb +0 -39
  48. data/lib/restfulie/client/http/xml.rb +0 -4
  49. data/lib/restfulie/common/builder/builder_base.rb +0 -73
  50. data/lib/restfulie/common/builder/helpers.rb +0 -22
  51. data/lib/restfulie/common/builder/marshalling/atom.rb +0 -197
  52. data/lib/restfulie/common/builder/marshalling/base.rb +0 -12
  53. data/lib/restfulie/common/builder/marshalling/json.rb +0 -2
  54. data/lib/restfulie/common/builder/marshalling/xml.rb +0 -183
  55. data/lib/restfulie/common/builder/marshalling.rb +0 -16
  56. data/lib/restfulie/common/builder/rules/collection_rule.rb +0 -10
  57. data/lib/restfulie/common/builder/rules/custom_attributes.rb +0 -24
  58. data/lib/restfulie/common/builder/rules/link.rb +0 -20
  59. data/lib/restfulie/common/builder/rules/links.rb +0 -9
  60. data/lib/restfulie/common/builder/rules/member_rule.rb +0 -8
  61. data/lib/restfulie/common/builder/rules/namespace.rb +0 -35
  62. data/lib/restfulie/common/builder/rules/rules_base.rb +0 -77
  63. data/lib/restfulie/common/builder.rb +0 -17
  64. data/lib/vendor/atom/configuration.rb +0 -24
  65. data/lib/vendor/atom/pub.rb +0 -250
  66. data/lib/vendor/atom/xml/parser.rb +0 -373
  67. data/lib/vendor/atom.rb +0 -771
@@ -1,77 +0,0 @@
1
- module Restfulie::Common::Builder::Rules; end
2
-
3
- # Set of rules that can be used to describe a resource in a tokamak view.
4
- class Restfulie::Common::Builder::Rules::Base
5
- attr_accessor :blocks
6
- attr_accessor :links
7
- attr_reader :namespaces
8
-
9
- def initialize(blocks = [], &block)
10
- @links = Restfulie::Common::Builder::Rules::Links.new
11
- @blocks = (block_given? ? [block] : []) + blocks
12
- @namespaces = []
13
- end
14
-
15
- def apply(*args)
16
- @blocks.each do |block|
17
- params = ([self] + args)[0..block.arity-1]
18
- block.call(*params)
19
- end
20
- end
21
-
22
- # Use to register a namespace
23
- #
24
- #==Example:
25
- #
26
- # namespace(@album , "http://example.com")
27
- # namespace(:albums, "http://example.com")
28
- # namespace(:albums, "http://example.com", :eager_load => false)
29
- # namespace(:albums, "http://example.com", :eager_load => { :title => 'A title' })
30
- #
31
- def namespace(ns, uri = nil, options = {}, &block)
32
- object = nil
33
-
34
- if !ns.kind_of?(String) && !ns.kind_of?(Symbol)
35
- object = ns
36
- ns = object.class.to_s.demodulize.downcase.pluralize.to_sym
37
- options[:eager_load] = true unless options.key?(:eager_load)
38
- end
39
-
40
- unless [true, false, nil].include?(options[:eager_load])
41
- object = options[:eager_load]
42
- options[:eager_load] = true
43
- end
44
-
45
- namespace = find_or_new_namespace(ns, uri)
46
- eager_load(object, namespace) if options[:eager_load]
47
-
48
- yield(namespace) if block_given?
49
- namespace
50
- end
51
-
52
- def metaclass
53
- (class << self; self; end)
54
- end
55
-
56
- private
57
- # Load attributes of the object to passed hash.
58
- # If object respond to attributes, attributes is merge, unless merge instance variables
59
- def eager_load(object, ns)
60
- if object.kind_of?(Hash)
61
- ns.merge!(object.symbolize_keys)
62
- elsif object.respond_to?(:attributes)
63
- ns.merge!(object.attributes.symbolize_keys)
64
- else
65
- object.instance_variables.each do |var|
66
- ns[var.gsub(/^@/, '').to_sym] = object.instance_variable_get(var)
67
- end
68
- end
69
- end
70
-
71
- # Search a namespace or create a new
72
- def find_or_new_namespace(name, uri)
73
- namespace = @namespaces.find { |n| n.namespace == name } || (@namespaces << Restfulie::Common::Builder::Rules::Namespace.new(name, uri)).last
74
- namespace.uri = uri unless uri.nil?
75
- namespace
76
- end
77
- end
@@ -1,17 +0,0 @@
1
- #initialize namespace
2
- module Restfulie::Common::Builder; end
3
-
4
- %w(
5
- helpers
6
- builder_base
7
- marshalling
8
- rules/rules_base
9
- rules/link
10
- rules/links
11
- rules/namespace
12
- rules/member_rule
13
- rules/collection_rule
14
- rules/custom_attributes
15
- ).each do |file|
16
- require File.join(File.dirname(__FILE__), 'builder', file)
17
- end
@@ -1,24 +0,0 @@
1
- # Copyright (c) 2008 The Kaphan Foundation
2
- #
3
- # For licensing information see LICENSE.txt.
4
- #
5
- # Please visit http://www.peerworks.org/contact for further information.
6
- #
7
-
8
- module Atom
9
- class Configuration
10
- def self.auth_hmac_enabled?
11
- unless defined?(@auth_hmac_enabled)
12
- begin
13
- gem 'auth-hmac'
14
- require 'auth-hmac'
15
- @auth_hmac_enabled = true
16
- rescue
17
- @auth_hmac_enabled = false
18
- end
19
- else
20
- @auth_hmac_enabled
21
- end
22
- end
23
- end
24
- end
@@ -1,250 +0,0 @@
1
- # Copyright (c) 2008 The Kaphan Foundation
2
- #
3
- # For licensing information see LICENSE.txt.
4
- #
5
- # Please visit http://www.peerworks.org/contact for further information.
6
- #
7
-
8
- require 'vendor/atom'
9
- require 'vendor/atom/configuration'
10
- require 'vendor/atom/xml/parser'
11
- require 'vendor/atom/version'
12
- require 'xml/libxml'
13
- require 'uri'
14
- require 'net/http'
15
-
16
- module Atom
17
- module Pub
18
- class NotSupported < StandardError; end
19
- class ProtocolError < StandardError
20
- attr_reader :response
21
- def initialize(response)
22
- @response = response
23
- end
24
-
25
- def to_s
26
- "Invalid response: #{@response}"
27
- end
28
- end
29
-
30
- class Service
31
- include Atom::Xml::Parseable
32
- namespace Atom::Pub::NAMESPACE
33
- elements :workspaces
34
- loadable! do |reader, message, severity, base, line|
35
- if severity == XML::Reader::SEVERITY_ERROR
36
- raise ArgumentError, "#{message} at #{line}"
37
- end
38
- end
39
-
40
- def initialize(xml = nil)
41
- @workspaces = []
42
-
43
- if xml
44
- begin
45
- if next_node_is?(xml, 'service', Atom::Pub::NAMESPACE)
46
- xml.read
47
- parse(xml)
48
- else
49
- raise ArgumentError, "XML document was missing atom:service"
50
- end
51
- ensure
52
- xml.close
53
- end
54
- end
55
-
56
- yield(self) if block_given?
57
- end
58
- end
59
-
60
- class Categories < DelegateClass(Array)
61
- include Atom::Xml::Parseable
62
- elements :categories, :class => Atom::Category
63
- attribute :href, :fixed
64
-
65
- def initialize(o)
66
- super([])
67
- parse(o, :once => true)
68
- o.read
69
- parse(o)
70
- end
71
-
72
- remove_method :categories
73
- def categories; self; end
74
-
75
- # True true if fixed was 'yes' or 'true'
76
- def fixed?
77
- !self.fixed.nil? && %w(yes true).include?(self.fixed.downcase)
78
- end
79
- end
80
-
81
- class Workspace
82
- include Atom::Xml::Parseable
83
- element :title, :class => Content, :namespace => Atom::NAMESPACE
84
- elements :collections
85
-
86
- def initialize(o = nil)
87
- @collections = []
88
-
89
- case o
90
- when XML::Reader
91
- o.read
92
- parse(o)
93
- when Hash
94
- o.each do |k, v|
95
- self.send("#{k}=".to_sym, v)
96
- end
97
- end
98
-
99
- yield(self) if block_given?
100
- end
101
- end
102
-
103
- class Collection
104
- include Atom::Xml::Parseable
105
- attribute :href
106
- element :title, :class => Content, :namespace => Atom::NAMESPACE
107
- element :categories, :class => Categories
108
- elements :accepts, :content_only => true
109
-
110
- def initialize(o = nil)
111
- @accepts = []
112
- case o
113
- when XML::Reader
114
- # do it once to get the attributes
115
- parse(o, :once => true)
116
- # now step into the element and the sub tree
117
- o.read
118
- parse(o)
119
- when Hash
120
- o.each do |k, v|
121
- self.send("#{k}=", v)
122
- end
123
- end
124
-
125
- yield(self) if block_given?
126
- end
127
-
128
- def feed(opts = {})
129
- if href
130
- Atom::Feed.load_feed(URI.parse(href), opts)
131
- end
132
- end
133
-
134
- def publish(entry, opts = {})
135
- uri = URI.parse(href)
136
- response = nil
137
- Net::HTTP.start(uri.host, uri.port) do |http|
138
- request = Net::HTTP::Post.new(uri.request_uri, headers)
139
- if opts[:user] && opts[:pass]
140
- request.basic_auth(opts[:user], opts[:pass])
141
- elsif opts[:hmac_access_id] && opts[:hmac_secret_key]
142
- if Atom::Configuration.auth_hmac_enabled?
143
- AuthHMAC.sign!(request, opts[:hmac_access_id], opts[:hmac_secret_key])
144
- else
145
- raise ArgumentError, "AuthHMAC credentials provides by auth-hmac gem is not installed"
146
- end
147
- end
148
- response = http.request(request, entry.to_xml.to_s)
149
- end
150
-
151
- case response
152
- when Net::HTTPCreated
153
- published = begin
154
- Atom::Entry.load_entry(response.body)
155
- rescue ArgumentError
156
- entry
157
- end
158
-
159
- if response['Location']
160
- if published.edit_link
161
- published.edit_link.href = response['Location']
162
- else
163
- published.links << Atom::Link.new(:rel => 'edit', :href => response['Location'])
164
- end
165
- end
166
-
167
- published
168
- else
169
- raise Atom::Pub::ProtocolError, response
170
- end
171
- end
172
-
173
- private
174
- def headers
175
- {'Accept' => 'application/atom+xml',
176
- 'Content-Type' => 'application/atom+xml;type=entry',
177
- 'User-Agent' => "rAtom #{Atom::VERSION::STRING}"
178
- }
179
- end
180
- end
181
- end
182
-
183
- class Entry
184
- def save!(opts = {})
185
- if edit = edit_link
186
- uri = URI.parse(edit.href)
187
- response = nil
188
- Net::HTTP.start(uri.host, uri.port) do |http|
189
- request = Net::HTTP::Put.new(uri.request_uri, headers)
190
- if opts[:user] && opts[:pass]
191
- request.basic_auth(opts[:user], opts[:pass])
192
- elsif opts[:hmac_access_id] && opts[:hmac_secret_key]
193
- if Atom::Configuration.auth_hmac_enabled?
194
- AuthHMAC.sign!(request, opts[:hmac_access_id], opts[:hmac_secret_key])
195
- else
196
- raise ArgumentError, "AuthHMAC credentials provides by auth-hmac gem is not installed"
197
- end
198
- end
199
-
200
- response = http.request(request, self.to_xml)
201
- end
202
-
203
- case response
204
- when Net::HTTPSuccess
205
- else
206
- raise Atom::Pub::ProtocolError, response
207
- end
208
- else
209
- raise Atom::Pub::NotSupported, "Entry does not have an edit link"
210
- end
211
- end
212
-
213
- def destroy!(opts = {})
214
- if edit = edit_link
215
- uri = URI.parse(edit.href)
216
- response = nil
217
- Net::HTTP.start(uri.host, uri.port) do |http|
218
- request = Net::HTTP::Delete.new(uri.request_uri, {'Accept' => 'application/atom+xml', 'User-Agent' => "rAtom #{Atom::VERSION::STRING}"})
219
- if opts[:user] && opts[:pass]
220
- request.basic_auth(opts[:user], opts[:pass])
221
- elsif opts[:hmac_access_id] && opts[:hmac_secret_key]
222
- if Atom::Configuration.auth_hmac_enabled?
223
- AuthHMAC.sign!(request, opts[:hmac_access_id], opts[:hmac_secret_key])
224
- else
225
- raise ArgumentError, "AuthHMAC credentials provides by auth-hmac gem is not installed"
226
- end
227
- end
228
-
229
- response = http.request(request)
230
- end
231
-
232
- case response
233
- when Net::HTTPSuccess
234
- else
235
- raise Atom::Pub::ProtocolError, response
236
- end
237
- else
238
- raise Atom::Pub::NotSupported, "Entry does not have an edit link"
239
- end
240
- end
241
-
242
- private
243
- def headers
244
- {'Accept' => 'application/atom+xml',
245
- 'Content-Type' => 'application/atom+xml;type=entry',
246
- 'User-Agent' => "rAtom #{Atom::VERSION::STRING}"
247
- }
248
- end
249
- end
250
- end