Module: Mosquito

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

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Methods included from Configuration

configuration, define_setting

Class Method Details

.retrieve_media(url, extension: nil) ⇒ Object

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mosquito.rb', line 52

def self.retrieve_media(url, extension: nil)
  return "" if url.nil?
  return "" if !Mosquito.save_media

  response = Typhoeus.get(url)

  # Get the file extension if it's in the file
  if extension.nil?
    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
  end

  temp_file_name = "#{Mosquito.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



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

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



41
42
43
# File 'lib/mosquito.rb', line 41

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