带HTTParty Gem的美味API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带HTTParty Gem的美味API相关的知识,希望对你有一定的参考价值。
# From: http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited # Author: John Nunemaker # Delicious API with HTTParty Gem require 'rubygems' require 'httparty' class Delicious include HTTParty base_uri 'https://api.del.icio.us/v1' def initialize(auth) @auth = auth end # query params that filter the posts are: # tag (optional). Filter by this tag. # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ). # url (optional). Filter by this url. # ie: posts(:query => {:tag => 'ruby'}) def posts(options={}) options.merge!({:basic_auth => @auth}) # get posts and convert to structs so we can do .key instead of ['key'] with results self.class.get('/posts/get', options) end # query params that filter the posts are: # tag (optional). Filter by this tag. # count (optional). Number of items to retrieve (Default:15, Maximum:100). def recent(options={}) options.merge!({:basic_auth => @auth}) self.class.get('/posts/recent', options) end end # CHANGE USERNAME & PASS !!! delicious = Delicious.new( :username => 'username', :password => 'password' ) puts delicious.posts(:query => {:tag => 'ruby'}).inspect puts puts delicious.recent.inspect
以上是关于带HTTParty Gem的美味API的主要内容,如果未能解决你的问题,请参考以下文章