Module: Birdsong

Extended by:
Configuration
Defined in:
lib/birdsong.rb,
lib/birdsong/user.rb,
lib/birdsong/tweet.rb,
lib/birdsong/version.rb,
lib/birdsong/scrapers/scraper.rb,
lib/birdsong/scrapers/tweet_scraper.rb

Defined Under Namespace

Classes: AuthorizationError, Error, InvalidIdError, InvalidMediaTypeError, NoTweetFoundError, RateLimitExceeded, Scraper, Tweet, TweetScraper, User, WebDriverError

Constant Summary collapse

VERSION =
"0.2.9"

Class Method Summary collapse

Methods included from Configuration

configuration, define_setting

Class Method Details

.retrieve_media(url) ⇒ Object

Get media from a URL and save to a temp folder set in the configuration under temp_storage_location



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/birdsong.rb', line 57

def self.retrieve_media(url)
  return "" if !Birdsong.save_media

  response = Typhoeus.get(url)

  # Get the file extension if it's in the file
  extension = url.split(".").last

  # Do some basic checks so we just empty out if there's something weird in the file extension
  # that could do some harm.
  if extension.length.positive?
    extension = extension[0...extension.index("?")]
    extension = nil unless /^[a-zA-Z0-9]+$/.match?(extension)
    extension = ".#{extension}" unless extension.nil?
  end

  temp_file_name = "#{Birdsong.temp_storage_location}/#{SecureRandom.uuid}#{extension}"

  # We do this in case the folder isn't created yet, since it's a temp folder we'll just do so
  self.create_temp_storage_location
  File.binwrite(temp_file_name, response.body)
  temp_file_name
end

.tweet_fieldsObject

The general fields to always return for Tweets



51
52
53
# File 'lib/birdsong.rb', line 51

def self.tweet_fields
  "attachments,author_id,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang"
end

.user_fieldsObject

The general fields to always return for Users



46
47
48
# File 'lib/birdsong.rb', line 46

def self.user_fields
  "name,created_at,location,profile_image_url,protected,public_metrics,url,username,verified,withheld,description"
end