Class: Tw::Client
- Inherits:
-
Object
- Object
- Tw::Client
- Defined in:
- lib/tw/client/auth.rb,
lib/tw/client/request.rb
Defined Under Namespace
Classes: Stream
Class Method Summary collapse
Instance Method Summary collapse
- #auth(user = nil) ⇒ Object
- #destroy_status(status_id) ⇒ Object
- #direct_message_create(to, message) ⇒ Object
- #direct_messages ⇒ Object
- #favorite(status_id) ⇒ Object
- #home_timeline ⇒ Object
- #list_timeline(user, list) ⇒ Object
- #mentions ⇒ Object
- #retweet(status_id) ⇒ Object
- #search(word) ⇒ Object
- #show_status(status_id) ⇒ Object
- #tweet(message, opts = {}) ⇒ Object
- #tweet_with_file(message, file, opts = {}) ⇒ Object
- #user_timeline(user) ⇒ Object
Class Method Details
.client ⇒ Object
3 4 5 |
# File 'lib/tw/client/auth.rb', line 3 def self.client @@client end |
.client=(client) ⇒ Object
7 8 9 |
# File 'lib/tw/client/auth.rb', line 7 def self.client=(client) @@client = client end |
Instance Method Details
#auth(user = nil) ⇒ Object
11 12 13 |
# File 'lib/tw/client/auth.rb', line 11 def auth(user=nil) self.class.client = @rest_client = Auth.auth(user) end |
#destroy_status(status_id) ⇒ Object
114 115 116 |
# File 'lib/tw/client/request.rb', line 114 def destroy_status(status_id) @rest_client.destroy_status status_id end |
#direct_message_create(to, message) ⇒ Object
90 91 92 93 94 |
# File 'lib/tw/client/request.rb', line 90 def (to, ) res = @rest_client. to, puts res.text puts res.created_at end |
#direct_messages ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tw/client/request.rb', line 59 def [@rest_client..map{|m| Tw::Tweet.new(:id => m.id, :user => m.sender.screen_name, :text => m.text, :time => m.created_at) }, @rest_client..map{|m| Tw::Tweet.new(:id => m.id, :user => { :from => m.sender.screen_name, :to => m.recipient.screen_name }, :text => m.text, :time => m.created_at) }].flatten end |
#favorite(status_id) ⇒ Object
106 107 108 |
# File 'lib/tw/client/request.rb', line 106 def favorite(status_id) @rest_client.favorite status_id end |
#home_timeline ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tw/client/request.rb', line 26 def home_timeline @rest_client.home_timeline.map{|m| Tw::Tweet.new(:id => m.id, :user => m.user.screen_name, :text => m.text, :time => m.created_at, :fav_count => m.favorite_count, :rt_count => m.retweet_count) } end |
#list_timeline(user, list) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tw/client/request.rb', line 48 def list_timeline(user,list) @rest_client.list_timeline(user, list).map{|m| Tw::Tweet.new(:id => m.id, :user => m.user.screen_name, :text => m.text, :time => m.created_at, :fav_count => m.favorite_count, :rt_count => m.retweet_count) } end |
#mentions ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/tw/client/request.rb', line 4 def mentions @rest_client.mentions.map{|m| Tw::Tweet.new(:id => m.id, :user => m.user.screen_name, :text => m.text, :time => m.created_at, :fav_count => m.favorite_count, :rt_count => m.retweet_count) } end |
#retweet(status_id) ⇒ Object
110 111 112 |
# File 'lib/tw/client/request.rb', line 110 def retweet(status_id) @rest_client.retweet status_id end |
#search(word) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tw/client/request.rb', line 15 def search(word) @rest_client.search(word).take(20).map{|m| Tw::Tweet.new(:id => m.id, :user => m.user.screen_name, :text => m.text, :time => m.created_at, :fav_count => m.favorite_count, :rt_count => m.retweet_count) } end |
#show_status(status_id) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/tw/client/request.rb', line 96 def show_status(status_id) res = @rest_client.status(status_id) line = CGI.unescapeHTML res.text line += " #{res.favorite_count}Fav" if res.favorite_count.to_i > 0 line += " #{res.retweet_count}RT" if res.retweet_count.to_i > 0 puts line.colorize(/@[a-zA-Z0-9_]+|\d+RT|\d+Fav/) puts "http://twitter.com/#{res.user.screen_name}/status/#{res.id}" puts res.created_at end |
#tweet(message, opts = {}) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/tw/client/request.rb', line 76 def tweet(, opts={}) res = @rest_client.update , opts puts res.text puts "http://twitter.com/#{res.user.screen_name}/status/#{res.id}" puts res.created_at end |
#tweet_with_file(message, file, opts = {}) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/tw/client/request.rb', line 83 def tweet_with_file(, file, opts={}) res = @rest_client.update_with_media , file, opts puts res.text puts "http://twitter.com/#{res.user.screen_name}/status/#{res.id}" puts res.created_at end |
#user_timeline(user) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tw/client/request.rb', line 37 def user_timeline(user) @rest_client.user_timeline(user).map{|m| Tw::Tweet.new(:id => m.id, :user => m.user.screen_name, :text => m.text, :time => m.created_at, :fav_count => m.favorite_count, :rt_count => m.retweet_count) } end |