1
0
Fork 0
forked from OpenNeo/impress

To "fetch" the image hash of an image hash name, just take off the @!

A further optimization, this lets us use the image hash as the new hash
for the pet type if it would be useful! (whereas before this change,
we'd dip into `fetch_metadata` and just get back `nil`, which was okay
too but a little bit less helpful!)
This commit is contained in:
Emi Matchu 2024-04-16 15:57:39 -07:00
parent 3ea0842f00
commit f8e4e83723

View file

@ -151,6 +151,9 @@ class Pet < ApplicationRecord
# Given a pet's name, load its image hash, for use in `pets.neopets.com`
# image URLs. (This corresponds to its current biology and items.)
def self.fetch_image_hash(name, timeout: 10)
# If this is an image hash "pet name", just take off the `@`!
return name[1..] if name.start_with?("@")
metadata = fetch_metadata(name, timeout:)
metadata[:hash]
end