-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitterhelper_mock.rb
More file actions
38 lines (31 loc) · 991 Bytes
/
twitterhelper_mock.rb
File metadata and controls
38 lines (31 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'twitter'
class TwitterHelper
def self.twitter_client
# normally you would generate your bearer token
Twitter::REST::Client.new do |config|
config.bearer_token = "XXX"
end
end
def self.twitter_user_info
$twitter_user_info ||= []
end
def self.twitter_error
$twitter_error ||= nil
end
def self.tweets
twitter_handle = "loadtocode"
twitter_user_info[1] = twitter_client.user(twitter_handle).name
twitter_user_info[2] = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false}.take(3)
twitter_user_info
rescue Twitter::Error::BadRequest
$twitter_error = "Oh no! no. no. no."
rescue Twitter::Error::Unauthorized
puts "Tweets can't be shown"
$twitter_error = "Oh no!"
rescue Twitter::Error::Forbidden
rescue Twitter::Error::NotAcceptable
rescue Twitter::Error::TooManyRequests
end
end
# TwitterHelper.new
# puts TwitterHelper.tweets