Class: ZooniverseSocial::Tweets

Inherits:
Object
  • Object
show all
Defined in:
lib/zooniverse_social/tweets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTweets

Returns a new instance of Tweets.



7
8
9
10
11
12
13
14
# File 'lib/zooniverse_social/tweets.rb', line 7

def initialize
  @twitter = Twitter::REST::Client.new({
    consumer_key: ENV.fetch('TWITTER_KEY'),
    consumer_secret: ENV.fetch('TWITTER_SECRET')
  })

  update
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/zooniverse_social/tweets.rb', line 5

def data
  @data
end

Instance Method Details

#updateObject



16
17
18
19
20
21
22
23
# File 'lib/zooniverse_social/tweets.rb', line 16

def update
  @data = @twitter.search('from:the_zooniverse', result_type: 'recent').take(3).collect do |tweet|
    tweet.to_h.tap do |hash|
      appended = hash.dig :entities, :urls, 0, :url
      hash[:text].sub!(/\s?#{ appended }/, '') if appended
    end
  end
end