Sha256: 8f58f0baac3d63c33e2ae1408f2c71092030ecadf62546f077fc33d3f39ad88e

Contents?: true

Size: 889 Bytes

Versions: 2

Compression:

Stored size: 889 Bytes

Contents

module MooMoo
  module OpenSRS
    class Response
      # Constructor
      #
      # ==== Required
      #  * <tt>:hash</tt> - hash of the response
      #
      # ==== Optional
      #  * <tt>:key</tt> - primary key to use when indexing the hash
      def initialize(hash, key = nil)
        @hash = hash
        @key = key
      end

      # Returns whether or not the command executed was successful
      #
      def success?
        @hash['is_success'].nil? ? true : @hash['is_success'].to_i == 1
      end

      # Returns the error message if one is present
      #
      def error_msg
        @hash['response_text']
      end

      # Returns the response code if one is present
      #
      def error_code
        @hash['response_code'].to_i
      end

      # Returns the result hash
      #
      def result
        @key.nil? ? @hash : @hash[@key]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moo_moo-0.1.1 lib/moo_moo/opensrs/response.rb
moo_moo-0.1.0 lib/moo_moo/opensrs/response.rb