Class: Mock::Twilio::Decorator
- Inherits:
-
Object
- Object
- Mock::Twilio::Decorator
- Defined in:
- lib/mock/twilio/decorator.rb
Constant Summary collapse
- ENDPOINTS =
{ api_2010: Mock::Twilio::Schemas::Api2010, messaging_v1: Mock::Twilio::Schemas::MessagingV1, customer_profiles_v1: Mock::Twilio::Schemas::CustomerProfilesV1, end_users_v1: Mock::Twilio::Schemas::EndUsersV1, supporting_documents_v1: Mock::Twilio::Schemas::SupportingDocumentsV1, phone_numbers_v2: Mock::Twilio::Schemas::PhoneNumbersV2, brands_registrations_a2p: Mock::Twilio::Schemas::BrandsRegistrationsA2p, trust_products_v1: Mock::Twilio::Schemas::TrustProductsV1 }
Class Method Summary collapse
Class Method Details
.call(body, request) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mock/twilio/decorator.rb', line 27 def call(body, request) body = JSON.parse(body) case body["status"] when 400..600 return body end schema = url_from(body, request) # return body decorate if needed return ENDPOINTS[schema].for(body, request) if schema body end |
.url_from(body, request) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mock/twilio/decorator.rb', line 42 def url_from(body, request) url = request.url.split(request.host).last case url when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/} :api_2010 when %r{\/v1\/Services\/\w{34}} :messaging_v1 when %r{\/v1/CustomerProfiles} :customer_profiles_v1 when %r{\/v1/EndUsers} :end_users_v1 when %r{\/v1/SupportingDocuments} :supporting_documents_v1 when %r{\/v2/PhoneNumbers} :phone_numbers_v2 when %r{\/v1/a2p/BrandRegistrations} :brands_registrations_a2p when %r{\/v1/TrustProducts} :trust_products_v1 end end |