reststop 0.2.0.50 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.loadpath ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <loadpath>
3
+ <pathentry path="" type="src"/>
4
+ <pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
5
+ <pathentry path="GEM_LIB/reststop-0.2.0.50/lib" type="var"/>
6
+ <pathentry path="GEM_LIB/reststop-0.2.0.50/lib" type="var"/>
7
+ </loadpath>
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>reststop</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/CHANGELOG.txt CHANGED
@@ -1,30 +1 @@
1
- === 0.2.1 :: In Progress...
2
-
3
- * Restr should now work properly with Rails 2.x (fixes bug #17421).
4
- * R helper method should now work properly when a Restful object is fed as
5
- input along with a custom action.
6
-
7
- === 0.2.0 :: 2007-12-10
8
-
9
- * It is now possible to specify the format for rendering a page by appending
10
- it as a filename extension to the URL. For example: '/items.xml' to use the XML
11
- view module, or '/items/5.rss' to use the RSS module.
12
- * Custom actions are now possible. Custom methods defined in your controller will
13
- respond to the standard custom-action URLs. For example, if you have a method
14
- 'foo' in your 'kittens' controller, you can get to it by requesting the URL
15
- '/kittens/foo' or '/kittens/1/foo'. Note that the action will respond to any
16
- HTTP method (post, get, put, delete). It is up to you to handle different
17
- request methods inside your action's definition.
18
- * XML input (from an ActiveResource client, for example) is now parsed into a
19
- nested Hash, and is made available as the standard @input Camping variable.
20
- * HTML forms created using Markaby (i.e. by just using `form`) that
21
- have a :method parameter now automatically insert a hidden '_method' input to
22
- facilitate 'put' and 'delete' HTTP methods for HTML browsers.
23
- * Pages now correctly return HTTP status code 501 when an unimplemented controller
24
- method is called. ActiveRecord::NotFound exceptions are caught and return 404
25
- status.
26
- * R helper now works for routing RESTful controllers.
27
-
28
- === 0.1.0 :: 2007-07-30
29
-
30
- * First public release.
1
+ See History.txt
data/History.txt CHANGED
@@ -1 +1,33 @@
1
- See CHANGELOG.txt
1
+ === 0.3.0 :: 2008-06-19
2
+
3
+ * Restr has been moved out to its own gem, and should now work properly with
4
+ Rails 2.x (fixes bug #17421).
5
+ * `R` helper method should now work properly when a Restful controlelr class
6
+ is fed as input along with a custom action. The final argument can be a Hash
7
+ and will be translated into URL parameters. For example:
8
+ R(Kittens, 'list', 'colour' => 'black')
9
+
10
+ === 0.2.0 :: 2007-12-10
11
+
12
+ * It is now possible to specify the format for rendering a page by appending
13
+ it as a filename extension to the URL. For example: '/items.xml' to use the XML
14
+ view module, or '/items/5.rss' to use the RSS module.
15
+ * Custom actions are now possible. Custom methods defined in your controller will
16
+ respond to the standard custom-action URLs. For example, if you have a method
17
+ 'foo' in your 'kittens' controller, you can get to it by requesting the URL
18
+ '/kittens/foo' or '/kittens/1/foo'. Note that the action will respond to any
19
+ HTTP method (post, get, put, delete). It is up to you to handle different
20
+ request methods inside your action's definition.
21
+ * XML input (from an ActiveResource client, for example) is now parsed into a
22
+ nested Hash, and is made available as the standard @input Camping variable.
23
+ * HTML forms created using Markaby (i.e. by just using `form`) that
24
+ have a :method parameter now automatically insert a hidden '_method' input to
25
+ facilitate 'put' and 'delete' HTTP methods for HTML browsers.
26
+ * Pages now correctly return HTTP status code 501 when an unimplemented controller
27
+ method is called. ActiveRecord::NotFound exceptions are caught and return 404
28
+ status.
29
+ * R helper now works for routing RESTful controllers.
30
+
31
+ === 0.1.0 :: 2007-07-30
32
+
33
+ * First public release.
data/Manifest.txt CHANGED
@@ -1,3 +1,5 @@
1
+ .loadpath
2
+ .project
1
3
  CHANGELOG.txt
2
4
  History.txt
3
5
  LICENSE.txt
@@ -5,7 +7,6 @@ Manifest.txt
5
7
  README.txt
6
8
  Rakefile
7
9
  examples/blog.rb
8
- lib/restr.rb
9
10
  lib/reststop.rb
10
11
  lib/reststop/version.rb
11
12
  setup.rb
data/README.txt CHANGED
@@ -77,14 +77,19 @@ through your Kittens controller's <tt>list</tt>, formatted using your
77
77
  <tt>XML</tt> view module.
78
78
 
79
79
 
80
- <b>BONUS: A simple REST client</b>
80
+ <b>Looking for Restr, the very simple REST client?</b>
81
81
 
82
- Reststop also comes with a very simple REST client called Restr.
82
+ Due to its popularity, <b>Restr</b>, the "very simple rest client",
83
+ has been moved out to its own gem. Restr now lives under
84
+ http://rubyforge.org/projects/restr/ and can be installed using:
85
+
86
+ gem install restr
87
+
83
88
  Restr is basically a wrapper around Ruby's Net::HTTP, offering
84
89
  a more RESTfully meaningful interface.
85
90
 
86
- See the Restr documentation for more info, but here's a simple
87
- example of RESTful interaction with Restr:
91
+ See the "Restr documentation"[http://restr.rubyforge.org/] for more info,
92
+ but here's a simple example of RESTful interaction with Restr:
88
93
 
89
94
  require 'restr'
90
95
  kitten = Restr.get('http://example.com/kittens/1.xml')
data/Rakefile CHANGED
@@ -21,8 +21,8 @@ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
21
21
  ENV['NODOT'] = '1'
22
22
 
23
23
  NAME = "reststop"
24
- #REV = nil
25
- REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
24
+ REV = nil
25
+ #REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
26
26
  VERS = ENV['VERSION'] || (Reststop::VERSION::STRING + (REV ? ".#{REV}" : ""))
27
27
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
28
28
  RDOC_OPTS = ['--quiet', '--title', "#{NAME} #{VERS} documentation",
@@ -51,6 +51,6 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
51
 
52
52
  # == Optional
53
53
  #p.changes - A description of the release's latest changes.
54
- #p.extra_deps - An array of rubygem dependencies.
54
+ p.extra_deps = ['restr']
55
55
  #p.spec_extras - A hash of extra values to set in the gemspec.
56
56
  end
@@ -1,7 +1,7 @@
1
1
  module Reststop
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
4
+ MINOR = 3
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/reststop.rb CHANGED
@@ -403,6 +403,7 @@ module Camping
403
403
  # R(Kittens, 1, 'meow') # /kittens/1/meow
404
404
  # R(@kitten) # /kittens/1
405
405
  # R(@kitten, 'meow') # /kittens/1/meow
406
+ # R(Kittens, 'list', :colour => 'black') # /kittens/list?colour=black
406
407
  #
407
408
  # The current output format is retained, so if the current <tt>@format</tt> is <tt>:XML</tt>,
408
409
  # the URL will be /kittens/1.xml rather than /kittens/1.
@@ -415,17 +416,21 @@ module Camping
415
416
  path = "/#{cl.underscore}/#{c.id}"
416
417
  path << ".#{@format.to_s.downcase}" if @format
417
418
  path << "/#{g.shift}" unless g.empty?
418
- # FIXME: undefined behaviour if there are multiple arguments left... maybe we should allow for arbitrary params as a Hash?
419
419
  self / path
420
420
  elsif c.respond_to?(:restful?) && c.restful?
421
421
  base = c.name.split("::").last.underscore
422
- id = g.shift
423
- action = g.shift
422
+ id_or_action = g.shift
423
+ if id_or_action =~ /\d+/
424
+ id = id_or_action
425
+ action = g.shift
426
+ else
427
+ action = id_or_action
428
+ end
424
429
  path = "/#{base}"
425
430
  path << "/#{id}" if id
426
431
  path << "/#{action}" if action
427
432
  path << ".#{@format.to_s.downcase}" if @format
428
- path << "?#{g}" unless g.empty? # FIXME: undefined behaviour if there are multiple arguments left
433
+ path << "?#{g.collect{|a|a.collect{|k,v| C.escape(k)+"="+C.escape(v)}.join("&")}.join("&")}" unless g.empty? # FIXME: undefined behaviour if there are multiple arguments left
429
434
  self / path
430
435
  else
431
436
  _R(c, *g)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reststop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.50
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zukowski
@@ -9,10 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-10 00:00:00 -04:00
12
+ date: 2008-06-19 00:00:00 -04:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: restr
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
16
24
  description: Convenient RESTfulness for all your Camping needs (i.e. makes it easy to implement RESTful controllers in Camping).
17
25
  email: matt@roughest.net
18
26
  executables: []
@@ -26,6 +34,8 @@ extra_rdoc_files:
26
34
  - Manifest.txt
27
35
  - README.txt
28
36
  files:
37
+ - .loadpath
38
+ - .project
29
39
  - CHANGELOG.txt
30
40
  - History.txt
31
41
  - LICENSE.txt
@@ -33,7 +43,6 @@ files:
33
43
  - README.txt
34
44
  - Rakefile
35
45
  - examples/blog.rb
36
- - lib/restr.rb
37
46
  - lib/reststop.rb
38
47
  - lib/reststop/version.rb
39
48
  - setup.rb
data/lib/restr.rb DELETED
@@ -1,126 +0,0 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'uri'
4
- require 'cgi'
5
-
6
- begin
7
- require 'xml_simple'
8
- rescue LoadError
9
- require 'rubygems'
10
- require 'active_support'
11
- begin
12
- require 'xml_simple'
13
- rescue LoadError
14
- require 'xmlsimple'
15
- end
16
- end
17
-
18
-
19
- # A very simple REST client, best explained by example:
20
- #
21
- # # Retrieve a Kitten and print its name and colour
22
- # kitten = Restr.get('http://example.com/kittens/1.xml')
23
- # puts kitten['name']
24
- # puts kitten['colour']
25
- #
26
- # # Create a Kitten
27
- # kitten = Restr.post('http://example.com/kittens.xml',
28
- # :name => 'batman', :colour => 'black')
29
- #
30
- # # Update a Kitten
31
- # kitten = Restr.put('http://example.com/kittens/1.xml',
32
- # :age => '6 months')
33
- #
34
- # # Delete a Kitten :(
35
- # kitten = Restr.delete('http://example.com/kittens/1.xml')
36
- #
37
- # # Retrieve a list of Kittens
38
- # kittens = Restr.get('http://example.com/kittens.xml')
39
- #
40
- # When the response to a Restr request has content type 'text/xml', the
41
- # response body will be parsed from XML into a nested Hash (using XmlSimple
42
- # -- see http://xml-simple.rubyforge.org/). Otherwise the response is
43
- # returned untouched, as a String.
44
- #
45
- # If the remote REST resource requires authentication (Restr only supports
46
- # HTTP Basic authentication, for now):
47
- #
48
- # Restr.get('http://example.com/kittens/1.xml, {},
49
- # {:username => 'foo', :password => 'bar'})
50
- #
51
- class Restr
52
- @@log = nil
53
-
54
- def self.logger=(logger)
55
- @@log = logger.dup
56
- @@log.progname = self.name
57
- end
58
-
59
- def self.method_missing(method, *args)
60
- self.do(method, args[0], args[1] || {}, args[2])
61
- end
62
-
63
- def self.do(method, url, params = {}, auth = nil)
64
- uri = URI.parse(url)
65
- params = {} unless params
66
-
67
- method_mod = method.to_s.downcase.capitalize
68
- unless Net::HTTP.const_defined?(method_mod)
69
- raise InvalidRequestMethod,
70
- "Callback method #{method.inspect} is not a valid HTTP request method."
71
- end
72
-
73
- if method_mod == 'Get'
74
- q = params.collect{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join("&")
75
- if uri.query
76
- uri.query += "&#{q}"
77
- else
78
- uri.query = q
79
- end
80
- end
81
-
82
- req = Net::HTTP.const_get(method_mod).new(uri.request_uri)
83
-
84
-
85
- if auth
86
- raise ArgumentError,
87
- "The `auth` parameter must be a Hash with a :username and :password value." unless
88
- auth.kind_of? Hash
89
- req.basic_auth auth[:username] || auth['username'], auth[:password] || auth['password']
90
- end
91
-
92
- unless method_mod == 'Get'
93
- req.set_form_data(params, '&')
94
- end
95
-
96
- @@log.debug("Sending #{method.inspect} request to #{url.inspect} with data #{params.inspect}"+
97
- (auth ? " with authentication" : "")+".") if @@log
98
-
99
- client = Net::HTTP.new(uri.host, uri.port)
100
- client.use_ssl = (uri.scheme == 'https')
101
- res = client.start do |http|
102
- http.request(req)
103
- end
104
-
105
- case res
106
- when Net::HTTPSuccess
107
- if res.content_type == 'text/xml'
108
- @@log.debug("Got XML response.") if @@log
109
- return XmlSimple.xml_in_string(res.body,
110
- 'forcearray' => false,
111
- 'keeproot' => false
112
- )
113
- else
114
- @@log.debug("Got #{res.content_type.inspect} response.") if @@log
115
- return res.body
116
- end
117
- else
118
- $LAST_ERROR_BODY = res.body # FIXME: this is dumb... need a better way of reporting errors
119
- @@log.error("Got error response '#{res.message}(#{res.code})': #{$LAST_ERROR_BODY}") if @@log
120
- res.error!
121
- end
122
- end
123
-
124
- class InvalidRequestMethod < Exception
125
- end
126
- end