diff --git a/app/models/pet.rb b/app/models/pet.rb index 13530018..8973a11a 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -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) diff --git a/lib/rocketamf/remote_gateway.rb b/lib/rocketamf_extensions/remote_gateway.rb similarity index 70% rename from lib/rocketamf/remote_gateway.rb rename to lib/rocketamf_extensions/remote_gateway.rb index cc48e25c..00b7c922 100644 --- a/lib/rocketamf/remote_gateway.rb +++ b/lib/rocketamf_extensions/remote_gateway.rb @@ -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 diff --git a/lib/rocketamf/remote_gateway/action.rb b/lib/rocketamf_extensions/remote_gateway/action.rb similarity index 79% rename from lib/rocketamf/remote_gateway/action.rb rename to lib/rocketamf_extensions/remote_gateway/action.rb index eefbcd57..a0444d2c 100644 --- a/lib/rocketamf/remote_gateway/action.rb +++ b/lib/rocketamf_extensions/remote_gateway/action.rb @@ -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 diff --git a/lib/rocketamf/remote_gateway/request.rb b/lib/rocketamf_extensions/remote_gateway/request.rb similarity index 91% rename from lib/rocketamf/remote_gateway/request.rb rename to lib/rocketamf_extensions/remote_gateway/request.rb index 4dcaafda..d102b6c3 100644 --- a/lib/rocketamf/remote_gateway/request.rb +++ b/lib/rocketamf_extensions/remote_gateway/request.rb @@ -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 diff --git a/lib/rocketamf/remote_gateway/service.rb b/lib/rocketamf_extensions/remote_gateway/service.rb similarity index 79% rename from lib/rocketamf/remote_gateway/service.rb rename to lib/rocketamf_extensions/remote_gateway/service.rb index 6f19aa74..4f79ea0a 100644 --- a/lib/rocketamf/remote_gateway/service.rb +++ b/lib/rocketamf_extensions/remote_gateway/service.rb @@ -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