Oops, fix sloppiness about pet service refactor
I guess I like super didn't test this end-to-end, oops!!
This commit is contained in:
parent
abfe1e6df7
commit
7607c2c015
3 changed files with 9 additions and 4 deletions
|
@ -1,13 +1,13 @@
|
||||||
class PetsController < ApplicationController
|
class PetsController < ApplicationController
|
||||||
rescue_from Pet::PetNotFound, with: :pet_not_found
|
rescue_from Neopets::CustomPets::PetNotFound, with: :pet_not_found
|
||||||
rescue_from Pet::DownloadError, with: :pet_download_error
|
rescue_from Neopets::CustomPets::DownloadError, with: :pet_download_error
|
||||||
rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format
|
rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format
|
||||||
|
|
||||||
def load
|
def load
|
||||||
# Uncomment this to temporarily disable modeling for most users.
|
# Uncomment this to temporarily disable modeling for most users.
|
||||||
# return modeling_disabled unless user_signed_in? && current_user.admin?
|
# return modeling_disabled unless user_signed_in? && current_user.admin?
|
||||||
|
|
||||||
raise Pet::PetNotFound unless params[:name]
|
raise Neopets::CustomPets::PetNotFound unless params[:name]
|
||||||
@pet = Pet.load(params[:name])
|
@pet = Pet.load(params[:name])
|
||||||
points = contribute(current_user, @pet)
|
points = contribute(current_user, @pet)
|
||||||
|
|
||||||
|
|
|
@ -114,5 +114,7 @@ class Pet < ApplicationRecord
|
||||||
pet.load!(**options)
|
pet.load!(**options)
|
||||||
pet
|
pet
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class UnexpectedDataFormat < RuntimeError;end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ module Neopets::CustomPets
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Send an AMFPHP request, re-raising errors as `Pet::DownloadError`.
|
# Send an AMFPHP request, re-raising errors as `DownloadError`.
|
||||||
# Return the response body as a `HashWithIndifferentAccess`.
|
# Return the response body as a `HashWithIndifferentAccess`.
|
||||||
def send_amfphp_request(request, timeout: 10)
|
def send_amfphp_request(request, timeout: 10)
|
||||||
begin
|
begin
|
||||||
|
@ -61,4 +61,7 @@ module Neopets::CustomPets
|
||||||
HashWithIndifferentAccess.new(response_data)
|
HashWithIndifferentAccess.new(response_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class PetNotFound < RuntimeError;end
|
||||||
|
class DownloadError < RuntimeError;end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue