1
0
Fork 0
forked from OpenNeo/impress

Move lib/rocketamf -> lib/rocketamf_extensions, to fix reload issues

Something in the Rails loader doesn't like that I have both a gem and
a lib folder named `RocketAMF`, I think? It'll often work for the first
pet load request, then on subsequent ones say `Envelope` is not
defined, I'm guessing because it scrapped the gem's module in favor of
mine?

Idk, let's just simplify all this by making our own module. I feel like
this old lib could use an overhaul and simplification anyway, but this
will do for now!
This commit is contained in:
Emi Matchu 2024-01-24 00:59:11 -08:00
parent 0406a32444
commit b0e7f2ccd5
5 changed files with 15 additions and 15 deletions

View file

@ -1,10 +1,10 @@
require 'rocketamf/remote_gateway' require 'rocketamf_extensions/remote_gateway'
require 'ostruct' require 'ostruct'
class Pet < ApplicationRecord class Pet < ApplicationRecord
NEOPETS_URL_ORIGIN = ENV['NEOPETS_URL_ORIGIN'] || 'https://www.neopets.com' NEOPETS_URL_ORIGIN = ENV['NEOPETS_URL_ORIGIN'] || 'https://www.neopets.com'
GATEWAY_URL = NEOPETS_URL_ORIGIN + '/amfphp/gateway.php' GATEWAY_URL = NEOPETS_URL_ORIGIN + '/amfphp/gateway.php'
PET_VIEWER = RocketAMF::RemoteGateway.new(GATEWAY_URL). PET_VIEWER = RocketAMFExtensions::RemoteGateway.new(GATEWAY_URL).
service('CustomPetService').action('getViewerData') service('CustomPetService').action('getViewerData')
PET_NOT_FOUND_REMOTE_ERROR = 'PHP: Unable to retrieve records from the database.' PET_NOT_FOUND_REMOTE_ERROR = 'PHP: Unable to retrieve records from the database.'
WARDROBE_PATH = '/wardrobe' WARDROBE_PATH = '/wardrobe'
@ -110,12 +110,12 @@ class Pet < ApplicationRecord
'Cookie' => "lang=#{neopets_language_code}" 'Cookie' => "lang=#{neopets_language_code}"
} }
) )
rescue RocketAMF::RemoteGateway::AMFError => e rescue RocketAMFExtensions::RemoteGateway::AMFError => e
if e.message == PET_NOT_FOUND_REMOTE_ERROR if e.message == PET_NOT_FOUND_REMOTE_ERROR
raise PetNotFound, "Pet #{name.inspect} does not exist" raise PetNotFound, "Pet #{name.inspect} does not exist"
end end
raise DownloadError, e.message raise DownloadError, e.message
rescue RocketAMF::RemoteGateway::ConnectionError => e rescue RocketAMFExtensions::RemoteGateway::ConnectionError => e
raise DownloadError, e.message, e.backtrace raise DownloadError, e.message, e.backtrace
end end
HashWithIndifferentAccess.new(envelope.messages[0].data.body) HashWithIndifferentAccess.new(envelope.messages[0].data.body)

View file

@ -1,8 +1,8 @@
require 'net/http' require 'net/http'
require 'rocketamf' require 'rocketamf'
require File.join(File.dirname(__FILE__), 'remote_gateway', 'service') require_relative 'remote_gateway/service'
module RocketAMF module RocketAMFExtensions
class RemoteGateway class RemoteGateway
attr_reader :uri attr_reader :uri

View file

@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), 'request') require_relative 'request'
module RocketAMF module RocketAMFExtensions
class RemoteGateway class RemoteGateway
class Action class Action
attr_reader :service, :name attr_reader :service, :name

View file

@ -1,6 +1,6 @@
require 'timeout' require 'timeout'
module RocketAMF module RocketAMFExtensions
class RemoteGateway class RemoteGateway
class Request class Request
ERROR_CODE = 'AMFPHP_RUNTIME_ERROR' ERROR_CODE = 'AMFPHP_RUNTIME_ERROR'
@ -51,7 +51,7 @@ module RocketAMF
first_message_data = HashWithIndifferentAccess.new(result.messages[0].data) first_message_data = HashWithIndifferentAccess.new(result.messages[0].data)
if first_message_data.respond_to?(:[]) && first_message_data[:code] == ERROR_CODE if first_message_data.respond_to?(:[]) && first_message_data[:code] == ERROR_CODE
raise AMFError.new(first_message_data) raise RocketAMF::AMFError.new(first_message_data)
end end
result result
@ -60,17 +60,17 @@ module RocketAMF
private private
def envelope def envelope
output = Envelope.new output = RocketAMF::Envelope.new
output.messages << wrapper_message output.messages << wrapper_message
output output
end end
def wrapper_message def wrapper_message
message = Message.new 'null', '/1', [remoting_message] message = RocketAMF::Message.new 'null', '/1', [remoting_message]
end end
def remoting_message def remoting_message
message = Values::RemotingMessage.new message = RocketAMF::Values::RemotingMessage.new
message.source = @action.service.name message.source = @action.service.name
message.operation = @action.name message.operation = @action.name
message.body = @params message.body = @params

View file

@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), 'action') require_relative 'action'
module RocketAMF module RocketAMFExtensions
class RemoteGateway class RemoteGateway
class Service class Service
attr_reader :gateway, :name attr_reader :gateway, :name