Class: Twitter::Base
- Inherits:
-
Object
- Object
- Twitter::Base
- Defined in:
- lib/twitter/base.rb
Instance Method Summary collapse
-
#block(id) ⇒ Object
Blocks the user specified by id for the auth user.
-
#create_favorite(id) ⇒ Object
Favorites the status specified by id for the auth user.
-
#create_friendship(id_or_screenname) ⇒ Object
Befriends id_or_screenname for the auth user.
-
#d(user, text) ⇒ Object
Sends a direct message
text
touser
. -
#destroy(id) ⇒ Object
Destroys a status by id.
-
#destroy_direct_message(id) ⇒ Object
destroys a give direct message by id if the auth user is a recipient.
-
#destroy_favorite(id) ⇒ Object
Un-favorites the status specified by id for the auth user.
-
#destroy_friendship(id_or_screenname) ⇒ Object
Defriends id_or_screenname for the auth user.
-
#direct_messages(options = {}) ⇒ Object
(also: #received_messages)
Returns an array of all the direct messages for the authenticated user.
-
#favorites(options = {}) ⇒ Object
Returns the most recent favorite statuses for the autenticating user.
-
#featured ⇒ Object
waiting for twitter to correctly implement this in the api as it is documented.
-
#follow(id_or_screenname) ⇒ Object
Turns notifications by id_or_screenname on for auth user.
-
#followers(options = {}) ⇒ Object
Returns an array of users who are following you.
- #followers_for(id, options = {}) ⇒ Object
-
#friends(options = {}) ⇒ Object
Returns an array of users who are in your friends list.
-
#friends_for(id, options = {}) ⇒ Object
Returns an array of users who are friends for the id or username passed in.
-
#friendship_exists?(user_a, user_b) ⇒ Boolean
Returns true if friendship exists, false if it doesn’t.
-
#initialize(email, password, options = {}) ⇒ Base
constructor
Initializes the configuration for making requests to twitter Twitter example: Twitter.new(‘email/username’, ‘password’).
-
#leave(id_or_screenname) ⇒ Object
Turns notifications by id_or_screenname off for auth user.
-
#post(status, options = {}) ⇒ Object
(also: #update)
Posts a new update to twitter for auth user.
- #rate_limit_status ⇒ Object
-
#replies(options = {}) ⇒ Object
Returns an array of statuses that are replies.
-
#sent_messages(options = {}) ⇒ Object
Returns direct messages sent by auth user.
-
#status(id) ⇒ Object
Returns a single status for a given id.
-
#timeline(which = :friends, options = {}) ⇒ Object
Returns an array of statuses for a timeline; Defaults to your friends timeline.
-
#unblock(id) ⇒ Object
Unblocks the user specified by id for the auth user.
-
#update_delivery_device(device) ⇒ Object
Updates your deliver device and returns Twitter::User object.
-
#update_location(location) ⇒ Object
Updates your location and returns Twitter::User object.
-
#user(id_or_screenname) ⇒ Object
returns all the profile information and the last status for a user.
-
#verify_credentials ⇒ Object
Verifies the credentials for the auth user.
Constructor Details
#initialize(email, password, options = {}) ⇒ Base
14 15 16 17 18 19 |
# File 'lib/twitter/base.rb', line 14 def initialize(email, password, ={}) @api_host = .delete(:api_host) || 'twitter.com' @config, @config[:email], @config[:password] = , email, password @proxy_host = [:proxy_host] @proxy_port = [:proxy_port] end |
Instance Method Details
#block(id) ⇒ Object
Blocks the user specified by id for the auth user
151 152 153 |
# File 'lib/twitter/base.rb', line 151 def block(id) users(request("blocks/create/#{id}.xml", :auth => true, :method => :post)).first end |
#create_favorite(id) ⇒ Object
Favorites the status specified by id for the auth user
141 142 143 |
# File 'lib/twitter/base.rb', line 141 def create_favorite(id) statuses(request("favorites/create/#{id}.xml", :auth => true, :method => :post)).first end |
#create_friendship(id_or_screenname) ⇒ Object
Befriends id_or_screenname for the auth user
100 101 102 |
# File 'lib/twitter/base.rb', line 100 def create_friendship(id_or_screenname) users(request("friendships/create/#{id_or_screenname}.xml", :auth => true, :method => :post)).first end |
#d(user, text) ⇒ Object
Sends a direct message text
to user
95 96 97 |
# File 'lib/twitter/base.rb', line 95 def d(user, text) DirectMessage.new_from_xml(request('direct_messages/new.xml', :auth => true, :method => :post, :form_data => {'text' => text, 'user' => user})) end |
#destroy(id) ⇒ Object
Destroys a status by id
63 64 65 |
# File 'lib/twitter/base.rb', line 63 def destroy(id) call("destroy/#{id}") end |
#destroy_direct_message(id) ⇒ Object
destroys a give direct message by id if the auth user is a recipient
90 91 92 |
# File 'lib/twitter/base.rb', line 90 def (id) DirectMessage.new_from_xml(request("direct_messages/destroy/#{id}.xml", :auth => true, :method => :post)) end |
#destroy_favorite(id) ⇒ Object
Un-favorites the status specified by id for the auth user
146 147 148 |
# File 'lib/twitter/base.rb', line 146 def destroy_favorite(id) statuses(request("favorites/destroy/#{id}.xml", :auth => true, :method => :post)).first end |
#destroy_friendship(id_or_screenname) ⇒ Object
Defriends id_or_screenname for the auth user
105 106 107 |
# File 'lib/twitter/base.rb', line 105 def destroy_friendship(id_or_screenname) users(request("friendships/destroy/#{id_or_screenname}.xml", :auth => true, :method => :post)).first end |
#direct_messages(options = {}) ⇒ Object Also known as: received_messages
Returns an array of all the direct messages for the authenticated user
77 78 79 80 |
# File 'lib/twitter/base.rb', line 77 def (={}) doc = request(build_path('direct_messages.xml', ()), {:auth => true, :since => [:since]}) (doc/:direct_message).inject([]) { |dms, dm| dms << DirectMessage.new_from_xml(dm); dms } end |
#favorites(options = {}) ⇒ Object
Returns the most recent favorite statuses for the autenticating user
136 137 138 |
# File 'lib/twitter/base.rb', line 136 def favorites(={}) statuses(request(build_path('favorites.xml', ()), :auth => true)) end |
#featured ⇒ Object
waiting for twitter to correctly implement this in the api as it is documented
72 73 74 |
# File 'lib/twitter/base.rb', line 72 def featured users(call(:featured)) end |
#follow(id_or_screenname) ⇒ Object
Turns notifications by id_or_screenname on for auth user.
126 127 128 |
# File 'lib/twitter/base.rb', line 126 def follow(id_or_screenname) users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true, :method => :post)).first end |
#followers(options = {}) ⇒ Object
Returns an array of users who are following you
39 40 41 |
# File 'lib/twitter/base.rb', line 39 def followers(={}) users(call(:followers, {:args => ()})) end |
#followers_for(id, options = {}) ⇒ Object
43 44 45 |
# File 'lib/twitter/base.rb', line 43 def followers_for(id, ={}) followers(.merge({:id => id})) end |
#friends(options = {}) ⇒ Object
Returns an array of users who are in your friends list
29 30 31 |
# File 'lib/twitter/base.rb', line 29 def friends(={}) users(call(:friends, {:args => ()})) end |
#friends_for(id, options = {}) ⇒ Object
Returns an array of users who are friends for the id or username passed in
34 35 36 |
# File 'lib/twitter/base.rb', line 34 def friends_for(id, ={}) friends(.merge({:id => id})) end |
#friendship_exists?(user_a, user_b) ⇒ Boolean
Returns true if friendship exists, false if it doesn’t.
110 111 112 113 |
# File 'lib/twitter/base.rb', line 110 def friendship_exists?(user_a, user_b) doc = request(build_path("friendships/exists.xml", {:user_a => user_a, :user_b => user_b}), :auth => true) doc.at('friends').innerHTML == 'true' ? true : false end |
#leave(id_or_screenname) ⇒ Object
Turns notifications by id_or_screenname off for auth user.
131 132 133 |
# File 'lib/twitter/base.rb', line 131 def leave(id_or_screenname) users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true, :method => :post)).first end |
#post(status, options = {}) ⇒ Object Also known as: update
Posts a new update to twitter for auth user.
161 162 163 164 165 166 |
# File 'lib/twitter/base.rb', line 161 def post(status, ={}) form_data = {'status' => status} form_data.merge!({'source' => [:source]}) if [:source] form_data.merge!({'in_reply_to_status_id' => [:in_reply_to_status_id]}) if [:in_reply_to_status_id] Status.new_from_xml(request('statuses/update.xml', :auth => true, :method => :post, :form_data => form_data)) end |
#rate_limit_status ⇒ Object
67 68 69 |
# File 'lib/twitter/base.rb', line 67 def rate_limit_status RateLimitStatus.new_from_xml request("account/rate_limit_status.xml", :auth => true) end |
#replies(options = {}) ⇒ Object
Returns an array of statuses that are replies
58 59 60 |
# File 'lib/twitter/base.rb', line 58 def replies(={}) statuses(call(:replies, :since => [:since], :args => ())) end |
#sent_messages(options = {}) ⇒ Object
Returns direct messages sent by auth user
84 85 86 87 |
# File 'lib/twitter/base.rb', line 84 def (={}) doc = request(build_path('direct_messages/sent.xml', ()), {:auth => true, :since => [:since]}) (doc/:direct_message).inject([]) { |dms, dm| dms << DirectMessage.new_from_xml(dm); dms } end |
#status(id) ⇒ Object
Returns a single status for a given id
48 49 50 |
# File 'lib/twitter/base.rb', line 48 def status(id) statuses(call("show/#{id}")).first end |
#timeline(which = :friends, options = {}) ⇒ Object
Returns an array of statuses for a timeline; Defaults to your friends timeline.
22 23 24 25 26 |
# File 'lib/twitter/base.rb', line 22 def timeline(which=:friends, ={}) raise UnknownTimeline unless [:friends, :public, :user].include?(which) auth = which.to_s.include?('public') ? false : true statuses(call("#{which}_timeline", :auth => auth, :since => [:since], :args => ())) end |
#unblock(id) ⇒ Object
Unblocks the user specified by id for the auth user
156 157 158 |
# File 'lib/twitter/base.rb', line 156 def unblock(id) users(request("blocks/destroy/#{id}.xml", :auth => true, :method => :post)).first end |
#update_delivery_device(device) ⇒ Object
Updates your deliver device and returns Twitter::User object
121 122 123 |
# File 'lib/twitter/base.rb', line 121 def update_delivery_device(device) users(request(build_path('account/update_delivery_device.xml', {'device' => device}), :auth => true, :method => :post)).first end |
#update_location(location) ⇒ Object
Updates your location and returns Twitter::User object
116 117 118 |
# File 'lib/twitter/base.rb', line 116 def update_location(location) users(request(build_path('account/update_location.xml', {'location' => location}), :auth => true, :method => :post)).first end |
#user(id_or_screenname) ⇒ Object
returns all the profile information and the last status for a user
53 54 55 |
# File 'lib/twitter/base.rb', line 53 def user(id_or_screenname) users(request("users/show/#{id_or_screenname}.xml", :auth => true)).first end |
#verify_credentials ⇒ Object
Verifies the credentials for the auth user.
raises Twitter::CantConnect on failure.
171 172 173 |
# File 'lib/twitter/base.rb', line 171 def verify_credentials request('account/verify_credentials.xml', :auth => true) end |