Skip to content
Browse files

Updated the README and fixed GH#34 Wrest::Uri extensions swallow exis…

…ting path
  • Loading branch information...
1 parent c51ed89 commit cd59244651bac5a6506efc41abbf22a82d0509eb @kaiwren committed Sep 17, 2010
Showing with 36 additions and 38 deletions.
  1. +2 −1 CHANGELOG
  2. +2 −0 Gemfile.lock
  3. +27 −36 README.rdoc
  4. +1 −1 lib/wrest/uri.rb
  5. +4 −0 spec/wrest/uri_spec.rb
View
3 CHANGELOG
@@ -17,7 +17,8 @@ Features under a numbered section are complete and available in the Wrest gem.
* Ensure Components::Container is ActiveModel compliant
== Current
-
+ * GH#34 Wrest::Uri extensions swallow existing path
+
== 1.0.0.beta3
* GH#13 Works for get and delete with parameters appended to the uri string and
with ? and no parameters appended to the uri string
View
2 Gemfile.lock
@@ -8,6 +8,7 @@ GEM
jrexml (0.5.3)
json (1.4.6)
json-jruby (1.4.3.1-java)
+ libxml-ruby (1.1.4)
multipart-post (1.0.1)
nokogiri (1.4.3.1)
nokogiri (1.4.3.1-java)
@@ -35,6 +36,7 @@ DEPENDENCIES
jrexml (~> 0.5.3)
json (~> 1.4.6)
json-jruby (~> 1.4.3.1)
+ libxml-ruby (~> 1.1.4)
multipart-post (~> 1.0)
nokogiri (~> 1.4.3.1)
patron (~> 0.4.9)
View
63 README.rdoc
@@ -17,55 +17,32 @@ To receive notifications whenever new features are added to Wrest, please subscr
For Facebook, Twitter, Delicious, GitHub and other API examples, see http://github.com/kaiwren/wrest/tree/master/examples
-== Installation
-
-The source is available at git://github.com/kaiwren/wrest.git
-
-To install the Wrest gem, do <tt>(sudo) gem install wrest --pre</tt>.
-
-Wrest is currently available as a gem for for Ruby and JRuby.
-
-=== Shell
-
-You can launch the interactive Wrest shell by running bin/wrest if you have the source or invoking <tt>wrest</tt> from your prompt if you've installed the gem.
- $ wrest
- >> y 'http://twitter.com/statuses/public_timeline.json'.to_uri(:timeout => 5).get.deserialise
-
-=== Library
-
- require 'rubygems'
- require 'wrest'
- y "http://search.yahooapis.com/NewsSearchService/V1/newsSearch".to_uri.get(
- :appid => 'YahooDemo',
- :output => 'xml',
- :query => 'India',
- :results=> '3',
- :start => '1'
- )
=== Basic Http Calls
==== GET
-A couple of ways to get Yahoo news as a hash map.
+ 'http://twitter.com/statuses/public_timeline.json'.to_uri.get.deserialise # works with json and xml out-of-the-box
-* This example simply does a get on a uri and figures out the appropriate deserialiser using the content-type (in this case 'text/javascript', which uses Wrest::Translators::Json). See content_types.rb under lib/wrest/mappers/translators.
- "http://search.yahooapis.com/NewsSearchService/V1/newsSearch?appid=YahooDemo&output=json&query=India&results=3&start=1".to_uri.get.deserialise
+ 'http://twitter.com/statuses/public_timeline.xml'.to_uri.get.deserialise
+
+ 'http://twitter.com/statuses/public_timeline.json'.to_uri.get(:timeout => 5).body
+
+ 'http://google.com'.to_uri(:follow_redirects => false).get
+
+ 'http://google.com'.to_uri(:follow_redirects_limit => 1).get
-* This example does a get on a base uri with several parameters passed to it, resulting in a uri essentially the same as the one above. It also shows how you can specify a custom deserialiser to produce a hash-map from the response, as well as a hash mutator to clean up the deserialised hash.
- require 'rubygems'
- require 'wrest'
- include Wrest::Components
- y "http://search.yahooapis.com/NewsSearchService/V1/newsSearch".to_uri.get(
+ 'http://search.yahooapis.com/NewsSearchService/V1/newsSearch'.to_uri.get(
:appid => 'YahooDemo',
:output => 'xml',
:query => 'India',
:results=> '3',
:start => '1'
).deserialise_using(
- Translators::Xml
- ).mutate_using(
- Mutators::XmlMiniTypeCaster.new
+ Wrest::Translators::Xml
)
+
+ base_uri = 'https://api.del.icio.us/v1'.to_uri(:username => 'kaiwren', :password => 'fupupp1es') # simple HTTP authentication
+ bookmarks = base_uri['/posts/get'].get.deserialise
==== DELETE
@@ -125,3 +102,17 @@ Wrest RDocs can be found at http://wrest.rubyforge.org
== Roadmap
Features that are planned, in progress or already implemented are documented in the {CHANGELOG}[http://github.com/kaiwren/wrest/tree/master/CHANGELOG] starting from version 0.0.8.
+
+== Installation
+
+The source is available at git://github.com/kaiwren/wrest.git
+
+To install the Wrest gem, do <tt>(sudo) gem install wrest --pre</tt>.
+
+Wrest is currently available as a gem for for Ruby and JRuby.
+
+=== Shell
+
+You can launch the interactive Wrest shell by running bin/wrest if you have the source or invoking <tt>wrest</tt> from your prompt if you've installed the gem.
+ $ wrest
+ >> y 'http://twitter.com/statuses/public_timeline.json'.to_uri(:timeout => 5).get.deserialise
View
2 lib/wrest/uri.rb
@@ -58,7 +58,7 @@ def to_template(pattern)
# uri = "https://localhost:3000/v1".to_uri(:username => 'foo', :password => 'bar')
# uri['/oogas/1', {:username => 'meh', :password => 'baz'}].get
def [](path, options = nil)
- Uri.new(URI.join(uri_string, path), options || @options)
+ Uri.new(uri + File.join(uri_path, path), options || @options)
end
# Clones a Uri, building a new instance with exactly the same uri string.
View
4 spec/wrest/uri_spec.rb
@@ -48,6 +48,10 @@ module Wrest
it "should know how to build a new uri from an existing one by appending a path" do
Uri.new('http://localhost:3000')['/ooga/booga'].should == Uri.new('http://localhost:3000/ooga/booga')
end
+
+ it "should not lose bits of the path along the way" do
+ Uri.new('http://localhost:3000/ooga')['/booga'].should == Uri.new('http://localhost:3000/ooga/booga')
+ end
it "should handle / positions with wisdom" do
Uri.new('http://localhost:3000/')['/ooga/booga'].should == Uri.new('http://localhost:3000/ooga/booga')

0 comments on commit cd59244

Please sign in to comment.
Something went wrong with that request. Please try again.