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
|
class Twitter
|
||||||
include Web
|
include Web
|
||||||
base_uri 'twitter.com'
|
base_uri 'twitter.com'
|
||||||
format :xml
|
|
||||||
|
|
||||||
def initialize(user, pass)
|
def initialize(user, pass)
|
||||||
self.class.basic_auth user, pass
|
self.class.basic_auth user, pass
|
||||||
end
|
end
|
||||||
|
|
||||||
def timeline
|
def timeline(which=:friends, options={})
|
||||||
self.class.get('/statuses/user_timeline.xml')['statuses'].map(&:to_struct)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
twitter = Twitter.new(config['email'], config['password'])
|
|
||||||
statuses = twitter.timeline
|
|
||||||
pp statuses
|
|
||||||
|
|
||||||
statuses.each do |s|
|
twitter = Twitter.new(config['email'], config['password'])
|
||||||
puts s.user.name
|
|
||||||
puts s.text
|
twitter.timeline.each do |s|
|
||||||
puts s.created_at
|
puts s.user.name, s.text, "#{s.created_at} #{s.id}", ''
|
||||||
puts '', ''
|
|
||||||
end
|
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