Module: Morris
- Extended by:
- Configuration
- Defined in:
- lib/morris.rb,
lib/morris/post.rb,
lib/morris/user.rb,
lib/morris/version.rb,
lib/morris/scrapers/scraper.rb,
lib/morris/scrapers/post_scraper.rb,
lib/morris/scrapers/user_scraper.rb,
lib/morris/scrapers/video_scraper.rb
Defined Under Namespace
Classes: AccountNotFoundError, ContentUnavailableError, Error, MediaRequestFailedError, MediaRequestTimedOutError, Post, PostScraper, RetryableError, Scraper, User, UserScraper, VideoScraper
Constant Summary collapse
- VERSION =
"0.1.3"
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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/morris.rb', line 68 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 = "#{Morris.temp_storage_location}/morris_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 |