Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 106 lines (81 sloc) 2.982 kb
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
1 # Addressable
2
3 <dl>
4 <dt>Homepage</dt><dd><a href="http://addressable.rubyforge.org/">addressable.rubyforge.org</a></dd>
5 <dt>Author</dt><dd><a href="mailto:bob@sporkmonger.com">Bob Aman</a></dd>
c38aec1 @sporkmonger Bump the copyright dates.
authored
6 <dt>Copyright</dt><dd>Copyright © 2006-2015 Bob Aman</dd>
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
7 <dt>License</dt><dd>Apache 2.0</dd>
8 </dl>
9
58c12e1 @sporkmonger Update copyright and badges.
authored
10 [![Gem Version](http://img.shields.io/gem/dt/addressable.svg)][gem]
d39b594 @sporkmonger Adding gem version badge and coveralls.
authored
11 [![Build Status](https://secure.travis-ci.org/sporkmonger/addressable.png?branch=master)][travis]
12 [![Dependency Status](https://gemnasium.com/sporkmonger/addressable.png?travis)][gemnasium]
58c12e1 @sporkmonger Update copyright and badges.
authored
13 [![Test Coverage Status](https://img.shields.io/coveralls/sporkmonger/addressable.svg)][coveralls]
4600062 @sporkmonger Adding documentation coverage.
authored
14 [![Documentation Coverage Status](http://inch-ci.org/github/sporkmonger/addressable.svg?branch=master)][inch]
a101eea @sporkmonger It's time to ask for donations.
authored
15 [![Gittip Donate](http://img.shields.io/gittip/sporkmonger.png)](https://www.gittip.com/sporkmonger/ "Support Open Source Development w/ Gittip")
d39b594 @sporkmonger Adding gem version badge and coveralls.
authored
16
17 [gem]: https://rubygems.org/gems/addressable
18 [travis]: http://travis-ci.org/sporkmonger/addressable
19 [gemnasium]: https://gemnasium.com/sporkmonger/addressable
20 [coveralls]: https://coveralls.io/r/sporkmonger/addressable
4600062 @sporkmonger Adding documentation coverage.
authored
21 [inch]: http://inch-ci.org/github/sporkmonger/addressable
d4eabc4 @sporkmonger Added build and dependency statuses to README.
authored
22
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
23 # Description
24
25 Addressable is a replacement for the URI implementation that is part of
43c448d Updated README to be more clear about which RFCs are supported.
Bob Aman authored
26 Ruby's standard library. It more closely conforms to RFC 3986, RFC 3987, and
21040ce Wording was weird.
Bob Aman authored
27 RFC 6570 (level 4), providing support for IRIs and URI templates.
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
28
29 # Reference
30
31 - {Addressable::URI}
32 - {Addressable::Template}
33
34 # Example usage
35
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
36 ```ruby
37 require "addressable/uri"
38
39 uri = Addressable::URI.parse("http://example.com/path/to/resource/")
40 uri.scheme
41 #=> "http"
42 uri.host
43 #=> "example.com"
44 uri.path
45 #=> "/path/to/resource/"
46
47 uri = Addressable::URI.parse("http://www.詹姆斯.com/")
48 uri.normalize
49 #=> #<Addressable::URI:0xc9a4c8 URI:http://www.xn--8ws00zhy3a.com/>
a650ee4 @therabidbanana Update readme for templates
therabidbanana authored
50 ```
51
52
53 # URI Templates
54
55 For more details, see [RFC 6570](https://www.rfc-editor.org/rfc/rfc6570.txt).
56
57
58 ```ruby
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
59
60 require "addressable/template"
61
a650ee4 @therabidbanana Update readme for templates
therabidbanana authored
62 template = Addressable::Template.new("http://example.com/{?query*}/")
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
63 template.expand({
a650ee4 @therabidbanana Update readme for templates
therabidbanana authored
64 "query" => {
65 'foo' => 'bar',
66 'color' => 'red'
67 }
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
68 })
a650ee4 @therabidbanana Update readme for templates
therabidbanana authored
69 #=> #<Addressable::URI:0xc9d95c URI:http://example.com/?foo=bar&color=red>
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
70
a650ee4 @therabidbanana Update readme for templates
therabidbanana authored
71 template = Addressable::Template.new("http://example.com/{?one,two,three}/")
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
72 template.partial_expand({"one" => "1", "three" => 3}).pattern
a650ee4 @therabidbanana Update readme for templates
therabidbanana authored
73 #=> "http://example.com/?one=1{&two}&three=3"
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
74
75 template = Addressable::Template.new(
ad3b134 @jure Fix typo in Addressable::Template extract example in README. Fixes #164
jure authored
76 "http://{host}{/segments*}/{?one,two,bogus}{#fragment}"
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
77 )
78 uri = Addressable::URI.parse(
79 "http://example.com/a/b/c/?one=1&two=2#foo"
80 )
81 template.extract(uri)
82 #=>
83 # {
84 # "host" => "example.com",
85 # "segments" => ["a", "b", "c"],
86 # "one" => "1",
87 # "two" => "2",
88 # "fragment" => "foo"
89 # }
90 ```
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
91
92 # Install
93
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
94 ```console
95 $ sudo gem install addressable
96 ```
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
97
98 You may optionally turn on native IDN support by installing libidn and the
99 idn gem:
100
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
101 ```console
102 $ sudo apt-get install idn # Debian/Ubuntu
156212d @sporkmonger These days, `sudo` is not required for these two.
authored
103 $ brew install libidn # OS X
104 $ gem install idn-ruby
3f9ae4c @ming13 Use syntax highlighting in the readme file.
ming13 authored
105 ```
Something went wrong with that request. Please try again.