Sha256: 30d301555bbf5bffd35078771b03b89de226ba50d1bf3cb37ba9a044927a03bf

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

require 'json'
module ActionTexter
  module Provider
    module Messagebird
      class Delivery
        attr_accessor :body
        attr_reader :response

        def initialize(settings)
          @endpoint = settings[:endpoint]
          @path = settings[:path]
        end

        def deliver message
          uri = URI.parse( @endpoint )
          Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
            @response = Response.new(http.post(@path, to_json(message), 'Authorization' => "AccessKey #{ActionTexter.config.product_token}", 'Content-Type' => 'application/json'))
          end
          response
        end

        def to_json message
            JSON.generate(recipients: message.to,
                          originator: message.from,
                          body: message.body)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action-texter-0.2.0.pre lib/action_texter/provider/messagebird/delivery.rb