mock-twilio 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +21 -15
- data/lib/mock/twilio/decorators/api_2010/calls.rb +6 -3
- data/lib/mock/twilio/decorators/api_2010/incoming_phone_numbers.rb +29 -0
- data/lib/mock/twilio/decorators/customer_profiles_v1/channel_endpoint_assignments.rb +57 -0
- data/lib/mock/twilio/decorators/trust_products_v1/channel_endpoint_assignments.rb +57 -0
- data/lib/mock/twilio/schemas/api_2010.rb +4 -0
- data/lib/mock/twilio/schemas/customer_profiles_v1.rb +12 -4
- data/lib/mock/twilio/schemas/trust_products_v1.rb +12 -4
- data/lib/mock/twilio/util/generator.rb +34 -0
- data/lib/mock/twilio/version.rb +1 -1
- data/lib/mock/twilio/webhooks/call_status_updates.rb +4 -4
- data/lib/mock/twilio/webhooks/calls.rb +4 -4
- data/lib/mock/twilio/webhooks/conferences.rb +1 -1
- data/lib/mock/twilio/webhooks/voicemail.rb +55 -0
- data/lib/mock/twilio.rb +1 -0
- metadata +18 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a71b6dac5f7c25544671b2d8052b923e7bf84a16dc29f8d0243a06273562e28
|
4
|
+
data.tar.gz: 7620eaae9ab396ab492cc8fd0e2ec4df5e82d14d8caccc3fa1f47c7e1042b84b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c41c751585b29ce23a51baf02df01b3f8b3ddb911c2570ea65df66a83d040c192d1867e124502eb0c53ca5ed7a96b479c79de82a1dbffcda472bc48418edc2e7
|
7
|
+
data.tar.gz: 2e40c25d80bae526531613a86661ff9cf00cab5ef3ff9208df3ef4748d21639dc5c83fafb5f96c8065cd16c7857a11ae88515238e3bdde3dfae2a6eee8c65a9b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [1.3.0] - 2024-10-10
|
2
|
+
- Support IncomingPhoneNumbers Updates
|
3
|
+
- Support CustomerProfilesV1 ChannelEndpointAssignments
|
4
|
+
- Support TrustProductsV1 ChannelEndpointAssignments
|
5
|
+
- Unlock gemspec dependencies
|
6
|
+
|
7
|
+
## [1.2.0] - 2024-09-30
|
8
|
+
- Add direct calls voicemail support
|
9
|
+
|
1
10
|
## [1.1.0] - 2024-08-08
|
2
11
|
- Add conference call no-answer use case webhooks flow
|
3
12
|
|
data/README.md
CHANGED
@@ -28,22 +28,27 @@ OR
|
|
28
28
|
|
29
29
|
## Features Support
|
30
30
|
|
31
|
-
| Mock::Twilio::Client
|
31
|
+
| Support | Mock::Twilio::Client |
|
32
32
|
| ------------- | ------------- |
|
33
|
-
| `client.messages.create(to: "+593978613041", body: "Testing SMS", from: "+13212855389")` |
|
34
|
-
| `client.messaging.v1.services("MG"+"F"*32).phone_numbers.create(phone_number_sid: @phone_number_sid)` |
|
35
|
-
| `client.available_phone_numbers('US').local.list(limit: 20)` |
|
36
|
-
| `client.incoming_phone_numbers.create(phone_number: "+1987654321", voice_url: "#{BASE_URL}/api/v1/twilio_calls/incoming", sms_url: "#{BASE_URL}/api/v1/twilio_requests/inbound")` |
|
37
|
-
| `client.
|
38
|
-
| `client.
|
39
|
-
| `client.
|
40
|
-
| `client.
|
41
|
-
| `client.trusthub.v1.customer_profiles
|
42
|
-
| `client.trusthub.v1.
|
43
|
-
| `client.trusthub.v1.
|
44
|
-
| `client.
|
45
|
-
| `client.trusthub.v1.
|
46
|
-
| `client.trusthub.v1.
|
33
|
+
| :white_check_mark: | `client.messages.create(to: "+593978613041", body: "Testing SMS", from: "+13212855389")` |
|
34
|
+
| :white_check_mark: | `client.messaging.v1.services("MG"+"F"*32).phone_numbers.create(phone_number_sid: @phone_number_sid)` |
|
35
|
+
| :white_check_mark: | `client.available_phone_numbers('US').local.list(limit: 20)` |
|
36
|
+
| :white_check_mark: | `client.incoming_phone_numbers.create(phone_number: "+1987654321", voice_url: "#{BASE_URL}/api/v1/twilio_calls/incoming", sms_url: "#{BASE_URL}/api/v1/twilio_requests/inbound")` |
|
37
|
+
| :white_check_mark: | `client.incoming_phone_numbers.update(sms_application_sid: "AP"+"F"*32, voice_application_sid: "AP"+"F"*32)` |
|
38
|
+
| :white_check_mark: | `client.lookups.v2.phone_numbers("+14159929960").fetch(fields: :line_type_intelligence)` |
|
39
|
+
| :white_check_mark: | `client.calls.create(url: '<http://demo.twilio.com/docs/voice.xml>', to: '+14155551212', from: '+15017122661', status_callback: '<https://myapp.com/events>', status_callback_event: ['ringing'], status_callback_method: 'POST')` |
|
40
|
+
| :white_check_mark: | `client.conferences("CF"+("F")*32).participants.create(label: 'customer', early_media: true, beep: 'onEnter', status_callback: '<https://myapp.com/events>', status_callback_event: ['ringing'], record: true, from: '+15017122661', to: '+15558675310')` |
|
41
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` |
|
42
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles(customer_profile_sid).customer_profiles_entity_assignments.create(object_sid:)` |
|
43
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles("BU"+"F"*32).customer_profiles_channel_endpoint_assignment.list(limit: 20)` |
|
44
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles("BU"+"F"*32).customer_profiles_channel_endpoint_assignment("RA"+"F"*32).delete` |
|
45
|
+
| :white_check_mark: | `client.trusthub.v1.trust_products("BU"+"F"*32).trust_products_channel_endpoint_assignment.list(limit: 20)` |
|
46
|
+
| :white_check_mark: | `client.trusthub.v1.trust_products("BU"+"F"*32).trust_products_channel_endpoint_assignment("RA"+"F"*32).delete` |
|
47
|
+
| :white_check_mark: | `client.trusthub.v1.end_users.create(**twilio_parameters)`
|
48
|
+
| :white_check_mark: | `client.trusthub.v1.supporting_documents.create(**twilio_parameters)` |
|
49
|
+
| :white_check_mark: | `client.addresses.create(**twilio_parameters)` |
|
50
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` |
|
51
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles(customer_profile.sid).customer_profiles_evaluations.create(policy_sid:)` |
|
47
52
|
|
48
53
|
|
49
54
|
## Trigger resources updates
|
@@ -54,6 +59,7 @@ OR
|
|
54
59
|
| `Webhooks::InboundMessages` | :white_check_mark: |
|
55
60
|
| `Webhooks::Calls` | :white_check_mark: |
|
56
61
|
| `Webhooks::CallStatusUpdates` | :white_check_mark: |
|
62
|
+
| `Webhooks::Voicemail` | :white_check_mark: |
|
57
63
|
| `Webhooks::Conferences` | :white_check_mark: |
|
58
64
|
| `Webhooks::CustomerProfiles` | :white_check_mark: |
|
59
65
|
| `Webhooks::Brands` | :white_check_mark: |
|
@@ -30,7 +30,7 @@ module Mock
|
|
30
30
|
scheduler.in '2s' do
|
31
31
|
conference_uuid = request.data["Url"].split("conference_uuid=").last
|
32
32
|
begin
|
33
|
-
response = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, 'unknown')
|
33
|
+
response = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, 'unknown', 'ringing')
|
34
34
|
|
35
35
|
conference_response = if response.success?
|
36
36
|
twiMl_xml = Nokogiri::XML response.body
|
@@ -38,9 +38,12 @@ module Mock
|
|
38
38
|
Mock::Twilio::Webhooks::Conferences.trigger(friendly_name)
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
# Participant
|
42
|
+
participant_ringing = Mock::Twilio::Webhooks::Calls.trigger(sid, 'ringing') if conference_response.success?
|
43
|
+
participant_completed = Mock::Twilio::Webhooks::Calls.trigger(sid, 'completed') if participant_ringing.success?
|
42
44
|
|
43
|
-
Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, '
|
45
|
+
call_completed = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, 'human', 'completed') if participant_completed.success?
|
46
|
+
Mock::Twilio::Webhooks::Voicemail.trigger(sid) if call_completed.success? && [true,false].sample
|
44
47
|
rescue => e
|
45
48
|
puts e
|
46
49
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Decorators
|
6
|
+
module Api2010
|
7
|
+
class IncomingPhoneNumbers
|
8
|
+
class << self
|
9
|
+
include Mock::Twilio::Generator
|
10
|
+
|
11
|
+
def decorate(body, request)
|
12
|
+
body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
|
13
|
+
body["date_created"] = Time.current.rfc2822 if body["date_created"]
|
14
|
+
body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
|
15
|
+
|
16
|
+
body["sid"] = random_phone_number_sid if body["sid"]
|
17
|
+
body["identity_sid"] = random_identity_sid if body["identity_sid"]
|
18
|
+
body["emergency_address_sid"] = random_address_sid if body["emergency_address_sid"]
|
19
|
+
body["address_sid"] = random_address_sid if body["address_sid"]
|
20
|
+
body["bundle_sid"] = random_bundle_sid if body["bundle_sid"]
|
21
|
+
|
22
|
+
body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Decorators
|
6
|
+
module CustomerProfilesV1
|
7
|
+
class ChannelEndpointAssignments
|
8
|
+
class << self
|
9
|
+
include Mock::Twilio::Generator
|
10
|
+
|
11
|
+
def decorate(body, request)
|
12
|
+
decorate_results(body, request) unless body["results"].nil?
|
13
|
+
decorate_meta(body, request) unless body["meta"].nil?
|
14
|
+
|
15
|
+
body
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def decorate_meta(body, request)
|
21
|
+
customer_profile_sid = parse_customer_profile_sid(request)
|
22
|
+
|
23
|
+
body["meta"].tap do |meta|
|
24
|
+
page_size = body["results"].length
|
25
|
+
meta["page_size"] = page_size
|
26
|
+
meta["first_page_url"] = "https://trusthub.twilio.com/v1/CustomerProfiles#{customer_profile_sid}/ChannelEndpointAssignments?PageSize=#{page_size}&Page=0"
|
27
|
+
meta["previous_page_url"] = nil
|
28
|
+
meta["next_page_url"] = nil
|
29
|
+
meta["url"] = "https://trusthub.twilio.com/v1/CustomerProfiles#{customer_profile_sid}/ChannelEndpointAssignments?PageSize=#{page_size}&Page=0"
|
30
|
+
meta["key"] = "results"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def decorate_results(body, request)
|
35
|
+
customer_profile_sid = parse_customer_profile_sid(request)
|
36
|
+
|
37
|
+
body["results"].each do |result|
|
38
|
+
result["customer_profile_sid"] = customer_profile_sid if result["customer_profile_sid"]
|
39
|
+
result["sid"] = random_assignment_sid if result["sid"]
|
40
|
+
result["channel_endpoint_sid"] = random_phone_number_sid if result["channel_endpoint_sid"]
|
41
|
+
result["url"] = "https://trusthub.twilio.com/v1/CustomerProfiles/#{customer_profile_sid}/ChannelEndpointAssignments/#{result["sid"]}"
|
42
|
+
result["channel_endpoint_type"] = "phone-number" if result["channel_endpoint_type"]
|
43
|
+
result["account_sid"] = ::Twilio.account_sid
|
44
|
+
result["date_created"] = Time.current.rfc2822 if result["date_created"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_customer_profile_sid(request)
|
49
|
+
uri = URI(request.url)
|
50
|
+
uri.path.split('/')[3]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Decorators
|
6
|
+
module TrustProductsV1
|
7
|
+
class ChannelEndpointAssignments
|
8
|
+
class << self
|
9
|
+
include Mock::Twilio::Generator
|
10
|
+
|
11
|
+
def decorate(body, request)
|
12
|
+
decorate_results(body, request) unless body["results"].nil?
|
13
|
+
decorate_meta(body, request) unless body["meta"].nil?
|
14
|
+
|
15
|
+
body
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def decorate_meta(body, request)
|
21
|
+
trust_product_sid = parse_trust_product_sid(request)
|
22
|
+
|
23
|
+
body["meta"].tap do |meta|
|
24
|
+
page_size = body["results"].length
|
25
|
+
meta["page_size"] = page_size
|
26
|
+
meta["first_page_url"] = "https://trusthub.twilio.com/v1/TrustProducts/#{trust_product_sid}/ChannelEndpointAssignments?PageSize=#{page_size}&Page=0"
|
27
|
+
meta["previous_page_url"] = nil
|
28
|
+
meta["next_page_url"] = nil
|
29
|
+
meta["url"] = "https://trusthub.twilio.com/v1/TrustProducts/#{trust_product_sid}/ChannelEndpointAssignments?PageSize=#{page_size}&Page=0"
|
30
|
+
meta["key"] = "results"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def decorate_results(body, request)
|
35
|
+
trust_product_sid = parse_trust_product_sid(request)
|
36
|
+
|
37
|
+
body["results"].each do |result|
|
38
|
+
result["trust_product_sid"] = trust_product_sid if result["trust_product_sid"]
|
39
|
+
result["sid"] = random_assignment_sid if result["sid"]
|
40
|
+
result["channel_endpoint_sid"] = random_phone_number_sid if result["channel_endpoint_sid"]
|
41
|
+
result["url"] = "https://trusthub.twilio.com/v1/TrustProducts/#{trust_product_sid}/ChannelEndpointAssignments/#{result["sid"]}"
|
42
|
+
result["channel_endpoint_type"] = "phone-number" if result["channel_endpoint_type"]
|
43
|
+
result["account_sid"] = ::Twilio.account_sid
|
44
|
+
result["date_created"] = Time.current.rfc2822 if result["date_created"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_trust_product_sid(request)
|
49
|
+
uri = URI(request.url)
|
50
|
+
uri.path.split('/')[3]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -5,6 +5,7 @@ require_relative "../decorators/api_2010/calls"
|
|
5
5
|
require_relative "../decorators/api_2010/conferences_participants_update"
|
6
6
|
require_relative "../decorators/api_2010/conferences_participants_create"
|
7
7
|
require_relative "../decorators/api_2010/addresses"
|
8
|
+
require_relative "../decorators/api_2010/incoming_phone_numbers"
|
8
9
|
|
9
10
|
module Mock
|
10
11
|
module Twilio
|
@@ -17,6 +18,7 @@ module Mock
|
|
17
18
|
conferences_participants_update: Mock::Twilio::Decorators::Api2010::ConferencesParticipantsUpdate,
|
18
19
|
conferences_participants_create: Mock::Twilio::Decorators::Api2010::ConferencesParticipantsCreate,
|
19
20
|
addresses: Mock::Twilio::Decorators::Api2010::Addresses,
|
21
|
+
incoming_phone_numbers: Mock::Twilio::Decorators::Api2010::IncomingPhoneNumbers,
|
20
22
|
}
|
21
23
|
|
22
24
|
PAGES_KEYS = [
|
@@ -47,6 +49,8 @@ module Mock
|
|
47
49
|
RESOURCES[:conferences_participants_create].decorate(body, request)
|
48
50
|
when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Addresses.json}
|
49
51
|
RESOURCES[:addresses].decorate(body, request)
|
52
|
+
when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/IncomingPhoneNumbers/[A-Za-z0-9]+.json}
|
53
|
+
RESOURCES[:incoming_phone_numbers].decorate(body, request)
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
@@ -4,6 +4,7 @@ require_relative "../decorators/customer_profiles_v1/customer_profile"
|
|
4
4
|
require_relative "../decorators/customer_profiles_v1/entity_assignments"
|
5
5
|
require_relative "../decorators/customer_profiles_v1/evaluations"
|
6
6
|
require_relative "../decorators/customer_profiles_v1/customer_profile_update"
|
7
|
+
require_relative "../decorators/customer_profiles_v1/channel_endpoint_assignments"
|
7
8
|
|
8
9
|
module Mock
|
9
10
|
module Twilio
|
@@ -15,19 +16,26 @@ module Mock
|
|
15
16
|
entity_assigments: Mock::Twilio::Decorators::CustomerProfilesV1::EntityAssignments,
|
16
17
|
evaluations: Mock::Twilio::Decorators::CustomerProfilesV1::Evaluations,
|
17
18
|
customer_profile_update: Mock::Twilio::Decorators::CustomerProfilesV1::CustomerProfileUpdate,
|
19
|
+
channel_endpoint_assignments: Mock::Twilio::Decorators::CustomerProfilesV1::ChannelEndpointAssignments,
|
18
20
|
}
|
19
21
|
|
20
22
|
def for(body, request)
|
21
23
|
url = request.url.split(request.host).last
|
22
24
|
|
23
25
|
case url
|
24
|
-
when %r{
|
26
|
+
when %r{/v1/CustomerProfiles$}
|
25
27
|
RESOURCES[:customer_profile].decorate(body, request)
|
26
|
-
when %r{
|
28
|
+
when %r{/v1/CustomerProfiles/[A-Za-z0-9]+/EntityAssignments}
|
27
29
|
RESOURCES[:entity_assigments].decorate(body, request)
|
28
|
-
when %r{
|
30
|
+
when %r{/v1/CustomerProfiles/[A-Za-z0-9]+/Evaluations}
|
29
31
|
RESOURCES[:evaluations].decorate(body, request)
|
30
|
-
when %r{
|
32
|
+
when %r{/v1/CustomerProfiles/[A-Za-z0-9]+/ChannelEndpointAssignments}
|
33
|
+
if request.method.downcase == 'get'
|
34
|
+
RESOURCES[:channel_endpoint_assignments].decorate(body, request)
|
35
|
+
else
|
36
|
+
body
|
37
|
+
end
|
38
|
+
when %r{/v1/CustomerProfiles/[A-Za-z0-0]+}
|
31
39
|
RESOURCES[:customer_profile_update].decorate(body, request)
|
32
40
|
end
|
33
41
|
end
|
@@ -4,6 +4,7 @@ require_relative "../decorators/trust_products_v1/trust_products"
|
|
4
4
|
require_relative "../decorators/trust_products_v1/update"
|
5
5
|
require_relative "../decorators/trust_products_v1/evaluations"
|
6
6
|
require_relative "../decorators/trust_products_v1/entity_assignments"
|
7
|
+
require_relative "../decorators/trust_products_v1/channel_endpoint_assignments"
|
7
8
|
|
8
9
|
module Mock
|
9
10
|
module Twilio
|
@@ -15,20 +16,27 @@ module Mock
|
|
15
16
|
update: Mock::Twilio::Decorators::TrustProductsV1::Update,
|
16
17
|
evaluations: Mock::Twilio::Decorators::TrustProductsV1::Evaluations,
|
17
18
|
entity_assignments: Mock::Twilio::Decorators::TrustProductsV1::EntityAssignments,
|
19
|
+
channel_endpoint_assignments: Mock::Twilio::Decorators::TrustProductsV1::ChannelEndpointAssignments,
|
18
20
|
}
|
19
21
|
|
20
22
|
def for(body, request)
|
21
23
|
url = request.url.split(request.host).last
|
22
24
|
|
23
25
|
case url
|
24
|
-
when %r{
|
26
|
+
when %r{/v1/TrustProducts$}
|
25
27
|
RESOURCES[:trust_products].decorate(body, request)
|
26
|
-
when %r{
|
28
|
+
when %r{/v1/TrustProducts/\w{34}$}
|
27
29
|
RESOURCES[:update].decorate(body, request)
|
28
|
-
when %r{
|
30
|
+
when %r{/v1/TrustProducts/\w{34}/Evaluations$}
|
29
31
|
RESOURCES[:evaluations].decorate(body, request)
|
30
|
-
when %r{
|
32
|
+
when %r{/v1/TrustProducts/\w{34}/EntityAssignments$}
|
31
33
|
RESOURCES[:entity_assignments].decorate(body, request)
|
34
|
+
when %r{/v1/TrustProducts/[A-Za-z0-9]+/ChannelEndpointAssignments}
|
35
|
+
if request.method.downcase == 'get'
|
36
|
+
RESOURCES[:channel_endpoint_assignments].decorate(body, request)
|
37
|
+
else
|
38
|
+
body
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
@@ -6,6 +6,40 @@ module Mock
|
|
6
6
|
def phone_number_generator
|
7
7
|
"+1" + rand(100000000..999999999).to_s
|
8
8
|
end
|
9
|
+
|
10
|
+
def random_phone_number_sid
|
11
|
+
random_sid_prefixed_by "PN"
|
12
|
+
end
|
13
|
+
|
14
|
+
def random_account_sid
|
15
|
+
random_sid_prefixed_by "AC"
|
16
|
+
end
|
17
|
+
|
18
|
+
def random_twiml_app_sid
|
19
|
+
random_sid_prefixed_by "AP"
|
20
|
+
end
|
21
|
+
|
22
|
+
def random_identity_sid
|
23
|
+
random_sid_prefixed_by "RI"
|
24
|
+
end
|
25
|
+
|
26
|
+
def random_address_sid
|
27
|
+
random_sid_prefixed_by "AD"
|
28
|
+
end
|
29
|
+
|
30
|
+
def random_bundle_sid
|
31
|
+
random_sid_prefixed_by "BU"
|
32
|
+
end
|
33
|
+
|
34
|
+
def random_assignment_sid
|
35
|
+
random_sid_prefixed_by "RA"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def random_sid_prefixed_by(prefix)
|
41
|
+
"#{prefix}#{SecureRandom.hex(16)}"
|
42
|
+
end
|
9
43
|
end
|
10
44
|
end
|
11
45
|
end
|
data/lib/mock/twilio/version.rb
CHANGED
@@ -6,13 +6,13 @@ module Mock
|
|
6
6
|
class CallStatusUpdates < Base
|
7
7
|
URL = "/api/v1/twilio_calls/voice_responses"
|
8
8
|
|
9
|
-
def self.trigger(sid, conference_uuid, answered_by)
|
9
|
+
def self.trigger(sid, conference_uuid, answered_by, call_status)
|
10
10
|
# Wait simulation from twilio
|
11
11
|
sleep DELAY.sample
|
12
12
|
|
13
13
|
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
14
14
|
|
15
|
-
data = call_status_updates_data(sid, conference_uuid, answered_by)
|
15
|
+
data = call_status_updates_data(sid, conference_uuid, answered_by, call_status)
|
16
16
|
|
17
17
|
signature = build_signature_for_request(request_url, data)
|
18
18
|
|
@@ -33,7 +33,7 @@ module Mock
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.call_status_updates_data(sid, conference_uuid, answered_by)
|
36
|
+
def self.call_status_updates_data(sid, conference_uuid, answered_by, call_status)
|
37
37
|
{
|
38
38
|
:AccountSid=> twilio_client.account_sid,
|
39
39
|
:ApiVersion=> "2010-04-01",
|
@@ -50,7 +50,7 @@ module Mock
|
|
50
50
|
:CallerState=> "CA",
|
51
51
|
:CallerZip=> "no value",
|
52
52
|
:CallSid=> sid,
|
53
|
-
:CallStatus=>
|
53
|
+
:CallStatus=> call_status,
|
54
54
|
:Direction=> "outbound-api",
|
55
55
|
:Duration=> "0",
|
56
56
|
:From=> "+18111111111",
|
@@ -6,13 +6,13 @@ module Mock
|
|
6
6
|
class Calls < Base
|
7
7
|
URL = "/api/v1/twilio_calls/participant_status_changes"
|
8
8
|
|
9
|
-
def self.trigger(sid)
|
9
|
+
def self.trigger(sid, participant_status)
|
10
10
|
# Wait simulation from twilio
|
11
11
|
sleep DELAY.sample
|
12
12
|
|
13
13
|
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
14
14
|
|
15
|
-
data = call_data(sid)
|
15
|
+
data = call_data(sid, participant_status)
|
16
16
|
|
17
17
|
signature = build_signature_for_request(request_url, data)
|
18
18
|
|
@@ -33,7 +33,7 @@ module Mock
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.call_data(sid)
|
36
|
+
def self.call_data(sid, participant_status)
|
37
37
|
{
|
38
38
|
:AccountSid=> twilio_client.account_sid,
|
39
39
|
:ApiVersion=> "2010-04-01",
|
@@ -50,7 +50,7 @@ module Mock
|
|
50
50
|
:CallerState=> "CA",
|
51
51
|
:CallerZip=> "no value",
|
52
52
|
:CallSid=> sid,
|
53
|
-
:CallStatus=>
|
53
|
+
:CallStatus=> participant_status,
|
54
54
|
:Direction=> "outbound-api",
|
55
55
|
:Duration=> "0",
|
56
56
|
:From=> "+18111111111",
|
@@ -41,7 +41,7 @@ module Mock
|
|
41
41
|
:FriendlyName=> friendly_name,
|
42
42
|
:SequenceNumber=> "6",
|
43
43
|
:ConferenceSid=> sid,
|
44
|
-
:StatusCallbackEvent=> "conference-
|
44
|
+
:StatusCallbackEvent=> "conference-end",
|
45
45
|
:Timestamp=> "2024-06-17 16:49:31 UTC",
|
46
46
|
:AccountSid=> twilio_client.account_sid,
|
47
47
|
:Reason=> "Participant from mock twilio"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Webhooks
|
6
|
+
class Voicemail < Base
|
7
|
+
URL = "/api/v1/twilio_calls/create_voicemail"
|
8
|
+
|
9
|
+
def self.trigger(call_sid)
|
10
|
+
# Wait simulation from twilio
|
11
|
+
sleep DELAY.sample
|
12
|
+
|
13
|
+
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
14
|
+
|
15
|
+
data = voicemail_data(call_sid)
|
16
|
+
|
17
|
+
signature = build_signature_for_request(request_url, data)
|
18
|
+
|
19
|
+
response = webhook_client.request(Mock::Twilio.host,
|
20
|
+
Mock::Twilio.port,
|
21
|
+
'POST',
|
22
|
+
URL,
|
23
|
+
nil,
|
24
|
+
data,
|
25
|
+
headers.merge!({ 'X-Twilio-Signature': signature }),
|
26
|
+
auth_twilio,
|
27
|
+
nil)
|
28
|
+
case response.status
|
29
|
+
when 200..204
|
30
|
+
response
|
31
|
+
when 400..600
|
32
|
+
raise Webhooks::RestError, Mock::Twilio::ErrorHandler.new(response).raise
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.voicemail_data(call_sid)
|
37
|
+
prefix = "RE"
|
38
|
+
recording_sid = prefix + SecureRandom.hex(16)
|
39
|
+
{
|
40
|
+
:RecordingSource=> "RecordVerb",
|
41
|
+
:RecordingSid=> recording_sid,
|
42
|
+
:RecordingUrl=> "https://cdn.pixabay.com/download/audio/2022/03/24/audio_4ff823c44c.mp3?filename=ding-101492.mp3",
|
43
|
+
:RecordingStatus=> "completed",
|
44
|
+
:RecordingChannels=> "1",
|
45
|
+
:ErrorCode=> "0",
|
46
|
+
:CallSid=> call_sid,
|
47
|
+
:RecordingStartTime=> Time.current.rfc2822,
|
48
|
+
:AccountSid=> twilio_client.account_sid,
|
49
|
+
:RecordingDuration=> "4"
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/mock/twilio.rb
CHANGED
@@ -14,6 +14,7 @@ require_relative "twilio/webhooks/conferences"
|
|
14
14
|
require_relative "twilio/webhooks/customer_profiles"
|
15
15
|
require_relative "twilio/webhooks/brands"
|
16
16
|
require_relative "twilio/webhooks/inbound_messages"
|
17
|
+
require_relative "twilio/webhooks/voicemail"
|
17
18
|
require_relative "twilio/util/configuration"
|
18
19
|
require_relative "twilio/util/error_handler"
|
19
20
|
require_relative "twilio/util/generator"
|
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock-twilio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SchoolStatus Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.9.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rufus-scheduler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.9.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.9.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: twilio-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 7.
|
47
|
+
version: 7.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 7.
|
54
|
+
version: 7.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 6.0.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 6.0.0
|
69
69
|
description: This repository contains Mock::Twilio::Client for Twilio's API.
|
70
70
|
email:
|
71
71
|
executables: []
|
@@ -84,7 +84,9 @@ files:
|
|
84
84
|
- lib/mock/twilio/decorators/api_2010/calls.rb
|
85
85
|
- lib/mock/twilio/decorators/api_2010/conferences_participants_create.rb
|
86
86
|
- lib/mock/twilio/decorators/api_2010/conferences_participants_update.rb
|
87
|
+
- lib/mock/twilio/decorators/api_2010/incoming_phone_numbers.rb
|
87
88
|
- lib/mock/twilio/decorators/api_2010/messages.rb
|
89
|
+
- lib/mock/twilio/decorators/customer_profiles_v1/channel_endpoint_assignments.rb
|
88
90
|
- lib/mock/twilio/decorators/customer_profiles_v1/customer_profile.rb
|
89
91
|
- lib/mock/twilio/decorators/customer_profiles_v1/customer_profile_update.rb
|
90
92
|
- lib/mock/twilio/decorators/customer_profiles_v1/entity_assignments.rb
|
@@ -92,6 +94,7 @@ files:
|
|
92
94
|
- lib/mock/twilio/decorators/messaging_v1/phone_number_create.rb
|
93
95
|
- lib/mock/twilio/decorators/messaging_v1/phone_number_fetch.rb
|
94
96
|
- lib/mock/twilio/decorators/messaging_v1/phone_number_list.rb
|
97
|
+
- lib/mock/twilio/decorators/trust_products_v1/channel_endpoint_assignments.rb
|
95
98
|
- lib/mock/twilio/decorators/trust_products_v1/entity_assignments.rb
|
96
99
|
- lib/mock/twilio/decorators/trust_products_v1/evaluations.rb
|
97
100
|
- lib/mock/twilio/decorators/trust_products_v1/trust_products.rb
|
@@ -119,6 +122,7 @@ files:
|
|
119
122
|
- lib/mock/twilio/webhooks/customer_profiles.rb
|
120
123
|
- lib/mock/twilio/webhooks/inbound_messages.rb
|
121
124
|
- lib/mock/twilio/webhooks/messages.rb
|
125
|
+
- lib/mock/twilio/webhooks/voicemail.rb
|
122
126
|
- lib/twilio/rest/messaging/v1/service/phone_number_decorator.rb
|
123
127
|
- sig/mock/twilio.rbs
|
124
128
|
homepage: https://github.com/schoolstatus/mock-twilio
|