mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
added delicious example and tweaked the twitter example
This commit is contained in:
parent
a8e1e6acbd
commit
99cd89d33d
2 changed files with 54 additions and 12 deletions
37
examples/delicious.rb
Normal file
37
examples/delicious.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
require File.join(dir, 'web')
|
||||
require 'pp'
|
||||
config = YAML::load(File.read(File.join(ENV['HOME'], '.delicious')))
|
||||
|
||||
class Delicious
|
||||
include Web
|
||||
|
||||
base_uri 'https://api.del.icio.us/v1'
|
||||
format :xml
|
||||
|
||||
def initialize(user, pass)
|
||||
self.class.basic_auth(user, pass)
|
||||
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={})
|
||||
self.class.get('/posts/get', options)['posts']['post'].map { |b| b.to_struct }
|
||||
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={})
|
||||
self.class.get('/posts/recent', options)['posts']['post'].map { |b| b.to_struct }
|
||||
end
|
||||
end
|
||||
|
||||
pp Delicious.new(config['username'], config['password']).posts
|
||||
|
||||
puts '', 'RECENT'
|
||||
pp Delicious.new(config['username'], config['password']).recent
|
||||
|
|
@ -6,24 +6,29 @@ config = YAML::load(File.read(File.join(ENV['HOME'], '.twitter')))
|
|||
class Twitter
|
||||
include Web
|
||||
base_uri 'twitter.com'
|
||||
format :xml
|
||||
|
||||
def initialize(user, pass)
|
||||
self.class.basic_auth user, pass
|
||||
end
|
||||
|
||||
def timeline
|
||||
self.class.get('/statuses/user_timeline.xml')['statuses'].map(&:to_struct)
|
||||
def timeline(which=:friends, options={})
|
||||
self.class.get("/statuses/#{which}_timeline.xml", options)['statuses'].map(&:to_struct)
|
||||
end
|
||||
|
||||
def post(text)
|
||||
self.class.post('/statuses/update.xml', :query => {:status => text})['status'].to_struct
|
||||
end
|
||||
end
|
||||
|
||||
twitter = Twitter.new(config['email'], config['password'])
|
||||
statuses = twitter.timeline
|
||||
pp statuses
|
||||
|
||||
statuses.each do |s|
|
||||
puts s.user.name
|
||||
puts s.text
|
||||
puts s.created_at
|
||||
puts '', ''
|
||||
end
|
||||
twitter = Twitter.new(config['email'], config['password'])
|
||||
|
||||
twitter.timeline.each do |s|
|
||||
puts s.user.name, s.text, "#{s.created_at} #{s.id}", ''
|
||||
end
|
||||
|
||||
# twitter.timeline(:friends, :query => {:since_id => 868482746}).each do |s|
|
||||
# puts s.user.name, s.text, "#{s.created_at} #{s.id}", ''
|
||||
# end
|
||||
#
|
||||
# pp twitter.post('this is a test')
|
Loading…
Reference in a new issue