From f8e4e8372369043675b49a1d63351b5d03470561 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 16 Apr 2024 15:57:39 -0700 Subject: [PATCH] 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!) --- app/models/pet.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/pet.rb b/app/models/pet.rb index 04f6bc1d..a4aa5214 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -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