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:
parent
0406a32444
commit
b0e7f2ccd5
5 changed files with 15 additions and 15 deletions
|
@ -1,10 +1,10 @@
|
|||
require 'rocketamf/remote_gateway'
|
||||
require 'rocketamf_extensions/remote_gateway'
|
||||
require 'ostruct'
|
||||
|
||||
class Pet < ApplicationRecord
|
||||
NEOPETS_URL_ORIGIN = ENV['NEOPETS_URL_ORIGIN'] || 'https://www.neopets.com'
|
||||
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')
|
||||
PET_NOT_FOUND_REMOTE_ERROR = 'PHP: Unable to retrieve records from the database.'
|
||||
WARDROBE_PATH = '/wardrobe'
|
||||
|
@ -110,12 +110,12 @@ class Pet < ApplicationRecord
|
|||
'Cookie' => "lang=#{neopets_language_code}"
|
||||
}
|
||||
)
|
||||
rescue RocketAMF::RemoteGateway::AMFError => e
|
||||
rescue RocketAMFExtensions::RemoteGateway::AMFError => e
|
||||
if e.message == PET_NOT_FOUND_REMOTE_ERROR
|
||||
raise PetNotFound, "Pet #{name.inspect} does not exist"
|
||||
end
|
||||
raise DownloadError, e.message
|
||||
rescue RocketAMF::RemoteGateway::ConnectionError => e
|
||||
rescue RocketAMFExtensions::RemoteGateway::ConnectionError => e
|
||||
raise DownloadError, e.message, e.backtrace
|
||||
end
|
||||
HashWithIndifferentAccess.new(envelope.messages[0].data.body)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'net/http'
|
||||
require 'rocketamf'
|
||||
require File.join(File.dirname(__FILE__), 'remote_gateway', 'service')
|
||||
require_relative 'remote_gateway/service'
|
||||
|
||||
module RocketAMF
|
||||
module RocketAMFExtensions
|
||||
class RemoteGateway
|
||||
attr_reader :uri
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
require File.join(File.dirname(__FILE__), 'request')
|
||||
require_relative 'request'
|
||||
|
||||
module RocketAMF
|
||||
module RocketAMFExtensions
|
||||
class RemoteGateway
|
||||
class Action
|
||||
attr_reader :service, :name
|
|
@ -1,6 +1,6 @@
|
|||
require 'timeout'
|
||||
|
||||
module RocketAMF
|
||||
module RocketAMFExtensions
|
||||
class RemoteGateway
|
||||
class Request
|
||||
ERROR_CODE = 'AMFPHP_RUNTIME_ERROR'
|
||||
|
@ -51,7 +51,7 @@ module RocketAMF
|
|||
|
||||
first_message_data = HashWithIndifferentAccess.new(result.messages[0].data)
|
||||
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
|
||||
|
||||
result
|
||||
|
@ -60,17 +60,17 @@ module RocketAMF
|
|||
private
|
||||
|
||||
def envelope
|
||||
output = Envelope.new
|
||||
output = RocketAMF::Envelope.new
|
||||
output.messages << wrapper_message
|
||||
output
|
||||
end
|
||||
|
||||
def wrapper_message
|
||||
message = Message.new 'null', '/1', [remoting_message]
|
||||
message = RocketAMF::Message.new 'null', '/1', [remoting_message]
|
||||
end
|
||||
|
||||
def remoting_message
|
||||
message = Values::RemotingMessage.new
|
||||
message = RocketAMF::Values::RemotingMessage.new
|
||||
message.source = @action.service.name
|
||||
message.operation = @action.name
|
||||
message.body = @params
|
|
@ -1,6 +1,6 @@
|
|||
require File.join(File.dirname(__FILE__), 'action')
|
||||
require_relative 'action'
|
||||
|
||||
module RocketAMF
|
||||
module RocketAMFExtensions
|
||||
class RemoteGateway
|
||||
class Service
|
||||
attr_reader :gateway, :name
|
Loading…
Reference in a new issue