Class: Mock::Twilio::Decorators::MessagingV1::PhoneNumberCreate

Inherits:
Object
  • Object
show all
Extended by:
Generator
Defined in:
lib/mock/twilio/decorators/messaging_v1/phone_number_create.rb

Class Method Summary collapse

Methods included from Generator

friendly_number_generator, phone_number_generator, random_account_sid, random_address_sid, random_assignment_sid, random_bundle_sid, random_identity_sid, random_latitude, random_longitude, random_phone_number_sid, random_twiml_app_sid

Class Method Details

.decorate(body, request) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mock/twilio/decorators/messaging_v1/phone_number_create.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"]

  phone_number_sid(body) if body["sid"]
  parse_messaging_service_sid(body, request) if body["service_sid"]

  body["account_sid"] = ::Twilio. if body["account_sid"]
  body["country_code"] = "US" if body["country_code"]
  body["capabilities"] = [] if body["capabilities"]
  body["phone_number"] = phone_number_generator if body["phone_number"]

  body
end

.parse_messaging_service_sid(body, request) ⇒ Object



32
33
34
35
36
# File 'lib/mock/twilio/decorators/messaging_v1/phone_number_create.rb', line 32

def parse_messaging_service_sid(body, request)
  uri = URI(request.url)
  messaging_service_sid = uri.path.split('/')[3]
  body["service_sid"] = messaging_service_sid
end

.phone_number_sid(body) ⇒ Object



26
27
28
29
30
# File 'lib/mock/twilio/decorators/messaging_v1/phone_number_create.rb', line 26

def phone_number_sid(body)
  prefix = "PN"
  sid = prefix + SecureRandom.hex(16)
  body["sid"] = sid
end