mock-twilio 0.2.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbb843efbd1e8b54602d0463971c24a502b20b42ec9085530f624549190bee40
4
- data.tar.gz: 40d24741f57296220aaa3ca36b21c2b5fd429a08c4669c2ce2cf0f636696889a
3
+ metadata.gz: 1fa25d49f6ae4eb3c3660e470478b6bd9ed803c55a106ce81b24698ecef8eaf8
4
+ data.tar.gz: b1ce1de75fba85aaae12cf95d0b09444f668319ea9481efeea5ff461f1e61240
5
5
  SHA512:
6
- metadata.gz: 570376720a4f739d537bdb4285cfd8aaadea578d3d076089b849a8d7f66b603a0b0562a116c0fc9ecb6462ee64d8f8fdf3cb957d2c8a4a82575111354ba16670
7
- data.tar.gz: 41dc6b8fcd7b6e2b58b85d81eb43e75defc1969a7c8a349ef4546a4a7c9114a35e4e9d85e3e4dc804b95ea7f9de827551a2a1724dd82e52eaa8d8d0ed712f9d4
6
+ metadata.gz: fb1170b5cc6d024c6423bc70c1f3d0db6589e93e1e6adf9f6ef84df960fe84ef0ac4ed1eaa284b64b66fbaf67aec9d8e46ae1a4aa380ca6e96ea882ca04bfcd3
7
+ data.tar.gz: e3e1defce5ed25b23e170cf068958b2144eabbae4544dfe80222c9385c14d74affc2a35c3bf1a156105b60e37ad43834fd90de98f67efc8f5d7cdb653ac42eed
data/CHANGELOG.md CHANGED
@@ -1,8 +1,20 @@
1
+ ## [0.4.0] - 2024-07-01
2
+ - Support CustomerProfiles, EntityAssignments, Evaluations
3
+ - Support EndUsersV1
4
+ - Support SupportingDocumentsV1
5
+ - Support Addresses
6
+ - Support Mock::Twilio::Webhooks::CustomerProfiles
7
+ - Support LookupV2 line_type_intelligence
8
+
9
+ ## [0.3.0] - 2024-06-24
10
+ - Support Calls service
11
+ - Support Conferences service
12
+ - Support Webhooks CallStatusUpdates, Conferences and Calls
13
+
1
14
  ## [0.2.0] - 2024-06-09
2
15
  - Support MessageSid SMS and MMS
3
16
  - Support Webhooks::Messages SMS and MMS
4
17
 
5
- - Initial release
6
18
  ## [0.1.0] - 2024-05-29
7
19
 
8
20
  - Initial release
data/Gemfile CHANGED
@@ -8,5 +8,6 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "minitest", "~> 5.0"
11
+ gem 'simplecov', require: false, group: :test
11
12
  gem "webmock"
12
13
  gem "pry"
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Mock::Twilio::Client
2
+ [![Gem Version](https://badge.fury.io/rb/mock-twilio.svg)](https://badge.fury.io/rb/mock-twilio)
3
+ ![mock-twilio](https://github.com/schoolstatus/mock-twilio/actions/workflows/ruby.yml/badge.svg)
2
4
 
3
5
  This is a SchoolStatus implementation to mock twilio client to perform requests to [twilio-oai](https://github.com/twilio/twilio-oai)
4
6
 
@@ -8,7 +10,7 @@ This is a SchoolStatus implementation to mock twilio client to perform requests
8
10
  To install using bundler grab the latest stable version:
9
11
 
10
12
  ```ruby
11
- gem "mock-twilio", "~> 0.2.0", git: "https://github.com/schoolstatus/mock-twilio.git"
13
+ gem install mock-twilio
12
14
  ```
13
15
 
14
16
  ## Requirements
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
8
8
  t.libs << "lib"
9
9
  t.test_files = FileList["test/**/test_*.rb"]
10
+ t.warning = false
10
11
  end
11
12
 
12
13
  task default: :test
@@ -1,11 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "schemas/api_2010"
4
+ require_relative "schemas/messaging_v1"
5
+ require_relative "schemas/customer_profiles_v1"
6
+ require_relative "schemas/end_users_v1"
7
+ require_relative "schemas/supporting_documents_v1"
8
+ require_relative "schemas/phone_numbers_v2"
9
+
3
10
  module Mock
4
11
  module Twilio
5
12
  class Decorator
6
13
  ENDPOINTS = {
7
14
  api_2010: Mock::Twilio::Schemas::Api2010,
8
15
  messaging_v1: Mock::Twilio::Schemas::MessagingV1,
16
+ customer_profiles_v1: Mock::Twilio::Schemas::CustomerProfilesV1,
17
+ end_users_v1: Mock::Twilio::Schemas::EndUsersV1,
18
+ supporting_documents_v1: Mock::Twilio::Schemas::SupportingDocumentsV1,
19
+ phone_numbers_v2: Mock::Twilio::Schemas::PhoneNumbersV2
9
20
  }
10
21
 
11
22
  class << self
@@ -19,7 +30,7 @@ module Mock
19
30
 
20
31
  schema = url_from(body, request)
21
32
  # return body decorate if needed
22
- return ENDPOINTS[schema].decorate(body, request) if schema
33
+ return ENDPOINTS[schema].for(body, request) if schema
23
34
 
24
35
  body
25
36
  end
@@ -32,6 +43,14 @@ module Mock
32
43
  :api_2010
33
44
  when %r{\/v1/Services/[A-Za-z0-9]+/}
34
45
  :messaging_v1
46
+ when %r{\/v1/CustomerProfiles}
47
+ :customer_profiles_v1
48
+ when %r{\/v1/EndUsers}
49
+ :end_users_v1
50
+ when %r{\/v1/SupportingDocuments}
51
+ :supporting_documents_v1
52
+ when %r{\/v2/PhoneNumbers}
53
+ :phone_numbers_v2
35
54
  end
36
55
  end
37
56
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module Api2010
7
+ class Addresses
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
11
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
12
+ body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
13
+
14
+ address_sid(body, request) if body["sid"]
15
+ body["iso_country"] = "US" if body["iso_country"]
16
+ body["city"] = request.data["City"] if body["city"]
17
+ body["region"] = request.data["Region"] if body["region"]
18
+ body["street"] = request.data["Street"] if body["street"]
19
+ body["postal_code"] = request.data["PostalCode"] if body["postal_code"]
20
+ body["friendly_name"] = request.data["FriendlyName"] if body["friendly_name"]
21
+
22
+ body["emergency_enabled"] = false if body["emergency_enabled"]
23
+ body["validated"] = true if body["validated"]
24
+ body["verified"] = true if body["verified"]
25
+
26
+ body
27
+ end
28
+
29
+ def address_sid(body, request)
30
+ prefix = "AD"
31
+ sid = prefix + SecureRandom.hex(16)
32
+ body["sid"] = sid
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module Api2010
7
+ class Calls
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
11
+ body["date_sent"] = Time.current.rfc2822 if body["date_sent"]
12
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
13
+ body["start_time"] = Time.current.rfc2822 if body["start_time"]
14
+ body["end_time"] = Time.current.rfc2822 if body["end_time"]
15
+
16
+ call_sid(body, request) if body["sid"]
17
+ phone_number_sid(body, request) if body["phone_number_sid"]
18
+ body["direction"] = "outbound-api" if body["direction"]
19
+ body["api_version"] = "2010-04-01" if body["api_version"]
20
+ body["to"] = request.data['To'] if body["to"]
21
+ body["from"] = request.data['From'] if body["from"]
22
+
23
+ body
24
+ end
25
+
26
+ def call_sid(body, request)
27
+ prefix = "CA"
28
+ sid = prefix + SecureRandom.hex(16)
29
+ scheduler = Rufus::Scheduler.new
30
+ scheduler.in '2s' do
31
+ conference_uuid = request.data["Url"].split("conference_uuid=").last
32
+ response = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid)
33
+
34
+ conference_response = if response.status == 200
35
+ twiMl_xml = Nokogiri::XML response.body
36
+ friendly_name = twiMl_xml.at_xpath('//Dial').at_xpath('//Conference').children.text
37
+ Mock::Twilio::Webhooks::Conferences.trigger(friendly_name)
38
+ end
39
+
40
+ Mock::Twilio::Webhooks::Calls.trigger(sid) if conference_response.status == 200
41
+ end
42
+ body["sid"] = sid
43
+ end
44
+
45
+ def phone_number_sid(body, request)
46
+ prefix = "PN"
47
+ sid = prefix + SecureRandom.hex(16)
48
+ body["phone_number_sid"] = sid
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module Api2010
7
+ class ConferencesParticipantsCreate
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
11
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
12
+ body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
13
+ body["label"] = "Mock Customer" if body["label"]
14
+ body["status"] = "initiated" if body["status"]
15
+
16
+ parse_call_sid(body, request) if body["call_sid"]
17
+ parse_conference_sid(body, request) if body["conference_sid"]
18
+
19
+ body
20
+ end
21
+
22
+ def parse_call_sid(body, request)
23
+ prefix = "CA"
24
+ call_sid = prefix + SecureRandom.hex(16)
25
+ body["call_sid"] = call_sid
26
+ end
27
+
28
+ def parse_conference_sid(body, request)
29
+ uri = URI(request.url)
30
+ conference_sid = uri.path.split('/')[5]
31
+ body["conference_sid"] = conference_sid
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module Api2010
7
+ class ConferencesParticipantsUpdate
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
11
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
12
+ body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
13
+ body["label"] = "Mock Customer" if body["label"]
14
+ body["status"] = "complete" if body["status"]
15
+
16
+ parse_call_sid(body, request) if body["call_sid"]
17
+ parse_conference_sid(body, request) if body["conference_sid"]
18
+
19
+ body
20
+ end
21
+
22
+ def parse_call_sid(body, request)
23
+ uri = URI(request.url)
24
+ call_sid = uri.path.split('/')[7].split('.').first
25
+ body["call_sid"] = call_sid
26
+ end
27
+
28
+ def parse_conference_sid(body, request)
29
+ uri = URI(request.url)
30
+ conference_sid = uri.path.split('/')[5]
31
+ body["conference_sid"] = conference_sid
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module Api2010
7
+ class Messages
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
11
+ body["date_sent"] = Time.current.rfc2822 if body["date_sent"]
12
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
13
+ body["start_time"] = Time.current.rfc2822 if body["start_time"]
14
+ body["end_time"] = Time.current.rfc2822 if body["end_time"]
15
+
16
+ message_sid(body, request) if body["sid"]
17
+ pagination(body) if body["available_phone_numbers"]
18
+
19
+ body
20
+ end
21
+
22
+ def pagination(body)
23
+ # Params returned in mock_server but not on real twilio request for the moment.
24
+ # Not needed for us now.
25
+ PAGES_KEYS.each do |key|
26
+ body.delete(key) if body[key]
27
+ end
28
+ end
29
+
30
+ def message_sid(body, request)
31
+ prefix = request.data["MediaUrl"] ? "MM" : "SM"
32
+ sid = prefix + SecureRandom.hex(16)
33
+ scheduler = Rufus::Scheduler.new
34
+ scheduler.in '2s' do
35
+ Mock::Twilio::Webhooks::Messages.trigger(sid)
36
+ end
37
+ body["sid"] = sid
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module CustomerProfilesV1
7
+ class CustomerProfile
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
11
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
12
+ customer_profile_sid(body, request) if body["sid"]
13
+ body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
14
+ body["friendly_name"] = request.data["FriendlyName"] if body["friendly_name"]
15
+ body["email"] = request.data["Email"] if body["email"]
16
+ body["policy_sid"] = request.data["PolicySid"] if body["policy_sid"]
17
+ body["status_callback"] = request.data["StatusCallback"] if body["status_callback"]
18
+ body["status"] = "in-review" if body["status"]
19
+
20
+ body
21
+ end
22
+
23
+ def customer_profile_sid(body, request)
24
+ prefix = "BU"
25
+ sid = prefix + SecureRandom.hex(16)
26
+ scheduler = Rufus::Scheduler.new
27
+ scheduler.in '2s' do
28
+ Mock::Twilio::Webhooks::CustomerProfiles.trigger(sid, "in-review")
29
+ end
30
+ body["sid"] = sid
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module CustomerProfilesV1
7
+ class EntityAssignments
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
11
+ entity_sid(body, request) if body["sid"]
12
+ body["account_sid"] = ::Twilio.account_sid
13
+ body["object_sid"] = request.data["ObjectSid"]
14
+ parse_customer_profile_sid(body, request) if body["customer_profile_sid"]
15
+
16
+ body
17
+ end
18
+
19
+ def entity_sid(body, request)
20
+ prefix = "BV"
21
+ sid = prefix + SecureRandom.hex(16)
22
+ body["sid"] = sid
23
+ end
24
+
25
+ def parse_customer_profile_sid(body, request)
26
+ uri = URI(request.url)
27
+ customer_profile_sid = uri.path.split('/')[3].split('.').first
28
+ body["customer_profile_sid"] = customer_profile_sid
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Decorators
6
+ module CustomerProfilesV1
7
+ class Evaluations
8
+ class << self
9
+ def decorate(body, request)
10
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
11
+ parse_customer_profile_sid(body, request) if body["customer_profile_sid"]
12
+ evaluation_sid(body, request) if body["sid"]
13
+ body["account_sid"] = ::Twilio.account_sid
14
+ body["policy_sid"] = request.data["PolicySid"] if body["policy_sid"]
15
+ body["status"] = "compliant" if body["status"]
16
+
17
+ body
18
+ end
19
+
20
+ def evaluation_sid(body, request)
21
+ prefix = "EL"
22
+ sid = prefix + SecureRandom.hex(16)
23
+ scheduler = Rufus::Scheduler.new
24
+ scheduler.in '2s' do
25
+ Mock::Twilio::Webhooks::CustomerProfiles.trigger(body['customer_profile_sid'], "twilio-approved")
26
+ end
27
+ body["sid"] = sid
28
+ end
29
+
30
+ def parse_customer_profile_sid(body, request)
31
+ uri = URI(request.url)
32
+ customer_profile_sid = uri.path.split('/')[3].split('.').first
33
+ body["customer_profile_sid"] = customer_profile_sid
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,10 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../decorators/api_2010/messages"
4
+ require_relative "../decorators/api_2010/calls"
5
+ require_relative "../decorators/api_2010/conferences_participants_update"
6
+ require_relative "../decorators/api_2010/conferences_participants_create"
7
+ require_relative "../decorators/api_2010/addresses"
8
+
3
9
  module Mock
4
10
  module Twilio
5
11
  module Schemas
6
12
  class Api2010
7
13
  class << self
14
+ RESOURCES = {
15
+ messages: Mock::Twilio::Decorators::Api2010::Messages,
16
+ calls: Mock::Twilio::Decorators::Api2010::Calls,
17
+ conferences_participants_update: Mock::Twilio::Decorators::Api2010::ConferencesParticipantsUpdate,
18
+ conferences_participants_create: Mock::Twilio::Decorators::Api2010::ConferencesParticipantsCreate,
19
+ addresses: Mock::Twilio::Decorators::Api2010::Addresses,
20
+ }
21
+
8
22
  PAGES_KEYS = [
9
23
  "end",
10
24
  "first_page_uri",
@@ -19,35 +33,21 @@ module Mock
19
33
  "uri"
20
34
  ].freeze
21
35
 
22
- def decorate(body, request)
23
- body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
24
- body["date_sent"] = Time.current.rfc2822 if body["date_sent"]
25
- body["date_created"] = Time.current.rfc2822 if body["date_created"]
26
- body["start_time"] = Time.current.rfc2822 if body["start_time"]
27
- body["end_time"] = Time.current.rfc2822 if body["end_time"]
28
-
29
- message_sid(body, request) if body["sid"]
30
- pagination(body) if body["available_phone_numbers"]
31
-
32
- body
33
- end
34
-
35
- def pagination(body)
36
- # Params returned in mock_server but not on real twilio request for the moment.
37
- # Not needed for us now.
38
- PAGES_KEYS.each do |key|
39
- body.delete(key) if body[key]
40
- end
41
- end
36
+ def for(body, request)
37
+ url = request.url.split(request.host).last
42
38
 
43
- def message_sid(body, request)
44
- prefix = request.data["MediaUrl"] ? "MM" : "SM"
45
- sid = prefix + SecureRandom.hex(16)
46
- scheduler = Rufus::Scheduler.new
47
- scheduler.in '2s' do
48
- Mock::Twilio::Webhooks::Messages.trigger(sid)
39
+ case url
40
+ when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Messages.json}
41
+ RESOURCES[:messages].decorate(body, request)
42
+ when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Calls.json}
43
+ RESOURCES[:calls].decorate(body, request)
44
+ when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Conferences/[A-Za-z0-9]+/Participants/[A-Za-z0-9]+.json}
45
+ RESOURCES[:conferences_participants_update].decorate(body, request)
46
+ when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Conferences/[A-Za-z0-9]+/Participants.json}
47
+ RESOURCES[:conferences_participants_create].decorate(body, request)
48
+ when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Addresses.json}
49
+ RESOURCES[:addresses].decorate(body, request)
49
50
  end
50
- body["sid"] = sid
51
51
  end
52
52
  end
53
53
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../decorators/customer_profiles_v1/customer_profile"
4
+ require_relative "../decorators/customer_profiles_v1/entity_assignments"
5
+ require_relative "../decorators/customer_profiles_v1/evaluations"
6
+
7
+ module Mock
8
+ module Twilio
9
+ module Schemas
10
+ class CustomerProfilesV1
11
+ class << self
12
+ RESOURCES = {
13
+ customer_profile: Mock::Twilio::Decorators::CustomerProfilesV1::CustomerProfile,
14
+ entity_assigments: Mock::Twilio::Decorators::CustomerProfilesV1::EntityAssignments,
15
+ evaluations: Mock::Twilio::Decorators::CustomerProfilesV1::Evaluations
16
+ }
17
+
18
+ def for(body, request)
19
+ url = request.url.split(request.host).last
20
+
21
+ case url
22
+ when %r{\/v1/CustomerProfiles$}
23
+ RESOURCES[:customer_profile].decorate(body, request)
24
+ when %r{\/v1/CustomerProfiles/[A-Za-z0-9]+/EntityAssignments}
25
+ RESOURCES[:entity_assigments].decorate(body, request)
26
+ when %r{\/v1/CustomerProfiles/[A-Za-z0-9]+/Evaluations}
27
+ RESOURCES[:evaluations].decorate(body, request)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Schemas
6
+ class EndUsersV1
7
+ class << self
8
+ def for(body, request)
9
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
10
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
11
+ body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
12
+ body["type"] = request.data["Type"] if body["type"]
13
+ end_user_sid(body, request) if body["sid"]
14
+ body["friendly_name"] = request.data["FriendlyName"] if body["friendly_name"]
15
+
16
+ body
17
+ end
18
+
19
+ def end_user_sid(body, request)
20
+ prefix = "IT"
21
+ sid = prefix + SecureRandom.hex(16)
22
+ body["sid"] = sid
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Schemas
6
+ class PhoneNumbersV2
7
+ class << self
8
+ def for(body, request)
9
+ body["calling_country_code"] = '1' if body["calling_country_code"]
10
+ body["country_code"] = 'US' if body["country_code"]
11
+ body["valid"] = true if body["valid"]
12
+ body["validation_errors"] = [] if body["validation_errors"]
13
+ body["line_type_intelligence"] = { "carrier_name" => "Mock::Twilio - SMS/MMS-SVR", "type" => "mock" }
14
+
15
+ body
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Schemas
6
+ class SupportingDocumentsV1
7
+ class << self
8
+ def for(body, request)
9
+ body["date_updated"] = Time.current.rfc2822 if body["date_updated"]
10
+ body["date_created"] = Time.current.rfc2822 if body["date_created"]
11
+ body["account_sid"] = ::Twilio.account_sid if body["account_sid"]
12
+
13
+ support_document_sid(body, request) if body["sid"]
14
+ body["friendly_name"] = request.data["FriendlyName"] if body["friendly_name"]
15
+ body["status"] = "approved" if body["status"]
16
+ body["type"] = request.data["Type"] if body["type"]
17
+
18
+ body
19
+ end
20
+
21
+ def support_document_sid(body, request)
22
+ prefix = "RD"
23
+ sid = prefix + SecureRandom.hex(16)
24
+ body["sid"] = sid
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mock
4
4
  module Twilio
5
- VERSION = "0.2.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Webhooks
6
+ class CallStatusUpdates < Base
7
+ URL = "/api/v1/twilio_calls/voice_responses"
8
+
9
+ def self.trigger(sid, conference_uuid)
10
+ # Wait simulation from twilio
11
+ sleep DELAY.sample
12
+
13
+ request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
14
+
15
+ data = call_status_updates_data(sid, conference_uuid)
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, response.body
33
+ end
34
+ end
35
+
36
+ def self.call_status_updates_data(sid, conference_uuid)
37
+ {
38
+ :AccountSid=> twilio_client.account_sid,
39
+ :ApiVersion=> "2010-04-01",
40
+ :CallbackSource=> "call-progress-events",
41
+ :CallDuration=> "0",
42
+ :Called=> "+18222222222",
43
+ :CalledCity=> "TAMPA",
44
+ :CalledCountry=> "US",
45
+ :CalledState=> "FL",
46
+ :CalledZip=> "33605",
47
+ :Caller=> "+18111111111",
48
+ :CallerCity=> "no value",
49
+ :CallerCountry=> "US",
50
+ :CallerState=> "CA",
51
+ :CallerZip=> "no value",
52
+ :CallSid=> sid,
53
+ :CallStatus=> "in-progress",
54
+ :Direction=> "outbound-api",
55
+ :Duration=> "0",
56
+ :From=> "+18111111111",
57
+ :FromCity=> "no value",
58
+ :FromCountry=> "US",
59
+ :FromState=> "CA",
60
+ :FromZip=> "no value",
61
+ :SequenceNumber=> "2",
62
+ :SipResponseCode=> "487",
63
+ :Timestamp=> "2024-06-17 16:49:31 UTC",
64
+ :To=> "+18222222222",
65
+ :ToCity=> "TAMPA",
66
+ :ToCountry=> "US",
67
+ :ToState=> "FL",
68
+ :ToZip=> "33605",
69
+ :StirStatus=> "B",
70
+ :StirVerstat=> "TN-Validation-Passed-B",
71
+ :AnsweredBy=> "unknown",
72
+ :conference_uuid=> conference_uuid
73
+ }
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Webhooks
6
+ class Calls < Base
7
+ URL = "/api/v1/twilio_calls/participant_status_changes"
8
+
9
+ def self.trigger(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 = call_data(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, response.body
33
+ end
34
+ end
35
+
36
+ def self.call_data(sid)
37
+ {
38
+ :AccountSid=> twilio_client.account_sid,
39
+ :ApiVersion=> "2010-04-01",
40
+ :CallbackSource=> "call-progress-events",
41
+ :CallDuration=> "0",
42
+ :Called=> "+18222222222",
43
+ :CalledCity=> "TAMPA",
44
+ :CalledCountry=> "US",
45
+ :CalledState=> "FL",
46
+ :CalledZip=> "33605",
47
+ :Caller=> "+18111111111",
48
+ :CallerCity=> "no value",
49
+ :CallerCountry=> "US",
50
+ :CallerState=> "CA",
51
+ :CallerZip=> "no value",
52
+ :CallSid=> sid,
53
+ :CallStatus=> "in-progress",
54
+ :Direction=> "outbound-api",
55
+ :Duration=> "0",
56
+ :From=> "+18111111111",
57
+ :FromCity=> "no value",
58
+ :FromCountry=> "US",
59
+ :FromState=> "CA",
60
+ :FromZip=> "no value",
61
+ :SequenceNumber=> "2",
62
+ :SipResponseCode=> "487",
63
+ :Timestamp=> "2024-06-17 16:49:31 UTC",
64
+ :To=> "+18222222222",
65
+ :ToCity=> "TAMPA",
66
+ :ToCountry=> "US",
67
+ :ToState=> "FL",
68
+ :ToZip=> "33605"
69
+ }
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Webhooks
6
+ class Conferences < Base
7
+ URL = "/api/v1/twilio_calls/conference_status_changes"
8
+
9
+ def self.trigger(friendly_name)
10
+ # Wait simulation from twilio
11
+ sleep DELAY.sample
12
+
13
+ request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
14
+
15
+ data = conference_data(friendly_name)
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
+
29
+ case response.status
30
+ when 200..204
31
+ response
32
+ when 400..600
33
+ raise Webhooks::RestError, response.body
34
+ end
35
+ end
36
+
37
+ def self.conference_data(friendly_name)
38
+ prefix = "CF"
39
+ sid = prefix + SecureRandom.hex(16)
40
+ {
41
+ :FriendlyName=> friendly_name,
42
+ :SequenceNumber=> "6",
43
+ :ConferenceSid=> sid,
44
+ :StatusCallbackEvent=> "conference-start",
45
+ :Timestamp=> "2024-06-17 16:49:31 UTC",
46
+ :AccountSid=> twilio_client.account_sid,
47
+ :Reason=> "Participant from mock twilio"
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Twilio
5
+ module Webhooks
6
+ class CustomerProfiles < Base
7
+ URL = "/webhooks/twilio/customer_profiles_compliance"
8
+
9
+ def self.trigger(sid, status)
10
+ # Wait simulation from twilio
11
+ sleep DELAY.sample
12
+
13
+ request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
14
+
15
+ data = { :BundleSid=>sid, :Status=>status }
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, response.body
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/mock/twilio.rb CHANGED
@@ -4,11 +4,13 @@ require "rufus-scheduler"
4
4
  require "active_support"
5
5
  require "active_support/core_ext/time"
6
6
  require_relative "twilio/middleware/proxy"
7
- require_relative "twilio/schemas/api_2010"
8
- require_relative "twilio/schemas/messaging_v1"
9
7
  require_relative "twilio/webhook_client"
10
8
  require_relative "twilio/webhooks/base"
11
9
  require_relative "twilio/webhooks/messages"
10
+ require_relative "twilio/webhooks/calls"
11
+ require_relative "twilio/webhooks/call_status_updates"
12
+ require_relative "twilio/webhooks/conferences"
13
+ require_relative "twilio/webhooks/customer_profiles"
12
14
  require_relative "twilio/util/configuration"
13
15
  require_relative "twilio/client"
14
16
  require_relative "twilio/decorator"
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: 0.2.0
4
+ version: 0.4.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-06-10 00:00:00.000000000 Z
11
+ date: 2024-07-01 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
- version: '2.7'
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
- version: '2.7'
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
- version: '0'
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
- version: '0'
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: '0'
47
+ version: 6.7.1
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: '0'
54
+ version: 6.7.1
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: '0'
61
+ version: 7.1.3.4
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: '0'
68
+ version: 7.1.3.4
69
69
  description: This repository contains Mock::Twilio::Client for Twilio's API.
70
70
  email:
71
71
  executables: []
@@ -80,14 +80,30 @@ files:
80
80
  - lib/mock/twilio.rb
81
81
  - lib/mock/twilio/client.rb
82
82
  - lib/mock/twilio/decorator.rb
83
+ - lib/mock/twilio/decorators/api_2010/addresses.rb
84
+ - lib/mock/twilio/decorators/api_2010/calls.rb
85
+ - lib/mock/twilio/decorators/api_2010/conferences_participants_create.rb
86
+ - lib/mock/twilio/decorators/api_2010/conferences_participants_update.rb
87
+ - lib/mock/twilio/decorators/api_2010/messages.rb
88
+ - lib/mock/twilio/decorators/customer_profiles_v1/customer_profile.rb
89
+ - lib/mock/twilio/decorators/customer_profiles_v1/entity_assignments.rb
90
+ - lib/mock/twilio/decorators/customer_profiles_v1/evaluations.rb
83
91
  - lib/mock/twilio/middleware/proxy.rb
84
92
  - lib/mock/twilio/response.rb
85
93
  - lib/mock/twilio/schemas/api_2010.rb
94
+ - lib/mock/twilio/schemas/customer_profiles_v1.rb
95
+ - lib/mock/twilio/schemas/end_users_v1.rb
86
96
  - lib/mock/twilio/schemas/messaging_v1.rb
97
+ - lib/mock/twilio/schemas/phone_numbers_v2.rb
98
+ - lib/mock/twilio/schemas/supporting_documents_v1.rb
87
99
  - lib/mock/twilio/util/configuration.rb
88
100
  - lib/mock/twilio/version.rb
89
101
  - lib/mock/twilio/webhook_client.rb
90
102
  - lib/mock/twilio/webhooks/base.rb
103
+ - lib/mock/twilio/webhooks/call_status_updates.rb
104
+ - lib/mock/twilio/webhooks/calls.rb
105
+ - lib/mock/twilio/webhooks/conferences.rb
106
+ - lib/mock/twilio/webhooks/customer_profiles.rb
91
107
  - lib/mock/twilio/webhooks/messages.rb
92
108
  - sig/mock/twilio.rbs
93
109
  homepage: https://github.com/schoolstatus/mock-twilio
@@ -95,8 +111,8 @@ licenses:
95
111
  - MIT
96
112
  metadata:
97
113
  homepage_uri: https://github.com/schoolstatus/mock-twilio
98
- source_code_uri: https://github.com/schoolstatus/mock-twilio.
99
- changelog_uri: https://github.com/schoolstatus/mock-twilio/CHANGELOG.md
114
+ source_code_uri: https://github.com/schoolstatus/mock-twilio
115
+ changelog_uri: https://github.com/schoolstatus/mock-twilio/blob/main/CHANGELOG.md
100
116
  post_install_message:
101
117
  rdoc_options: []
102
118
  require_paths:
@@ -112,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
128
  - !ruby/object:Gem::Version
113
129
  version: '0'
114
130
  requirements: []
115
- rubygems_version: 3.4.19
131
+ rubygems_version: 3.5.12
116
132
  signing_key:
117
133
  specification_version: 4
118
134
  summary: This repository contains Mock::Twilio::Client for Twilio's API.