Sha256: 5d3f4144266887b15477b57054ebd44f0f07e8dd2933255d15891e3ac1b0d6c2

Contents?: true

Size: 769 Bytes

Versions: 7

Compression:

Stored size: 769 Bytes

Contents

require_relative 'deliver_reply'
require_relative 'status_reply'

module SmsTraffic
  class Client
    class Response
      attr_reader :origin, :reply, :code, :body, :message

      REPLY_HASH_MAP = {
        :status  => StatusReply,
        :deliver => DeliverReply,
        nil      => Reply
      }.freeze

      def initialize(response, type: nil)
        @origin = response
        @code = response.code.to_i
        @body = response.body
        @message = response.message

        return unless success?

        @reply = REPLY_HASH_MAP[type].new(body)
      end

      def success?
        code == 200
      end

      def failure?
        !success?
      end

      def error_description
        "#{code}: #{message}" if failure?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sms_traffic_sdk-0.0.7 lib/sms_traffic/client/response.rb
sms_traffic_sdk-0.0.6 lib/sms_traffic/client/response.rb
sms_traffic_sdk-0.0.5 lib/sms_traffic/client/response.rb
sms_traffic_sdk-0.0.4 lib/sms_traffic/client/response.rb
sms_traffic_sdk-0.0.3 lib/sms_traffic/client/response.rb
sms_traffic_sdk-0.0.2 lib/sms_traffic/client/response.rb
sms_traffic_sdk-0.0.1 lib/sms_traffic/client/response.rb