Class: BadPigeon::TweetExtractor

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/bad_pigeon/tweet_extractor.rb

Overview

The main entry point to the library. Pass the contents of a HAR archive file to #get_tweets_from_har and get a flat list of all extracted tweets in return.

Instance Method Summary collapse

Methods included from Assertions

extended, included

Constructor Details

#initializeTweetExtractor



16
17
18
# File 'lib/bad_pigeon/tweet_extractor.rb', line 16

def initialize
  @filter = EntryFilter.new
end

Instance Method Details

#get_tweets_from_har(har_data) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/bad_pigeon/tweet_extractor.rb', line 20

def get_tweets_from_har(har_data)
  archive = HARArchive.new(har_data)
  requests = archive.requests.select(&:includes_tweet_data?)

  timeline_entries = requests.map { |e| timeline_entries_from_request(e) }.flatten
  timeline_entries.select { |e| @filter.include_entry?(e) }.map(&:all_tweets).flatten
end

#timeline_entries_from_request(request) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/bad_pigeon/tweet_extractor.rb', line 28

def timeline_entries_from_request(request)
  endpoint = request.endpoint_name

  if timeline_class = TIMELINE_TYPES[endpoint]
    timeline_class.new(request.response_json).instructions.map(&:entries).flatten
  else
    debug "Unknown endpoint: #{endpoint}" unless TIMELINE_TYPES.has_key?(endpoint)
    []
  end
end