Ruby的HTTP/REST客户端库 HTTParty
<p>HTTParty是目前最受Ruby爱好者欢迎的一个简单的HTTP / REST客户端库。</p> <p>示例代码:</p> <p></p> <pre class="brush:ruby; toolbar: true; auto-links: false;">require 'rubygems' require 'httparty' class Representative include HTTParty base_uri 'whoismyrepresentative.com' default_params :output => 'json' format :json def self.find_by_zip(zip) get('/whoismyrep.php', :query => {:zip => zip}) end def self.get_all_by_name(last_name) get('/getall_reps_byname.php', :query => {:lastname => last_name}) end end puts Representative.get_all_by_name('Donnelly').inspect # {"results"=>[{"district"=>"2", "last"=>"Donnelly", "first"=>"Joe", "state"=>"IN", "party"=>"D"}]}</pre> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326988009233" target="_blank">http://www.open-open.com/lib/view/home/1326988009233</a></p>
本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!