Class: Mock::Twilio::Decorators::CustomerProfilesV1::CustomerProfileUpdate

Inherits:
Object
  • Object
show all
Defined in:
lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb

Constant Summary collapse

@@scheduler =
Rufus::Scheduler.new

Class Method Summary collapse

Class Method Details

.decorate(body, request) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb', line 11

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. if body["account_sid"]
  # Usually from pending-review to in-review
  body["status"] = request.data["Status"] if body["status"]

  body
end

.parse_customer_profile_sid(body, request) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb', line 23

def parse_customer_profile_sid(body, request)
  uri = URI(request.url)
  customer_profile_sid = uri.path.split('/')[3].split('.').first
  @@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