Sha256: 03c6b83fb34b19bdf8f39e447d15a3ff8023284398c0376949438c603930a3b7

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Mock
  module Twilio
    module Decorators
      module CustomerProfilesV1
        class CustomerProfileUpdate
          class << self
            def decorate(body, request)
              body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
              body["date_created"] = Time.current.rfc2822 if body["date_created"]

              parse_customer_profile_sid(body, request) if body["sid"]
              body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
              # Usually from pending-review to in-review
              body["status"] = request.data["Status"] if body["status"]

              body
            end

            def parse_customer_profile_sid(body, request)
              uri = URI(request.url)
              customer_profile_sid = uri.path.split('/')[3].split('.').first
              scheduler = Rufus::Scheduler.new
              scheduler.in '2s' do
                begin
                  response = Mock::Twilio::Webhooks::CustomerProfiles.trigger(customer_profile_sid, "in-review")

                  if response.status == 200
                    Mock::Twilio::Webhooks::CustomerProfiles.trigger(customer_profile_sid, "twilio-approved")
                  end
                rescue => e
                  puts e
                end
              end
              body["sid"] = customer_profile_sid
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mock-twilio-1.4 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-1.3.2 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-1.3.1 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-1.3.0 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-1.2.0 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-1.1.0 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-1.0.0 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
mock-twilio-0.8.0 lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb