restfulie 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/Gemfile +10 -5
  2. data/Rakefile +5 -2
  3. data/lib/restfulie.rb +10 -5
  4. data/lib/restfulie/client.rb +13 -9
  5. data/lib/restfulie/client/base.rb +24 -65
  6. data/lib/restfulie/client/configuration.rb +62 -64
  7. data/lib/restfulie/client/entry_point.rb +36 -0
  8. data/lib/restfulie/client/ext/atom_ext.rb +12 -0
  9. data/lib/restfulie/client/ext/http_ext.rb +22 -0
  10. data/lib/restfulie/client/ext/json_ext.rb +12 -0
  11. data/lib/restfulie/client/ext/xml_ext.rb +4 -0
  12. data/lib/restfulie/client/http.rb +25 -13
  13. data/lib/restfulie/client/http/cache.rb +22 -22
  14. data/lib/restfulie/client/http/error.rb +70 -70
  15. data/lib/restfulie/client/http/link_request_builder.rb +15 -0
  16. data/lib/restfulie/client/http/request_adapter.rb +209 -0
  17. data/lib/restfulie/client/http/request_builder.rb +107 -0
  18. data/lib/restfulie/client/http/request_builder_executor.rb +24 -0
  19. data/lib/restfulie/client/http/request_executor.rb +17 -0
  20. data/lib/restfulie/client/http/request_follow.rb +42 -0
  21. data/lib/restfulie/client/http/request_follow_executor.rb +10 -0
  22. data/lib/restfulie/client/http/request_history.rb +69 -0
  23. data/lib/restfulie/client/http/request_history_executor.rb +10 -0
  24. data/lib/restfulie/client/http/request_marshaller.rb +127 -0
  25. data/lib/restfulie/client/http/request_marshaller_executor.rb +10 -0
  26. data/lib/restfulie/client/http/response.rb +23 -0
  27. data/lib/restfulie/client/http/response_handler.rb +67 -0
  28. data/lib/restfulie/client/http/response_holder.rb +9 -0
  29. data/lib/restfulie/client/mikyung.rb +17 -14
  30. data/lib/restfulie/client/mikyung/concatenator.rb +15 -12
  31. data/lib/restfulie/client/mikyung/core.rb +65 -39
  32. data/lib/restfulie/client/mikyung/languages.rb +8 -26
  33. data/lib/restfulie/client/mikyung/languages/german.rb +24 -0
  34. data/lib/restfulie/client/mikyung/languages/portuguese.rb +23 -0
  35. data/lib/restfulie/client/mikyung/rest_process_model.rb +184 -107
  36. data/lib/restfulie/client/mikyung/steady_state_walker.rb +34 -28
  37. data/lib/restfulie/client/mikyung/then_condition.rb +33 -27
  38. data/lib/restfulie/client/mikyung/when_condition.rb +53 -49
  39. data/lib/restfulie/common.rb +7 -12
  40. data/lib/restfulie/common/converter.rb +20 -9
  41. data/lib/restfulie/common/converter/atom.rb +8 -83
  42. data/lib/restfulie/common/converter/atom/base.rb +89 -0
  43. data/lib/restfulie/common/converter/atom/builder.rb +101 -99
  44. data/lib/restfulie/common/converter/atom/helpers.rb +16 -8
  45. data/lib/restfulie/common/converter/json.rb +12 -0
  46. data/lib/restfulie/common/converter/json/base.rb +84 -0
  47. data/lib/restfulie/common/converter/json/builder.rb +102 -0
  48. data/lib/restfulie/common/converter/json/helpers.rb +17 -0
  49. data/lib/restfulie/common/converter/values.rb +30 -26
  50. data/lib/restfulie/common/converter/xml.rb +14 -0
  51. data/lib/restfulie/common/converter/xml/base.rb +61 -0
  52. data/lib/restfulie/common/converter/xml/builder.rb +112 -0
  53. data/lib/restfulie/common/converter/xml/helpers.rb +17 -0
  54. data/lib/restfulie/common/converter/xml/link.rb +25 -0
  55. data/lib/restfulie/common/converter/xml/links.rb +25 -0
  56. data/lib/restfulie/common/core_ext.rb +1 -5
  57. data/lib/restfulie/common/core_ext/hash.rb +12 -0
  58. data/lib/restfulie/common/error.rb +19 -0
  59. data/lib/restfulie/common/logger.rb +17 -9
  60. data/lib/restfulie/common/representation.rb +9 -10
  61. data/lib/restfulie/common/representation/atom.rb +15 -47
  62. data/lib/restfulie/common/representation/atom/base.rb +122 -365
  63. data/lib/restfulie/common/representation/atom/category.rb +41 -0
  64. data/lib/restfulie/common/representation/atom/entry.rb +52 -100
  65. data/lib/restfulie/common/representation/atom/factory.rb +43 -0
  66. data/lib/restfulie/common/representation/atom/feed.rb +103 -99
  67. data/lib/restfulie/common/representation/atom/link.rb +68 -0
  68. data/lib/restfulie/common/representation/atom/person.rb +48 -0
  69. data/lib/restfulie/common/representation/atom/source.rb +59 -0
  70. data/lib/restfulie/common/representation/atom/tag_collection.rb +38 -0
  71. data/lib/restfulie/common/representation/atom/xml.rb +95 -0
  72. data/lib/restfulie/common/representation/generic.rb +30 -29
  73. data/lib/restfulie/common/representation/json.rb +10 -22
  74. data/lib/restfulie/common/representation/json/base.rb +27 -0
  75. data/lib/restfulie/common/representation/json/keys_as_methods.rb +72 -0
  76. data/lib/restfulie/common/representation/json/link.rb +29 -0
  77. data/lib/restfulie/common/representation/json/link_collection.rb +23 -0
  78. data/lib/restfulie/common/representation/xml.rb +18 -227
  79. data/lib/restfulie/server.rb +9 -10
  80. data/lib/restfulie/server/action_controller.rb +10 -12
  81. data/lib/restfulie/server/action_controller/base.rb +18 -15
  82. data/lib/restfulie/server/action_controller/{routing/patch.rb → patch.rb} +0 -0
  83. data/lib/restfulie/server/action_controller/restful_responder.rb +43 -35
  84. data/lib/restfulie/server/action_view.rb +8 -6
  85. data/lib/restfulie/server/action_view/helpers.rb +47 -41
  86. data/lib/restfulie/server/action_view/template_handlers.rb +24 -12
  87. data/lib/restfulie/server/action_view/template_handlers/tokamak.rb +17 -12
  88. data/lib/restfulie/server/configuration.rb +22 -19
  89. data/lib/restfulie/server/{restfulie_controller.rb → controller.rb} +1 -10
  90. data/lib/restfulie/server/core_ext.rb +1 -1
  91. data/lib/restfulie/version.rb +14 -0
  92. metadata +52 -16
  93. data/lib/restfulie/client/http/adapter.rb +0 -502
  94. data/lib/restfulie/client/http/atom_ext.rb +0 -4
  95. data/lib/restfulie/client/http/core_ext.rb +0 -6
  96. data/lib/restfulie/client/http/core_ext/http.rb +0 -19
  97. data/lib/restfulie/client/http/marshal.rb +0 -145
  98. data/lib/restfulie/client/http/xml_ext.rb +0 -7
  99. data/lib/restfulie/common/core_ext/proc.rb +0 -48
  100. data/lib/restfulie/common/errors.rb +0 -15
  101. data/lib/restfulie/server/action_controller/routing.rb +0 -12
  102. data/lib/restfulie/server/action_controller/routing/restful_route.rb +0 -14
data/Gemfile CHANGED
@@ -4,18 +4,23 @@ source :gemcutter
4
4
  gem "rails"
5
5
  gem "libxml-ruby"
6
6
 
7
-
8
7
  gem "rack-conneg"
9
8
  gem "responders_backport"
10
9
  gem "json_pure"
11
10
  gem "sqlite3-ruby"
12
11
  gem "yard"
13
- gem "ruby-debug"
12
+
13
+ if RUBY_VERSION < "1.9"
14
+ gem "ruby-debug"
15
+ else
16
+ gem "ruby-debug19", :require => "ruby-debug"
17
+ end
14
18
 
15
19
  group :test do
16
- gem "nokogiri"
20
+ gem "nokogiri"
17
21
  gem "rspec-rails"
18
22
  gem "rcov"
19
23
  gem "sinatra"
20
- end
21
-
24
+ gem "state_machine"
25
+ gem "test-unit", "= 1.2.3"
26
+ end
data/Rakefile CHANGED
@@ -1,14 +1,17 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'rubygems'
2
4
  require 'rubygems/specification'
3
5
  require 'rake'
4
6
  require 'rake/gempackagetask'
5
7
  require 'spec/rake/spectask'
6
8
  require 'rake/rdoctask'
9
+ require File.expand_path('lib/restfulie')
7
10
 
8
11
  GEM = "restfulie"
9
- GEM_VERSION = "0.8.0"
12
+ GEM_VERSION = Restfulie::VERSION
10
13
  SUMMARY = "Hypermedia aware resource based library in ruby (client side) and ruby on rails (server side)."
11
- AUTHOR = "Guilherme Silveira, Caue Guerra, Luis Cipriani, Éverton Ribeiro, George Guimarães, Paulo Ahagon"
14
+ AUTHOR = "Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon"
12
15
  EMAIL = "guilherme.silveira@caelum.com.br"
13
16
  HOMEPAGE = "http://restfulie.caelumobjects.com"
14
17
 
data/lib/restfulie.rb CHANGED
@@ -1,9 +1,14 @@
1
- module Restfulie
2
- ROOT_PATH = File.dirname(__FILE__)
3
- $LOAD_PATH.unshift(ROOT_PATH) unless $LOAD_PATH.include?(ROOT_PATH)
4
-
5
- end
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
6
2
 
3
+ require 'restfulie/version'
7
4
  require 'restfulie/client'
8
5
  require 'restfulie/server'
9
6
 
7
+ # Shortcut to Restfulie::Client::EntryPoint
8
+ module Restfulie
9
+ extend Restfulie::Client::EntryPoint
10
+
11
+ def self.at(uri)
12
+ Object.new.send(:extend, Restfulie::Client::EntryPoint).at(uri)
13
+ end
14
+ end
@@ -1,13 +1,17 @@
1
1
  require 'restfulie/common'
2
2
 
3
- module Restfulie::Client; end
4
-
5
- %w(
6
- http
7
- configuration
8
- base
9
- mikyung
10
- ).each do |file|
11
- require "restfulie/client/#{file}"
3
+ module Restfulie
4
+ module Client
5
+ autoload :HTTP, 'restfulie/client/http'
6
+ autoload :Configuration, 'restfulie/client/configuration'
7
+ autoload :EntryPoint, 'restfulie/client/entry_point'
8
+ autoload :Base, 'restfulie/client/base'
9
+ autoload :Mikyung, 'restfulie/client/mikyung'
10
+ end
12
11
  end
13
12
 
13
+ require 'restfulie/client/ext/http_ext'
14
+ require 'restfulie/client/ext/atom_ext'
15
+ require 'restfulie/client/ext/json_ext'
16
+ require 'restfulie/client/ext/xml_ext'
17
+
@@ -1,70 +1,29 @@
1
- module Restfulie::Client#:nodoc
2
-
3
- module EntryPoint
4
- include HTTP::RequestMarshaller
5
- extend self
6
-
7
- def recipe(converter_sym, options={}, &block)
8
- raise 'Undefined block' unless block_given?
9
- converter = "Restfulie::Common::Converter::#{converter_sym.to_s.camelize}".constantize
10
- converter.describe_recipe(options[:name], &block)
11
- end
12
-
13
- @resources_configurations = {}
14
- def configuration_of(resource_name)
15
- @resources_configurations[resource_name]
16
- end
17
-
18
- def configuration_for(resource_name,configuration = Configuration.new)
19
- yield configuration if block_given?
20
- @resources_configurations[resource_name] = configuration
21
- end
22
-
23
- def retrieve(resource_name)
24
- returning Object.new do |resource|
25
- resource.extend(Base)
26
- resource.configure
1
+ module Restfulie
2
+ module Client#:nodoc
3
+ module Base
4
+ include HTTP::RequestMarshaller
5
+
6
+ def self.included(base)#:nodoc
7
+ base.extend(self)
27
8
  end
28
- end
29
-
30
- end
31
-
32
- module Base
33
- include HTTP::RequestMarshaller
34
-
35
- def self.included(base)#:nodoc
36
- base.extend(self)
37
- end
38
-
39
- def uses_restfulie(configuration = Configuration.new,&block)
40
- EntryPoint.configuration_for(resource_name,configuration,&block)
41
- configure
42
- end
43
-
44
- def configure
45
- configuration = EntryPoint.configuration_of(resource_name)
46
- raise "Undefined configuration for #{resource_name}" unless configuration
47
- at(configuration.entry_point)
48
- configuration.representations.each do |representation_name,representation|
49
- register_representation(representation_name,representation)
9
+
10
+ def uses_restfulie(configuration = Configuration.new,&block)
11
+ EntryPoint.configuration_for(resource_name,configuration,&block)
12
+ configure
50
13
  end
51
- end
52
-
53
- def resource_name
54
- @resource_name || @resource_name = self.class.to_s.to_sym
55
- end
56
-
57
- end
58
-
59
- end
60
-
61
-
62
- # Shortcut to Restfulie::Client::EntryPoint
63
- module Restfulie
64
- extend Restfulie::Client::EntryPoint
65
14
 
66
- def self.at(uri)
67
- Object.new.send(:extend, Restfulie::Client::EntryPoint).at(uri)
15
+ def configure
16
+ configuration = EntryPoint.configuration_of(resource_name)
17
+ raise "Undefined configuration for #{resource_name}" unless configuration
18
+ at(configuration.entry_point)
19
+ configuration.representations.each do |representation_name,representation|
20
+ register_representation(representation_name,representation)
21
+ end
22
+ end
23
+
24
+ def resource_name
25
+ @resource_name ||= self.class.to_s.to_sym
26
+ end
27
+ end
68
28
  end
69
29
  end
70
-
@@ -1,69 +1,67 @@
1
- module Restfulie::Client #:nodoc:
2
-
3
- # Use this class to configure the entry point and other relevant behaviors related to accessing or interacting with resources
4
- #
5
- # The available options are:
6
- #
7
- # * <tt>:entry_point</tt> - The URI for an entry point, such as http://resource.entrypoint.com/post
8
- # * <tt>:representations</tt> - Representations.
9
- #
10
- # You can also store any other custom configuration.
11
- #
12
- # ==== Example
13
- #
14
- # configuration = Configuration.new
15
- # configuration[:entry_point] = 'http://resource.entrypoint.com/post'
16
- # configuration[:entry_point] # => 'http://resource.entrypoint.com/post'
17
- #
18
- # or you can use:
19
- #
20
- # configuration.entry_point = 'http://resource.entrypoint.com/post'
21
- # configuration.entry_point # => 'http://resource.entrypoint.com/post'
22
- class Configuration < ::Hash
23
-
24
- # the current environment
25
- attr_reader :environment
26
-
27
- @@default_configuration = {
28
- :entry_point => '',
29
- :representations => {}
30
- }
31
-
32
- def initialize
33
- super
34
- self.environment = :development
35
- end
36
-
37
- # this will store a new configuration (based on the default) for the environment passed by value.
38
- def environment=(value)
39
- @environment = value
40
- unless has_key?(@environment)
41
- dee_clone = Marshal::load(Marshal::dump(@@default_configuration))
42
- store(@environment,dee_clone)
1
+ module Restfulie
2
+ module Client #:nodoc:
3
+ # Use this class to configure the entry point and other relevant behaviors related to accessing or interacting with resources
4
+ #
5
+ # The available options are:
6
+ #
7
+ # * <tt>:entry_point</tt> - The URI for an entry point, such as http://resource.entrypoint.com/post
8
+ # * <tt>:representations</tt> - Representations.
9
+ #
10
+ # You can also store any other custom configuration.
11
+ #
12
+ # ==== Example
13
+ #
14
+ # configuration = Configuration.new
15
+ # configuration[:entry_point] = 'http://resource.entrypoint.com/post'
16
+ # configuration[:entry_point] # => 'http://resource.entrypoint.com/post'
17
+ #
18
+ # or you can use:
19
+ #
20
+ # configuration.entry_point = 'http://resource.entrypoint.com/post'
21
+ # configuration.entry_point # => 'http://resource.entrypoint.com/post'
22
+ class Configuration < ::Hash
23
+ # the current environment
24
+ attr_reader :environment
25
+
26
+ @@default_configuration = {
27
+ :entry_point => '',
28
+ :representations => {}
29
+ }
30
+
31
+ def initialize
32
+ super
33
+ self.environment = :development
43
34
  end
44
- @environment
45
- end
46
-
47
- # access (key) configuration value
48
- def [](key)
49
- fetch(@environment)[key]
50
- end
51
-
52
- # store on (key) configuration the value
53
- def []=(key,value)
54
- fetch(@environment)[key] = value
55
- end
56
-
57
- def method_missing(name, *args, &block)
58
- method_name = name.to_s
59
- if method_name.last == '='
60
- fetch(environment)[method_name.chop.to_sym] = args[0]
61
- else
62
- value = fetch(environment)[name]
63
- value ? value : super
35
+
36
+ # this will store a new configuration (based on the default) for the environment passed by value.
37
+ def environment=(value)
38
+ @environment = value
39
+ unless has_key?(@environment)
40
+ dee_clone = Marshal::load(Marshal::dump(@@default_configuration))
41
+ store(@environment,dee_clone)
42
+ end
43
+ @environment
44
+ end
45
+
46
+ # access (key) configuration value
47
+ def [](key)
48
+ fetch(@environment)[key]
49
+ end
50
+
51
+ # store on (key) configuration the value
52
+ def []=(key,value)
53
+ fetch(@environment)[key] = value
54
+ end
55
+
56
+ def method_missing(name, *args, &block)
57
+ method_name = name.to_s
58
+ if method_name.last == '='
59
+ fetch(environment)[method_name.chop.to_sym] = args[0]
60
+ else
61
+ value = fetch(environment)[name]
62
+ value ? value : super
63
+ end
64
64
  end
65
65
  end
66
-
67
66
  end
68
-
69
67
  end
@@ -0,0 +1,36 @@
1
+ module Restfulie
2
+ module Client#:nodoc
3
+ module EntryPoint
4
+ include HTTP::RequestMarshaller
5
+ include HTTP::RequestFollow
6
+ extend self
7
+
8
+ def self.at(uri)
9
+ Object.new.send(:extend, EntryPoint).at(uri)
10
+ end
11
+
12
+ def recipe(converter_sym, options={}, &block)
13
+ raise 'Undefined block' unless block_given?
14
+ converter = "Restfulie::Common::Converter::#{converter_sym.to_s.camelize}".constantize
15
+ converter.describe_recipe(options[:name], &block)
16
+ end
17
+
18
+ @resources_configurations = {}
19
+ def configuration_of(resource_name)
20
+ @resources_configurations[resource_name]
21
+ end
22
+
23
+ def configuration_for(resource_name,configuration = Configuration.new)
24
+ yield configuration if block_given?
25
+ @resources_configurations[resource_name] = configuration
26
+ end
27
+
28
+ def retrieve(resource_name)
29
+ returning Object.new do |resource|
30
+ resource.extend(Base)
31
+ resource.configure
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,12 @@
1
+ # inject new behavior in Atom instances to enable easily access to link relationships.
2
+ module Restfulie
3
+ module Common
4
+ module Representation
5
+ module Atom
6
+ class Link
7
+ include Restfulie::Client::HTTP::LinkRequestBuilder
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ module Net
2
+ class HTTP
3
+ # Definition of a patch method in the same way that post works
4
+ def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
5
+ res = nil
6
+ request(Patch.new(path, initheader), data) {|r|
7
+ r.read_body dest, &block
8
+ res = r
9
+ }
10
+ unless @newimpl
11
+ res.value
12
+ return res, res.body
13
+ end
14
+ res
15
+ end
16
+
17
+ class Patch < Get
18
+ METHOD = "PATCH"
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,12 @@
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
+ include Restfulie::Client::HTTP::LinkRequestBuilder
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # inject new behavior in Atom instances to enable easily access to link relationships.
2
+ class Hash
3
+ include Restfulie::Client::HTTP::LinkRequestBuilder
4
+ end
@@ -1,15 +1,27 @@
1
- module Restfulie::Client::HTTP#:nodoc:
2
- end
3
-
4
- %w(
5
- error
6
- adapter
7
- cache
8
- marshal
9
- atom_ext
10
- xml_ext
11
- core_ext
12
- ).each do |file|
13
- require "restfulie/client/http/#{file}"
1
+ module Restfulie
2
+ module Client
3
+ module HTTP#:nodoc:
4
+ autoload :Error, 'restfulie/client/http/error'
5
+ autoload :Response, 'restfulie/client/http/response'
6
+ autoload :ResponseHandler, 'restfulie/client/http/response_handler'
7
+ autoload :RequestAdapter, 'restfulie/client/http/request_adapter'
8
+ autoload :RequestBuilder, 'restfulie/client/http/request_builder'
9
+ autoload :RequestFollow, 'restfulie/client/http/request_follow'
10
+ autoload :RequestHistory, 'restfulie/client/http/request_history'
11
+ autoload :RequestExecutor, 'restfulie/client/http/request_executor'
12
+ autoload :RequestBuilderExecutor, 'restfulie/client/http/request_builder_executor'
13
+ autoload :RequestFollowExecutor, 'restfulie/client/http/request_follow_executor'
14
+ autoload :RequestHistoryExecutor, 'restfulie/client/http/request_history_executor'
15
+ autoload :Cache, 'restfulie/client/http/cache'
16
+ autoload :ResponseHolder, 'restfulie/client/http/response_holder'
17
+ autoload :RequestMarshaller, 'restfulie/client/http/request_marshaller'
18
+ autoload :LinkRequestBuilder, 'restfulie/client/http/link_request_builder'
19
+ autoload :RequestMarshallerExecutor, 'restfulie/client/http/request_marshaller_executor'
20
+ end
21
+ end
14
22
  end
15
23
 
24
+ require 'restfulie/client/ext/atom_ext'
25
+ require 'restfulie/client/ext/xml_ext'
26
+ require 'restfulie/client/ext/http_ext'
27
+ require 'restfulie/client/ext/json_ext'