Module: Zorki
- Extended by:
- Configuration
- Defined in:
- lib/zorki.rb,
lib/zorki/post.rb,
lib/zorki/user.rb,
lib/zorki/version.rb,
lib/zorki/scrapers/scraper.rb,
lib/zorki/scrapers/post_scraper.rb,
lib/zorki/scrapers/user_scraper.rb
Defined Under Namespace
Classes: ContentUnavailableError, Error, ImageRequestFailedError, ImageRequestTimedOutError, Post, PostScraper, RetryableError, Scraper, User, UserScraper
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.retrieve_media(url) ⇒ Object
Get an image from a URL and save to a temp folder set in the configuration under temp_storage_location.
Methods included from Configuration
Class Method Details
.retrieve_media(url) ⇒ Object
Get an image from a URL and save to a temp folder set in the configuration under temp_storage_location
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zorki.rb', line 46 def self.retrieve_media(url) response = Typhoeus.get(url) # Get the file extension if it's in the file stripped_url = url.split("?").first # remove URL query params extension = stripped_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 = nil unless /^[a-zA-Z0-9]+$/.match?(extension) extension = ".#{extension}" unless extension.nil? end temp_file_name = "#{Zorki.temp_storage_location}/instagram_media_#{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 |