mock-twilio 0.3.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: 2832d75e6a41828ad36e39908bc9316a8d851ced711843a9ec3142e46ac65a04
4
- data.tar.gz: d20f52b78ef3d357e1210100b874ab08e35429993ee3c7499077267e40f25733
3
+ metadata.gz: 1fa25d49f6ae4eb3c3660e470478b6bd9ed803c55a106ce81b24698ecef8eaf8
4
+ data.tar.gz: b1ce1de75fba85aaae12cf95d0b09444f668319ea9481efeea5ff461f1e61240
5
5
  SHA512:
6
- metadata.gz: 73a12decb37e2c63b6ab66d2d74fa49d9a281bd8a4391ed321a44f4dfb83ae81946a80e1d26f18903185e5393267714184bab959d8b073dd52d2dd8196aed0d1
7
- data.tar.gz: cbdabf698e265893034d10ff001d7ae01ca035e8da18af469b1fbb9c399425e509bc3d49be40c6cb72b418ea86dc53f2336cc8cc75dce4cc6ecc2e262912a84c
6
+ metadata.gz: fb1170b5cc6d024c6423bc70c1f3d0db6589e93e1e6adf9f6ef84df960fe84ef0ac4ed1eaa284b64b66fbaf67aec9d8e46ae1a4aa380ca6e96ea882ca04bfcd3
7
+ data.tar.gz: e3e1defce5ed25b23e170cf068958b2144eabbae4544dfe80222c9385c14d74affc2a35c3bf1a156105b60e37ad43834fd90de98f67efc8f5d7cdb653ac42eed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  ## [0.3.0] - 2024-06-24
2
10
  - Support Calls service
3
11
  - Support Conferences service
@@ -2,6 +2,10 @@
2
2
 
3
3
  require_relative "schemas/api_2010"
4
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"
5
9
 
6
10
  module Mock
7
11
  module Twilio
@@ -9,6 +13,10 @@ module Mock
9
13
  ENDPOINTS = {
10
14
  api_2010: Mock::Twilio::Schemas::Api2010,
11
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
12
20
  }
13
21
 
14
22
  class << self
@@ -35,6 +43,14 @@ module Mock
35
43
  :api_2010
36
44
  when %r{\/v1/Services/[A-Za-z0-9]+/}
37
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
38
54
  end
39
55
  end
40
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,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
@@ -4,6 +4,7 @@ require_relative "../decorators/api_2010/messages"
4
4
  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
+ require_relative "../decorators/api_2010/addresses"
7
8
 
8
9
  module Mock
9
10
  module Twilio
@@ -15,6 +16,7 @@ module Mock
15
16
  calls: Mock::Twilio::Decorators::Api2010::Calls,
16
17
  conferences_participants_update: Mock::Twilio::Decorators::Api2010::ConferencesParticipantsUpdate,
17
18
  conferences_participants_create: Mock::Twilio::Decorators::Api2010::ConferencesParticipantsCreate,
19
+ addresses: Mock::Twilio::Decorators::Api2010::Addresses,
18
20
  }
19
21
 
20
22
  PAGES_KEYS = [
@@ -43,6 +45,8 @@ module Mock
43
45
  RESOURCES[:conferences_participants_update].decorate(body, request)
44
46
  when %r{\/2010-04-01/Accounts/[A-Za-z0-9]+/Conferences/[A-Za-z0-9]+/Participants.json}
45
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)
46
50
  end
47
51
  end
48
52
  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.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  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
@@ -10,6 +10,7 @@ require_relative "twilio/webhooks/messages"
10
10
  require_relative "twilio/webhooks/calls"
11
11
  require_relative "twilio/webhooks/call_status_updates"
12
12
  require_relative "twilio/webhooks/conferences"
13
+ require_relative "twilio/webhooks/customer_profiles"
13
14
  require_relative "twilio/util/configuration"
14
15
  require_relative "twilio/client"
15
16
  require_relative "twilio/decorator"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock-twilio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.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-24 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
@@ -80,14 +80,22 @@ 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
83
84
  - lib/mock/twilio/decorators/api_2010/calls.rb
84
85
  - lib/mock/twilio/decorators/api_2010/conferences_participants_create.rb
85
86
  - lib/mock/twilio/decorators/api_2010/conferences_participants_update.rb
86
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
87
91
  - lib/mock/twilio/middleware/proxy.rb
88
92
  - lib/mock/twilio/response.rb
89
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
90
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
91
99
  - lib/mock/twilio/util/configuration.rb
92
100
  - lib/mock/twilio/version.rb
93
101
  - lib/mock/twilio/webhook_client.rb
@@ -95,6 +103,7 @@ files:
95
103
  - lib/mock/twilio/webhooks/call_status_updates.rb
96
104
  - lib/mock/twilio/webhooks/calls.rb
97
105
  - lib/mock/twilio/webhooks/conferences.rb
106
+ - lib/mock/twilio/webhooks/customer_profiles.rb
98
107
  - lib/mock/twilio/webhooks/messages.rb
99
108
  - sig/mock/twilio.rbs
100
109
  homepage: https://github.com/schoolstatus/mock-twilio