Sha256: af52e3d7e781f66f2f5df8916568a8c91af3c12664eab56e05968fdff9b3a8fd

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

module AdaptivePayments
  # AbstractResponse provides a JsonModel with the default behaviour for all responses
  #
  # The ResponseEnvelope is already included by default.  It does not need to be redeclared in descendants.
  #
  # All responses have FaultMessage behaviour mixed in, so will behave as a FaultMessage if the API returns one.
  class AbstractResponse < JsonModel
    include FaultMessage

    # The ResponseEnvelope, encapsulating common information about the response
    #
    # All attributes #ack_code, #build, #correlation_id and #time are aliased as top-level attributes,
    # so you do not need to access #response_envelope directly.
    #
    # @see #success?, #failure?, #warning?, #success_with_warning?, #failure_with_warning?
    attribute :response_envelope, Node[ResponseEnvelope], :param => "responseEnvelope"

    alias_params :response_envelope, {
      :ack_code       => :ack_code,
      :build          => :build,
      :correlation_id => :correlation_id,
      :time           => :time
    }

    class << self
      # Set or get the API operation
      #
      # This method should be called in descendants, but is not currently used.
      #
      # @param [Symbol] name
      #   the name of the API operation as defined by PayPal, optional
      #
      # @return [Symbol]
      #   the name of the API operation as defined by PayPal
      def operation(name = nil)
        @operation = name unless name.nil?
        @operation
      end
    end

    # Provide status predicates for the possible response ack codes
    %w{success? failure? warning? success_with_warning? failure_with_warning?}.each do |method|
      define_method(method) { response_envelope.send(method) }
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
creative-pp-adaptive-1.1.1 lib/pp-adaptive/abstract_response.rb
pp-adaptive-1.0.0 lib/pp-adaptive/abstract_response.rb
pp-adaptive-0.0.6 lib/pp-adaptive/abstract_response.rb
pp-adaptive-0.0.5 lib/pp-adaptive/abstract_response.rb
pp-adaptive-0.0.4 lib/pp-adaptive/abstract_response.rb
pp-adaptive-0.0.3 lib/pp-adaptive/abstract_response.rb
pp-adaptive-0.0.2 lib/pp-adaptive/abstract_response.rb