Sha256: 19394a971bf989ac63309b9c50027848bcc2d3fd81b7c3ad8ae9ccf4a6196c01

Contents?: true

Size: 734 Bytes

Versions: 4

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module Sberbank
  module Acquiring
    class CommandResponseDecorator
      extend Forwardable

      attr_reader :response
      def_delegators :response, :data, :http_response, :http, :request
      def_delegators :http, :body

      def initialize(response)
        @response = response
      end

      def error?
        data.nil? || data['errorCode'].to_i > 0
      end

      def success?
        !error?
      end

      def method_missing(name, *attrs)
        key = camelize_string(name.to_s)
        data.key?(key) ? data[key] : super
      end

      private

      def camelize_string(string)
        string.gsub(/_([a-z])/) { $1.upcase }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sberbank-acquiring-1.0.0 lib/sberbank/acquiring/command_response_decorator.rb
sberbank-acquiring-0.2.1 lib/sberbank/acquiring/command_response_decorator.rb
sberbank-acquiring-0.2.0 lib/sberbank/acquiring/command_response_decorator.rb
sberbank-acquiring-0.1.0 lib/sberbank/acquiring/command_response_decorator.rb