Sha256: fa8482dd9309eb7a17561d837df870954eccac87c610b7077cbcec8220d61965

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module SmsBroker
  module Client
    class OpenMarket < Base
      def initialize(options)
        client = ::OpenMarket::SMS::Client.new(
          account_id: options[:account_id],
          account_password: options[:account_password]
        )

        super :open_market, client, options
      end

      def send_message(message)
        response = client.send_message \
          text: message[:text],
          from: message[:from],
          to: message[:to]

        if success_response?(response)
          Response::OpenMarket::SendMessageSuccess.new(response)
        else
          Response::OpenMarket::Error.new(response)
        end
      end

      def send_voice_message(_message)
        message = 'openmarket voice message is not implemented'
        exception = \
          Exceptions::NotImplemented.new(message)

        raise exception
      end

      def message_status(params)
        response = client.message_status \
          ticket_id: params[:message_id]

        if success_response?(response)
          Response::OpenMarket::MessageStatusSuccess.new(response)
        else
          Response::OpenMarket::Error.new(response)
        end
      end

      private

      def success_response?(response)
        response.success?
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sms_broker-1.0.8 lib/sms_broker/client/open_market.rb
sms_broker-1.0.7 lib/sms_broker/client/open_market.rb