Class: MyTimeline::Twitter::TweetScraper

Inherits:
Object
  • Object
show all
Defined in:
app/scrapers/my_timeline/twitter/tweet_scraper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ TweetScraper

Returns a new instance of TweetScraper.



10
11
12
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 10

def initialize(user)
  @user = user
end

Instance Attribute Details

#tweetsObject

Returns the value of attribute tweets.



8
9
10
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 8

def tweets
  @tweets
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 8

def user
  @user
end

Instance Method Details

#builderObject



29
30
31
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 29

def builder
  @builder ||= MyTimeline::Twitter::TweetBuilder.new(user)
end

#load_tweetsObject



25
26
27
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 25

def load_tweets
  @tweets = twitter.user_timeline(@user.settings(:twitter).user_name, count: 200)
end

#scrapeObject



14
15
16
17
18
19
20
21
22
23
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 14

def scrape
  load_tweets
  @count = 0

  tweets.each do |tweet_hash|
    @count = @count + 1 if builder.build_tweet(tweet_hash)
  end

  @count
end

#twitterObject



33
34
35
36
37
38
39
40
# File 'app/scrapers/my_timeline/twitter/tweet_scraper.rb', line 33

def twitter
  @twitter ||= ::Twitter::REST::Client.new do |config|
    config.consumer_key        = MyTimeline::Twitter.consumer_key
    config.consumer_secret     = MyTimeline::Twitter.consumer_secret
    config.access_token        = MyTimeline::Twitter.access_token
    config.access_token_secret = MyTimeline::Twitter.access_token_secret
  end
end