Sha256: aea7ec986ac0f05c198f00ad7f8510a401c1437e24f6cfa14d0f2a22040f30d6

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Mock
  module Twilio
    module Webhooks
      class Messages < Base
        URL = "/api/v1/twilio_requests/webhook_message_updates"

        def self.trigger(sid)
          # Wait simulation from twilio
          sleep DELAY.sample

          request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL

          data = { :MessageSid=>sid, :MessageStatus=>"delivered" }

          signature = build_signature_for_request(request_url, data)

          response = webhook_client.request(Mock::Twilio.host,
                                            Mock::Twilio.port,
                                            'POST',
                                            URL,
                                            nil,
                                            data,
                                            headers.merge!({ 'X-Twilio-Signature': signature }),
                                            auth_twilio,
                                            nil)
          case response.status
          when 200..204
            response
          when 400..600
            raise Webhooks::RestError, Mock::Twilio::ErrorHandler.new(response).raise
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mock-twilio-1.3.2 lib/mock/twilio/webhooks/messages.rb
mock-twilio-1.3.1 lib/mock/twilio/webhooks/messages.rb
mock-twilio-1.3.0 lib/mock/twilio/webhooks/messages.rb
mock-twilio-1.2.0 lib/mock/twilio/webhooks/messages.rb
mock-twilio-1.1.0 lib/mock/twilio/webhooks/messages.rb
mock-twilio-1.0.0 lib/mock/twilio/webhooks/messages.rb
mock-twilio-0.8.0 lib/mock/twilio/webhooks/messages.rb