Sha256: 46c0fb22032147c78c786a5f0e2dfef054a9f1a09803114bcc1e14d550b89291

Contents?: true

Size: 910 Bytes

Versions: 6

Compression:

Stored size: 910 Bytes

Contents

module SmsBroker
  module Client
    module Response
      class NexmoSuccess < Success
        def initialize(nexmo_response)
          super :nexmo, nexmo_response, serialize(nexmo_response)
        end

        private

        def serialize(response)
          single_response = response['messages'][0]

          {
            to: single_response['to'],
            from: single_response['from'],
            message_id: single_response['message-id'],
            raw: response_to_hash(single_response)
          }
        end

        def response_to_hash(response)
          attributes = %w(
            to from status network message-id client-ref
            remaining-balance message-price
          )

          {}.tap do |hash|
            attributes.each do |attr|
              hash[attr.tr('-', '_').to_sym] = response[attr]
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sms_broker-1.0.8 lib/sms_broker/client/response/nexmo_success.rb
sms_broker-1.0.7 lib/sms_broker/client/response/nexmo_success.rb
sms_broker-1.0.5 lib/sms_broker/client/response/nexmo_success.rb
sms_broker-1.0.4 lib/sms_broker/client/response/nexmo_success.rb
sms_broker-1.0.3 lib/sms_broker/client/response/nexmo_success.rb
sms_broker-1.0.2 lib/sms_broker/client/response/nexmo_success.rb