Created
July 7, 2022 05:46
-
-
Save sdthornton/0398aabe02bc083c1a4e1e2ea9339002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Steven::Rocks | |
def self.get_icon(appkey, token) | |
# Set temp path | |
path = "/tmp/submit/_icons" | |
# Create temp directory if it doesn't exist | |
if !File.directory?(path) | |
FileUtils.mkdir_p(path) | |
end | |
# Transform the URL string to a readable URI class | |
url = URI("https://artwork.subsplash.com/images/cdn/#{appkey}/540/405/ios/icon.png?release_team_cache_bust=sus") | |
# Get the HTTP Response from the url (which includes the response.body, which is the png data) | |
res = Net::HTTP.get_response(url) | |
# Open (or create) and write ("w" option) to the path/appkey.png file and pass that file as "f" into the block | |
# (The "b" option just prevents any changes between mac and windows) | |
File.open("#{path}/#{appkey}.png", "wb") do |f| | |
# Write to the file (f) the contents of res.body (from Http request) | |
f.write(res.body) | |
end | |
end | |
end | |
class Steven::RocksHarder | |
# Optionally, include the open-uri class to make use of the simple "open" method | |
require 'open-uri' | |
def self.get_icon(appkey, token) | |
path = "/tmp/submit/_icons" | |
if !File.directory?(path) | |
FileUtils.mkdir_p(path) | |
end | |
# Open the contents of the image and pass it into the block, simply as "image" | |
open("https://artwork.subsplash.com/images/cdn/#{appkey}/540/405/ios/icon.png?release_team_cache_bust=sus") do |image| | |
File.open("#{path}/#{appkey}.png", "wb") do |f| | |
f.write(res.body) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment