Sha256: bb0bfd0771318e6700865839d5ca9e274769c61cef53c9e1ec0207c9946829ee

Contents?: true

Size: 811 Bytes

Versions: 11

Compression:

Stored size: 811 Bytes

Contents

#require 'struct'

module MxHero
  module API

    # The class that contains the response information
    #
    # The *code* represent the HTTP code of the response.
    #
    # The *msg* represent a hash with the response information. Example:
    #
    #     { status: 500, code: 500,
    #       developerMessage: "rules.already.exists.for.component",
    #       moreInfoUrl: "mailto:support@mxhero.com" }
    #
    class Response < Struct.new(:code, :msg)

      # Response is successful? Based in HTTP status code
      def success?
        code.to_i == 200 || code.to_i == 201
      end

      # @return [String] the error message
      def error
        content[:developerMessage] if content.is_a? Hash
      end

      alias_method :content, :msg
      alias_method :content=, :msg=
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mxhero-api-1.2.9 lib/response.rb
mxhero-api-1.2.8 lib/response.rb
mxhero-api-1.2.7 lib/response.rb
mxhero-api-1.2.6 lib/response.rb
mxhero-api-1.2.5 lib/response.rb
mxhero-api-1.2.4 lib/response.rb
mxhero-api-1.2.3 lib/response.rb
mxhero-api-1.2.2 lib/response.rb
mxhero-api-1.2.1 lib/response.rb
mxhero-api-1.2.0 lib/response.rb
mxhero-api-1.1.4 lib/response.rb