treat 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +3 -3
  3. data/lib/treat/config.rb +10 -0
  4. data/lib/treat/core/data_set.rb +80 -32
  5. data/lib/treat/core/feature.rb +35 -0
  6. data/lib/treat/core/problem.rb +43 -0
  7. data/lib/treat/core/question.rb +27 -0
  8. data/lib/treat/entities/abilities/buildable.rb +5 -3
  9. data/lib/treat/entities/abilities/exportable.rb +4 -4
  10. data/lib/treat/entities/collection.rb +1 -1
  11. data/lib/treat/entities/document.rb +1 -1
  12. data/lib/treat/entities/group.rb +8 -5
  13. data/lib/treat/entities/section.rb +1 -1
  14. data/lib/treat/entities/token.rb +20 -8
  15. data/lib/treat/entities/zone.rb +6 -5
  16. data/lib/treat/loaders/linguistics.rb +18 -19
  17. data/lib/treat/loaders/stanford.rb +3 -2
  18. data/lib/treat/version.rb +1 -1
  19. data/lib/treat/workers/extractors/language/what_language.rb +53 -57
  20. data/lib/treat/workers/extractors/name_tag/stanford.rb +8 -5
  21. data/lib/treat/workers/formatters/serializers/mongo.rb +33 -27
  22. data/lib/treat/workers/formatters/unserializers/mongo.rb +14 -36
  23. data/lib/treat/workers/learners/classifiers/id3.rb +4 -5
  24. data/lib/treat/workers/learners/classifiers/mlp.rb +1 -1
  25. data/lib/treat/workers.rb +1 -1
  26. data/spec/entity.rb +7 -5
  27. data/spec/phrase.rb +2 -2
  28. data/spec/zone.rb +2 -3
  29. metadata +37 -15
  30. data/bin/stanford/bridge.jar +0 -0
  31. data/bin/stanford/joda-time.jar +0 -0
  32. data/bin/stanford/stanford-corenlp.jar +0 -0
  33. data/bin/stanford/stanford-parser.jar +0 -0
  34. data/bin/stanford/xom.jar +0 -0
  35. data/files/21552208.html +0 -683
  36. data/files/3_2_release_notes.html +0 -766
  37. data/files/nethttp-cheat-sheet-2940.html +0 -395
  38. data/files/weather-central-canada-heat-wave.html +0 -1370
  39. data/lib/treat/core/classification.rb +0 -63
  40. data/lib/treat/core/server.rb +0 -3
  41. data/spec/sandbox.rb +0 -223
  42. data/tmp/english.yaml +0 -10340
@@ -1,395 +0,0 @@
1
- <!doctype html>
2
-
3
- <!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
4
- <!--[if IE 7 ]> <html lang="en" class="ie7"> <![endif]-->
5
- <!--[if IE 8 ]> <html lang="en" class="ie8"> <![endif]-->
6
- <!--[if IE 9 ]> <html lang="en" class="ie9"> <![endif]-->
7
- <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
8
-
9
- <head>
10
- <meta charset="utf-8">
11
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
12
- <title>Net::HTTP Cheat Sheet</title>
13
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
14
- <link rel="icon" href="/favicon.png" type="image/png">
15
- <link rel="shortcut icon" href="/favicon.png" type="image/png">
16
- <link rel="alternate" type="application/rss+xml" title="Ruby Inside" href="http://www.rubyinside.com/feed/" />
17
- <link rel="stylesheet" href="http://www.rubyinside.com/wp-content/themes/ri2011/css/ri.css">
18
- <!-- script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script -->
19
- <script type="text/javascript" src="http://use.typekit.com/dmj7czx.js"></script>
20
- <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
21
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
22
-
23
- <!--[if lt IE 9]>
24
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
25
- <![endif]-->
26
- </head>
27
-
28
- <body class="single single-post postid-2940 single-format-standard">
29
- <div id="superheader">Want to stay on top? <a href="http://rubyweekly.com/?m">Ruby Weekly</a> is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.</div>
30
- <div id="container">
31
- <div class="outerheader top">
32
- <div class="right"><form method="get" id="searchform" action="/"><input type="text" value="" name="s" id="s" size="24" /><input type="submit" id="searchsubmit" value="Search" /></form>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.rubyinside.com/feed/"><img src="http://feeds2.feedburner.com/~fc/RubyInside?bg=99CCFF&fg=333333&anim=0" align="top" alt="Feed Icon" /></a></div>
33
- <a href="/"><img src="http://www.rubyinside.com/wp-content/themes/ri2011/css/logo.png" id="logo" alt="Ruby Inside - A Ruby Blog" /></a>
34
- </div>
35
-
36
- <div class="outerheader masthead">
37
- <div class="menu">
38
- <ul>
39
- <li><a href="/" class="home">Home</a></li> <li><a href="/about/">About</a></li>
40
- <li><a href="/archives/">Archives</a></li>
41
- <!-- li><a href="/advertise/">Advertising</a></li -->
42
- <li><a href="http://jobs.rubyinside.com/">Ruby and Rails Jobs</a></li>
43
- <li class="right"><a href="/feed/">RSS</a> <!-- span class="count">(24146)</span --></li>
44
- <li class="right">
45
- </li>
46
- <li class="right"><a href="http://twitter.com/rubyinside">Follow us on Twitter</a> <!-- span class="count">(5548)</span --></li>
47
- </ul>
48
- </div>
49
-
50
-
51
- </div>
52
-
53
- <div id="innercontainer"><div id="page">
54
-
55
-
56
- <div id="sidebar">
57
- <div style="margin-top: 12px"><a href="http://twitter.com/RubyInside" class="twitter-follow-button">Follow @RubyInside</a>
58
- <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script></div>
59
- <div id="text-3" class="widget-container section widget_text"> <div class="textwidget"><!-- a href="http://owningrails.com/?ref=5905208113"><img src="http://owningrails.com/images/ad-with.png" /></a -->
60
- <!-- a href="http://rubyweekly.com/"><img src="http://rubyinside.com/wp-content/themes/ri20102/images/rw-ri-box.gif" /></a -->
61
- <a href="https://cooperpress.com/19walkthrough"><img src="/images/ruby19wt2.gif" /></a></div>
62
- </div><div id="execphp-3" class="widget-container section widget_execphp">
63
- <div class="execphpwidget"> <h3><a href="http://jobs.rubyinside.com/">Ruby and Rails Jobs</a></h3>
64
- <div class="inner">
65
- <ul>
66
- <!-- ? readfile('http://www.rubyinside.com/jobs.html'); ? -->
67
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/715321">Ruby on Rails Developer</a></div><div class='company'>OneLogin</div><div class="location">San Francisco, California</div></li>
68
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/717005">Ruby Programmer</a></div><div class='company'>PuzzleFlow Solutions</div><div class="location">Novi, Michigan</div></li>
69
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/706544">Ruby Developer</a></div><div class='company'>MeLLmo, Inc.</div><div class="location">Solana Beach, California</div></li>
70
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/715317">DevOps Engineer</a></div><div class='company'>OneLogin</div><div class="location">San Francisco, California</div></li>
71
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/706570">Telecommute- Ruby on Rails Consultant</a></div><div class='company'>IMPRTL Inc</div><div class="location">Chicago, Illinois</div></li>
72
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/716582">Ruby Developer</a></div><div class='company'>Wildfire Interactive</div><div class="location">Redwood City, California</div></li>
73
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/695510">Ruby on Rails Developer (multiple openings)</a></div><div class='company'>Coupa Software</div><div class="location">San Mateo, California</div></li>
74
- <li><div class='link'><a href="http://jobs.rubyinside.com/a/jbb/job-details/698233">Ruby on Rails Programmer</a></div><div class='company'>Digital Monitoring Products, Inc.</div><div class="location">Springfield, Missouri</div></li>
75
- <div class="minor"><a href="http://ruby.jobamatic.com/">More jobs &raquo;</a> : <a href="/post-a-job">Post a Job</a></div>
76
- </div>
77
- </div>
78
- </div>
79
-
80
- <!-- if (is_front_page() && !is_paged()) { -->
81
- </div>
82
-
83
- <div id="main">
84
-
85
-
86
-
87
- <div class="post-2940 post type-post status-publish format-standard hentry category-reference" id="post-2940">
88
-
89
- <div class="content">
90
-
91
- <div class="title"><h2>Net::HTTP Cheat Sheet</h2></div>
92
-
93
- <p class="author">By <a href="http://www.rubyinside.com/author/admin" title="View all posts by Peter Cooper">Peter Cooper</a> <span class="date">/ January 16, 2010</span></p>
94
- <div id="thecontent"><p><img src="http://www.rubyinside.com/wp-content/uploads/2010/01/http-is-a-hamster-on-rollerblades-says-marc-andre-cournoyer.gif" width="120" height="120" alt="http-is-a-hamster-on-rollerblades-says-marc-andre-cournoyer.gif" style="float:left; margin-right:12px; margin-bottom:12px; border:1px #000000 solid;" />Norwegian Rubyist <a href="http://august.lilleaas.net/">August Lilleaas</a> has been busy putting together <a href="http://github.com/augustl/net-http-cheat-sheet">a ton of examples</a> of using the <a href="http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html">Net::HTTP</a> Ruby library that comes with most Ruby distributions. I asked him if it'd be okay to put some of them directly on Ruby Inside for reference purposes and he said "No problem!"</p>
95
- <p>It's worth noting that Net::HTTP has been superseded in many areas by libraries like John Nunemaker's <a href="http://github.com/jnunemaker/httparty">HTTParty</a> and Paul DIx's high performance <a href="http://github.com/pauldix/typhoeus">Typhoeus</a>, but as part of the standard library, Net::HTTP is still a popular option though it doesn't have the easiest API to remember.</p>
96
- <p>Here's a selection of August's examples for some of the most common operations. Want to see <i>all</i> of the examples and follow any updates made to them? Check out August's <a href="http://github.com/augustl/net-http-cheat-sheet">net-http-cheat-sheet GitHub repo</a>.</p>
97
- <h3>Standard HTTP Request</h3>
98
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/http</span><span class="punct">"</span>
99
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
100
-
101
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">http://google.com/</span><span class="punct">")</span>
102
-
103
- <span class="comment"># Shortcut</span>
104
- <span class="ident">response</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">get_response</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">)</span>
105
-
106
- <span class="comment"># Will print response.body</span>
107
- <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">get_print</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">)</span>
108
-
109
- <span class="comment"># Full</span>
110
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
111
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Get</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">))</span></pre>
112
- <h3>Basic Auth</h3>
113
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/http</span><span class="punct">"</span>
114
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
115
-
116
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">http://google.com/</span><span class="punct">")</span>
117
-
118
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
119
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Get</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">)</span>
120
- <span class="ident">request</span><span class="punct">.</span><span class="ident">basic_auth</span><span class="punct">("</span><span class="string">username</span><span class="punct">",</span> <span class="punct">"</span><span class="string">password</span><span class="punct">")</span>
121
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span></pre>
122
- <h3>Dealing with response objects</h3>
123
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/http</span><span class="punct">"</span>
124
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
125
-
126
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">http://google.com/</span><span class="punct">")</span>
127
-
128
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
129
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Get</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">)</span>
130
-
131
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span>
132
-
133
- <span class="ident">response</span><span class="punct">.</span><span class="ident">code</span> <span class="comment"># => 301</span>
134
- <span class="ident">response</span><span class="punct">.</span><span class="ident">body</span> <span class="comment"># => The body (HTML, XML, blob, whatever)</span>
135
- <span class="comment"># Headers are lowercased</span>
136
- <span class="ident">response</span><span class="punct">["</span><span class="string">cache-control</span><span class="punct">"]</span> <span class="comment"># => public, max-age=2592000</span></pre>
137
- <h3>POST form request</h3>
138
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/http</span><span class="punct">"</span>
139
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
140
-
141
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">http://example.com/search</span><span class="punct">")</span>
142
-
143
- <span class="comment"># Shortcut</span>
144
- <span class="ident">response</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">post_form</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">,</span> <span class="punct">{"</span><span class="string">q</span><span class="punct">"</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">My query</span><span class="punct">",</span> <span class="punct">"</span><span class="string">per_page</span><span class="punct">"</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">50</span><span class="punct">"})</span>
145
-
146
- <span class="comment"># Full control</span>
147
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
148
-
149
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Post</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">)</span>
150
- <span class="ident">request</span><span class="punct">.</span><span class="ident">set_form_data</span><span class="punct">({"</span><span class="string">q</span><span class="punct">"</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">My query</span><span class="punct">",</span> <span class="punct">"</span><span class="string">per_page</span><span class="punct">"</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">50</span><span class="punct">"})</span>
151
-
152
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span></pre>
153
- <h3>File upload - input type="file" style</h3>
154
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/http</span><span class="punct">"</span>
155
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
156
-
157
- <span class="comment"># Token used to terminate the file in the post body. Make sure it is not</span>
158
- <span class="comment"># present in the file you're uploading.</span>
159
- <span class="constant">BOUNDARY</span> <span class="punct">=</span> <span class="punct">"</span><span class="string">AaB03x</span><span class="punct">"</span>
160
-
161
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">http://something.com/uploads</span><span class="punct">")</span>
162
- <span class="ident">file</span> <span class="punct">=</span> <span class="punct">"</span><span class="string">/path/to/your/testfile.txt</span><span class="punct">"</span>
163
-
164
- <span class="ident">post_body</span> <span class="punct">=</span> <span class="punct">[]</span>
165
- <span class="ident">post_body</span> <span class="punct">< <</span> <span class="punct">"</span><span class="string">--<span class="expr">#{BOUNDARY}</span><span class="escape">rn</span></span><span class="punct">"</span>
166
- <span class="ident">post_body</span> <span class="punct">< <</span> <span class="punct">"</span><span class="string">Content-Disposition: form-data; name=<span class="escape">"</span>datafile<span class="escape">"</span>; filename=<span class="escape">"</span><span class="expr">#{File.basename(file)}</span><span class="escape">"rn</span></span><span class="punct">"</span>
167
- <span class="ident">post_body</span> <span class="punct">< <</span> <span class="punct">"</span><span class="string">Content-Type: text/plain<span class="escape">rn</span></span><span class="punct">"</span>
168
- <span class="ident">post_body</span> <span class="punct">< <</span> <span class="punct">"</span><span class="string"><span class="escape">rn</span></span><span class="punct">"</span>
169
- <span class="ident">post_body</span> <span class="punct">< <</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">read</span><span class="punct">(</span><span class="ident">file</span><span class="punct">)</span>
170
- <span class="ident">post_body</span> <span class="punct">< <</span> <span class="punct">"</span><span class="string"><span class="escape">rn</span>--<span class="expr">#{BOUNDARY}</span>--<span class="escape">rn</span></span><span class="punct">"</span>
171
-
172
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
173
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Post</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">)</span>
174
- <span class="ident">request</span><span class="punct">.</span><span class="ident">body</span> <span class="punct">=</span> <span class="ident">post_body</span><span class="punct">.</span><span class="ident">join</span>
175
- <span class="ident">request</span><span class="punct">["</span><span class="string">Content-Type</span><span class="punct">"]</span> <span class="punct">=</span> <span class="punct">"</span><span class="string">multipart/form-data, boundary=<span class="expr">#{BOUNDARY}</span></span><span class="punct">"</span>
176
-
177
- <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span></span></span></span></span></span></span></pre>
178
- <h3>SSL/HTTPS request</h3>
179
- <p><strong>Update: There are some good reasons why this code example is bad. It introduces a potential security vulnerability if it's essential you use the server certificate to verify the identity of the server you're connecting to. There's <a href="http://www.rubyinside.com/how-to-cure-nethttps-risky-default-https-behavior-4010.html">a fix for the issue though!</a></strong></p>
180
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/https</span><span class="punct">"</span>
181
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
182
-
183
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">https://secure.com/</span><span class="punct">")</span>
184
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
185
- <span class="ident">http</span><span class="punct">.</span><span class="ident">use_ssl</span> <span class="punct">=</span> <span class="constant">true</span>
186
- <span class="ident">http</span><span class="punct">.</span><span class="ident">verify_mode</span> <span class="punct">=</span> <span class="constant">OpenSSL</span><span class="punct">::</span><span class="constant">SSL</span><span class="punct">::</span><span class="constant">VERIFY_NONE</span>
187
-
188
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Get</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">)</span>
189
-
190
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span>
191
- <span class="ident">response</span><span class="punct">.</span><span class="ident">body</span>
192
- <span class="ident">response</span><span class="punct">.</span><span class="ident">status</span>
193
- <span class="ident">response</span><span class="punct">["</span><span class="string">header-here</span><span class="punct">"]</span> <span class="comment"># All headers are lowercase</span></pre>
194
- <h3>SSL/HTTPS request with PEM certificate</h3>
195
- <pre><span class="ident">require</span> <span class="punct">"</span><span class="string">net/https</span><span class="punct">"</span>
196
- <span class="ident">require</span> <span class="punct">"</span><span class="string">uri</span><span class="punct">"</span>
197
-
198
- <span class="ident">uri</span> <span class="punct">=</span> <span class="constant">URI</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">("</span><span class="string">https://secure.com/</span><span class="punct">")</span>
199
- <span class="ident">pem</span> <span class="punct">=</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">read</span><span class="punct">("</span><span class="string">/path/to/my.pem</span><span class="punct">")</span>
200
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">host</span><span class="punct">,</span> <span class="ident">uri</span><span class="punct">.</span><span class="ident">port</span><span class="punct">)</span>
201
- <span class="ident">http</span><span class="punct">.</span><span class="ident">use_ssl</span> <span class="punct">=</span> <span class="constant">true</span>
202
- <span class="ident">http</span><span class="punct">.</span><span class="ident">cert</span> <span class="punct">=</span> <span class="constant">OpenSSL</span><span class="punct">::</span><span class="constant">X509</span><span class="punct">::</span><span class="constant">Certificate</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">pem</span><span class="punct">)</span>
203
- <span class="ident">http</span><span class="punct">.</span><span class="ident">key</span> <span class="punct">=</span> <span class="constant">OpenSSL</span><span class="punct">::</span><span class="constant">PKey</span><span class="punct">::</span><span class="constant">RSA</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">pem</span><span class="punct">)</span>
204
- <span class="ident">http</span><span class="punct">.</span><span class="ident">verify_mode</span> <span class="punct">=</span> <span class="constant">OpenSSL</span><span class="punct">::</span><span class="constant">SSL</span><span class="punct">::</span><span class="constant">VERIFY_PEER</span>
205
-
206
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Get</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">uri</span><span class="punct">.</span><span class="ident">request_uri</span><span class="punct">)</span></pre>
207
- <h3>REST methods</h3>
208
- <pre><span class="comment"># Basic REST.</span>
209
- <span class="comment"># Most REST APIs will set semantic values in response.body and response.code.</span>
210
- <span class="ident">require</span> <span class="punct">"</span><span class="string">net/http</span><span class="punct">"</span>
211
-
212
- <span class="ident">http</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">("</span><span class="string">api.restsite.com</span><span class="punct">")</span>
213
-
214
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Post</span><span class="punct">.</span><span class="ident">new</span><span class="punct">("</span><span class="string">/users</span><span class="punct">")</span>
215
- <span class="ident">request</span><span class="punct">.</span><span class="ident">set_form_data</span><span class="punct">({"</span><span class="string">users[login]</span><span class="punct">"</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">quentin</span><span class="punct">"})</span>
216
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span>
217
- <span class="comment"># Use nokogiri, hpricot, etc to parse response.body.</span>
218
-
219
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Get</span><span class="punct">.</span><span class="ident">new</span><span class="punct">("</span><span class="string">/users/1</span><span class="punct">")</span>
220
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span>
221
- <span class="comment"># As with POST, the data is in response.body.</span>
222
-
223
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Put</span><span class="punct">.</span><span class="ident">new</span><span class="punct">("</span><span class="string">/users/1</span><span class="punct">")</span>
224
- <span class="ident">request</span><span class="punct">.</span><span class="ident">set_form_data</span><span class="punct">({"</span><span class="string">users[login]</span><span class="punct">"</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">changed</span><span class="punct">"})</span>
225
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span>
226
-
227
- <span class="ident">request</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">::</span><span class="constant">Delete</span><span class="punct">.</span><span class="ident">new</span><span class="punct">("</span><span class="string">/users/1</span><span class="punct">")</span>
228
- <span class="ident">response</span> <span class="punct">=</span> <span class="ident">http</span><span class="punct">.</span><span class="ident">request</span><span class="punct">(</span><span class="ident">request</span><span class="punct">)</span></pre>
229
- <p>There are more in August's repo if you want to keep browsing..</p>
230
- <p style="background-color: #ffc; font-weight: bold; font-size: 13px; color: #000;">Job: New Relic is <a href="http://ruby.jobamatic.com/a/jbb/job-details/165476">looking for a Ruby on Rails developer in Portland, Oregon.</a></p>
231
- </div>
232
-
233
-
234
-
235
-
236
- <!-- div style="margin-bottom: 8px; background-color: #ffc; text-align: center; padding: 6px"><a href="http://zfer.us/EKm97" style="text-decoration: none; margin: 0; padding: 0" rel="nofollow"><img src="http://www.rubyinside.com/images/railstutorial-box.gif" /></a></div -->
237
- <!-- <a href="http://www.rubyinside.com/19walkthrough/"><img src="http://www.rubyinside.com/images/19pro.gif" /></a> -->
238
-
239
-
240
-
241
-
242
-
243
- </div>
244
- </div>
245
-
246
- <div id="related"><h3>Related Posts</h3><ul><li><a href='http://www.rubyinside.com/cheat-sheet-for-rest-on-rails-261.html' rel='bookmark' title='Cheat Sheet for REST on Rails'>Cheat Sheet for REST on Rails</a></li>
247
- <li><a href='http://www.rubyinside.com/quick-ruby-reference-cheat-sheet-47.html' rel='bookmark' title='Quick Ruby Reference / Cheat Sheet'>Quick Ruby Reference / Cheat Sheet</a></li>
248
- <li><a href='http://www.rubyinside.com/ruby-on-rails-testing-cheat-sheet-206.html' rel='bookmark' title='Ruby on Rails Testing Cheat Sheet'>Ruby on Rails Testing Cheat Sheet</a></li>
249
- </ul></div>
250
- <div id="commentzone">
251
-
252
-
253
-
254
- <h3 id="comments-title">Comments</h3>
255
-
256
- <ol class="commentlist">
257
- <li class="comment even thread-even depth-1" id="comment-40542">
258
- <img alt='' src='http://0.gravatar.com/avatar/6268c7528d855f1cef5696a00d159909?s=64&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&amp;r=G' class='avatar avatar-64 photo' height='64' width='64' /> <cite><a href='http://twitter.com/peterc' rel='external nofollow' class='url'>Peter Cooper</a> says:</cite><br />
259
-
260
- <small class="commentmetadata">January 16, 2010 at 1:02 am</small>
261
-
262
-
263
- <p>The idea for the hamster on rollerskates issue can be discovered by checking out its filename.. :-)</p>
264
-
265
-
266
- </li> <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-40546">
267
- <img alt='' src='http://0.gravatar.com/avatar/aa31b79adedc3f60547769f1a8971ba6?s=64&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&amp;r=G' class='avatar avatar-64 photo' height='64' width='64' /> <cite><a href='http://emmanueloga@gmail.com' rel='external nofollow' class='url'>Emmanuel</a> says:</cite><br />
268
-
269
- <small class="commentmetadata">January 16, 2010 at 3:50 pm</small>
270
-
271
-
272
- <p>Anybody knows if the HTTP::Net issues related with Timeout is still present in all (or any) ruby versions?</p>
273
- <p><a href="http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html" rel="nofollow">http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html</a></p>
274
-
275
-
276
- </li> <li class="comment even thread-even depth-1" id="comment-40550">
277
- <img alt='' src='http://0.gravatar.com/avatar/2bfc6436d28fc4a224e3ff1702a046d0?s=64&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&amp;r=G' class='avatar avatar-64 photo' height='64' width='64' /> <cite>ratbeard says:</cite><br />
278
-
279
- <small class="commentmetadata">January 17, 2010 at 4:23 pm</small>
280
-
281
-
282
- <p>Another library that abstracts over Net::HTTP is Adam Wiggin's 'rest-client' library. It seems more targeted toward single requests (i.e. Restclient.get 'google.com') than mixing in and building a request class like HTTParty, though both libraries do variants of each style. It has a great interactive shell and request logging.</p>
283
- <p><a href="http://github.com/archiloque/rest-client/" rel="nofollow">http://github.com/archiloque/rest-client/</a></p>
284
- <p>I **highly** recommend another library authored by Mr. Wiggins that abstracts over the messy file system api, 'rush'. I'm really surprised that more libraries and apps that have a non-trivial amount of file system code don't use it.</p>
285
- <p><a href="http://rush.heroku.com/" rel="nofollow">http://rush.heroku.com/</a></p>
286
- <p>The code is very clean in both, I tip my hat to you Mr. Wiggins.</p>
287
-
288
-
289
- </li> <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-40556">
290
- <img alt='' src='http://0.gravatar.com/avatar/e61f142f400df8299d37c2bce09e3478?s=64&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D64&amp;r=G' class='avatar avatar-64 photo' height='64' width='64' /> <cite><a href='http://august.lilleaas.net/' rel='external nofollow' class='url'>August Lilleaas</a> says:</cite><br />
291
-
292
- <small class="commentmetadata">January 19, 2010 at 10:19 am</small>
293
-
294
-
295
- <p>I always use one of these libraries when I can (rest-client, httparty, ...). In some cases you'd be better off without dependencies, though, such as in small shell scripts, etc.</p>
296
-
297
-
298
- </li> </ol>
299
-
300
-
301
-
302
- </div>
303
-
304
- <h3>Other Posts to Enjoy</h3>
305
- <div class="widget_featured-posts noborder four">
306
- <ul class="clearfix"><li>
307
-
308
- <a href="http://www.rubyinside.com/mega-february-2012-ruby-news-5815.html"><img src="http://www.rubyinside.com/wp-content/plugins/wp-featured-post-with-thumbnail/scripts/timthumb.php?src=http://www.rubyinside.com/wp-content/uploads/2012/03/mega.png&amp;h=73&amp;w=73&amp;zc=1" class="alignleft" alt="The Mega Ruby News and Release Roundup for February 2012" /></a>
309
- <h4 class="featured-title"><a href="http://www.rubyinside.com/mega-february-2012-ruby-news-5815.html">The Mega Ruby News and Release Roundup for February 2012</a></h4>
310
- </li>
311
- <li>
312
-
313
- <a href="http://www.rubyinside.com/sinatra-book-review-5704.html"><img src="http://www.rubyinside.com/wp-content/plugins/wp-featured-post-with-thumbnail/scripts/timthumb.php?src=http://www.rubyinside.com/wp-content/uploads/2011/12/sinatra-up.jpeg&amp;h=73&amp;w=73&amp;zc=1" class="alignleft" alt="A Lagom Review of O&#8217;Reilly&#8217;s &#8216;Sinatra Up and Running&#8217;" /></a>
314
- <h4 class="featured-title"><a href="http://www.rubyinside.com/sinatra-book-review-5704.html">A Lagom Review of O&#8217;Reilly&#8217;s &#8216;Sinatra Up and Running&#8217;</a></h4>
315
- </li>
316
- <li>
317
-
318
- <a href="http://www.rubyinside.com/rubys-unary-operators-and-how-to-redefine-their-functionality-5610.html"><img src="http://www.rubyinside.com/wp-content/plugins/wp-featured-post-with-thumbnail/scripts/timthumb.php?src=http://www.rubyinside.com/wp-content/uploads/2011/11/unary.gif&amp;h=73&amp;w=73&amp;zc=1" class="alignleft" alt="Ruby&#8217;s Unary Operators and How to Define Their Functionality" /></a>
319
- <h4 class="featured-title"><a href="http://www.rubyinside.com/rubys-unary-operators-and-how-to-redefine-their-functionality-5610.html">Ruby&#8217;s Unary Operators and How to Define Their Functionality</a></h4>
320
- </li>
321
- <li>
322
-
323
- <a href="http://www.rubyinside.com/the-ruby-standard-library-to-be-converted-to-gems-for-ruby-2-0-5586.html"><img src="http://www.rubyinside.com/wp-content/plugins/wp-featured-post-with-thumbnail/scripts/timthumb.php?src=http://www.rubyinside.com/wp-content/uploads/2011/11/stdlib-gem.gif&amp;h=73&amp;w=73&amp;zc=1" class="alignleft" alt="The Ruby Standard Library To Be Converted to Gems for Ruby 2.0?" /></a>
324
- <h4 class="featured-title"><a href="http://www.rubyinside.com/the-ruby-standard-library-to-be-converted-to-gems-for-ruby-2-0-5586.html">The Ruby Standard Library To Be Converted to Gems for Ruby 2.0?</a></h4>
325
- </li>
326
- </ul> </div>
327
-
328
-
329
-
330
-
331
-
332
- <h3>Twitter Mentions</h3>
333
- <div id="boastful"></div>
334
-
335
- <div class="previousnext">
336
- <div class="next"><a href="http://www.rubyinside.com/rubys-unary-operators-and-how-to-redefine-their-functionality-5610.html" rel="next">Next Post &raquo;</a></div>
337
- <div class="previous"><a href="http://www.rubyinside.com/this-weeks-ruby-news-ruby-1-9-3p0-omniauth-1-0-maglev-1-0-and-more-5580.html" rel="prev">&laquo; Previous Post</a></div>
338
- </div>
339
-
340
- <!-- <h3>Want to get up to speed with Ruby 1.9?</h3>
341
-
342
- <p><a href="http://www.rubyinside.com/19walkthrough/"><img src="http://www.rubyinside.com/images/19pro.gif" /></a> </p>
343
- -->
344
-
345
-
346
- </div>
347
-
348
- </div>
349
-
350
- </div> <!-- inner -->
351
-
352
-
353
-
354
-
355
- </div> <!-- container -->
356
-
357
-
358
- <div id="footer">
359
- <div class="inner">
360
- <p>Copyright &copy; 2006&ndash;2012 <a href="http://twitter.com/peterc">Peter Cooper</a></p>
361
- </div>
362
- </div>
363
-
364
- <script type="text/javascript" src="http://engine.rubyrow.net/z/1313/adzerk1_4_16_19,adzerk2_4_16_19,adzerk3_4_16_19,adzerk4_4_16_19,adzerk5_4_16_19,adzerk6_4_16_19,adzerk7_4_16_19,adzerk8_4_16_19"></script>
365
- <script type="text/javascript" src="http://www.rubyinside.com/wp-content/themes/ri2011/jquery.boastful.js"></script>
366
-
367
- <script type="text/javascript">
368
- $(document).ready(function() {
369
- $('#boastful').boastful();
370
- });
371
- </script>
372
-
373
- <script type="text/javascript">
374
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
375
- document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
376
- </script>
377
- <script type="text/javascript">
378
- var pageTracker = _gat._getTracker("UA-2237791-3");
379
- pageTracker._initData();
380
- pageTracker._trackPageview();
381
- </script>
382
-
383
-
384
- </body>
385
- </html>
386
-
387
- <!-- div style="float:right"><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.rubyinside.com/the-ruby-standard-library-to-be-converted-to-gems-for-ruby-2-0-5586.html" data-counturl="http://www.rubyinside.com/the-ruby-standard-library-to-be-converted-to-gems-for-ruby-2-0-5586.html" data-text="The Ruby Standard Library To Be Converted to Gems for Ruby 2.0?" data-count="horizontal">Tweet</a></div -->
388
- <!-- div style="margin-bottom: -12px; margin-top: -10px"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.rubyinside.com%2Fthe-ruby-standard-library-to-be-converted-to-gems-for-ruby-2-0-5586.html&amp;layout=standard&amp;show_faces=false&amp;width=420&amp;action=like&amp;colorscheme=light&amp;height=26" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:420px; height:26px;" allowTransparency="true"></iframe></div -->
389
- <!-- div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http://x.com/" show_faces="false" width="450"></fb:like></div -->
390
-
391
-
392
-
393
- <!-- Dynamic page generated in 0.357 seconds. -->
394
- <!-- Cached page generated by WP-Super-Cache on 2012-07-10 03:35:08 -->
395
- <!-- super cache -->