lib/mock/twilio/schemas/messaging_v1.rb in mock-twilio-0.6.0 vs lib/mock/twilio/schemas/messaging_v1.rb in mock-twilio-0.7.0
- old
+ new
@@ -3,18 +3,36 @@
module Mock
module Twilio
module Schemas
class MessagingV1
class << self
- def decorate(body, request)
+ def for(body, request)
+ phone_number_sid(body) if body["phone_numbers"].first["sid"]
+ body["phone_numbers"].first["account_sid"] = ::Twilio.account_sid if body["phone_numbers"].first["account_sid"]
+ parse_messaging_service_sid(body, request) if body["phone_numbers"].first["service_sid"]
+ body["phone_numbers"].first["phone_number"] = "987654321" if body["phone_numbers"].first["phone_number"]
+ body["phone_numbers"].first["country_code"] = "US" if body["phone_numbers"].first["country_code"]
+
# Params for twilio pagination, needed for twilio-ruby serializers and absolute paths
- body["meta"]["key"] = "phone_numbers" if body["meta"]
- body["meta"]["page_size"] = 20 if body["meta"]
- body["meta"]["first_page_url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=0" if body["meta"]
- body["meta"]["previous_page_url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=0" if body["meta"]
- body["meta"]["next_page_url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=1" if body["meta"]
- body["meta"]["url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=0" if body["meta"]
+ body["meta"]["key"] = "phone_numbers" if body["meta"]["key"]
+ body["meta"]["page_size"] = 20 if body["meta"]["page_size"]
+ body["meta"]["first_page_url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=0" if body["meta"]["first_page_url"]
+ body["meta"]["previous_page_url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=0" if body["meta"]["previous_page_url"]
+ body["meta"]["next_page_url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=1" if body["meta"]["next_page_url"]
+ body["meta"]["url"] = "https://messaging.twilio.com/v1/Services/MGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/PhoneNumbers?PageSize=20&Page=0" if body["meta"]["url"]
body
+ end
+
+ def phone_number_sid(body)
+ prefix = "PN"
+ sid = prefix + SecureRandom.hex(16)
+ body["phone_numbers"].first["sid"] = sid
+ end
+
+ def parse_messaging_service_sid(body, request)
+ uri = URI(request.url)
+ messaging_service_sid = uri.path.split('/')[3]
+ body["phone_numbers"].first["service_sid"] = messaging_service_sid
end
end
end
end
end