mock-twilio 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +32 -1
- data/lib/mock/twilio/decorators/api_2010/messages.rb +10 -1
- data/lib/mock/twilio/version.rb +1 -1
- data/lib/mock/twilio/webhooks/inbound_messages.rb +65 -0
- data/lib/mock/twilio.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1da1ec05dd743344d3013c3f39a42923a3169f1712f5888379d404d29c437f0f
|
4
|
+
data.tar.gz: 59529b53405a1ea90813af0d41174a98a197a19c05b1b38968883e98fb7c8284
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5663f1c128513d140c75d2505c85e1e77c71c226889d1aa3a230df2764f7d4010964f2781c895508c5a2eb3df2d60225aa7f74e64df1c3d0e6583e5fff4e8659
|
7
|
+
data.tar.gz: 07ef35f9b4ee075fb4af82ffb03e02b5e6bb4af1dc9d324c9a0c4de7590a4c29314c58933798ab53bc0bd3859bdec6410c6d506eb03171207381b343467b90ac
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,38 @@ OR
|
|
26
26
|
- `proxy_port = 4010`
|
27
27
|
- `proxy_protocol = http`
|
28
28
|
|
29
|
+
## Features Support
|
30
|
+
|
31
|
+
| Mock::Twilio::Client | Support |
|
32
|
+
| ------------- | ------------- |
|
33
|
+
| `client.messages.create(to: "+593978613041", body: "Testing SMS", from: "+13212855389")` | :white_check_mark: |
|
34
|
+
| `client.messaging.v1.services("MG"+"F"*32).phone_numbers.create(phone_number_sid: @phone_number_sid)` | :white_check_mark: |
|
35
|
+
| `client.available_phone_numbers('US').local.list(limit: 20)` | :white_check_mark: |
|
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")` | :white_check_mark: |
|
37
|
+
| `client.lookups.v2.phone_numbers("+14159929960").fetch(fields: :line_type_intelligence)` | :white_check_mark: |
|
38
|
+
| `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')` | :white_check_mark: |
|
39
|
+
| `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')` | :white_check_mark: |
|
40
|
+
| `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` | :white_check_mark: |
|
41
|
+
| `client.trusthub.v1.customer_profiles(customer_profile_sid).customer_profiles_entity_assignments.create(object_sid:)` | :white_check_mark: |
|
42
|
+
| `client.trusthub.v1.end_users.create(**twilio_parameters)` | :white_check_mark: |
|
43
|
+
| `client.trusthub.v1.supporting_documents.create(**twilio_parameters)` | :white_check_mark: |
|
44
|
+
| `client.addresses.create(**twilio_parameters)` | :white_check_mark: |
|
45
|
+
| `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` | :white_check_mark: |
|
46
|
+
| `client.trusthub.v1.customer_profiles(customer_profile.sid).customer_profiles_evaluations.create(policy_sid:)` | :white_check_mark: |
|
47
|
+
|
48
|
+
|
49
|
+
## Trigger resources updates
|
50
|
+
|
51
|
+
| Mock::Twilio::Webhooks | Support |
|
52
|
+
| ------------- | ------------- |
|
53
|
+
| `Webhooks::Messages` | :white_check_mark: |
|
54
|
+
| `Webhooks::InboundMessages` | :white_check_mark: |
|
55
|
+
| `Webhooks::Calls` | :white_check_mark: |
|
56
|
+
| `Webhooks::CallStatusUpdates` | :white_check_mark: |
|
57
|
+
| `Webhooks::Conferences` | :white_check_mark: |
|
58
|
+
| `Webhooks::CustomerProfiles` | :white_check_mark: |
|
59
|
+
| `Webhooks::Brands` | :white_check_mark: |
|
60
|
+
|
29
61
|
## How to use
|
30
62
|
Initializer sample
|
31
63
|
```ruby
|
@@ -35,7 +67,6 @@ Mock::Twilio.configure do |config|
|
|
35
67
|
config.port = "3000"
|
36
68
|
config.proto = "http"
|
37
69
|
end
|
38
|
-
|
39
70
|
```
|
40
71
|
|
41
72
|
Example
|
@@ -14,8 +14,12 @@ module Mock
|
|
14
14
|
body["end_time"] = Time.current.rfc2822 if body["end_time"]
|
15
15
|
|
16
16
|
message_sid(body, request) if body["sid"]
|
17
|
+
body["messaging_service_sid"] = request.data["MessagingServiceSid"] if request.data["MessagingServiceSid"]
|
17
18
|
pagination(body) if body["available_phone_numbers"]
|
18
19
|
|
20
|
+
body["to"] = request.data["To"] if request.data["To"]
|
21
|
+
body["from"] = request.data["From"] if request.data["From"]
|
22
|
+
|
19
23
|
body
|
20
24
|
end
|
21
25
|
|
@@ -33,7 +37,12 @@ module Mock
|
|
33
37
|
scheduler = Rufus::Scheduler.new
|
34
38
|
scheduler.in '2s' do
|
35
39
|
begin
|
36
|
-
Mock::Twilio::Webhooks::Messages.trigger(sid)
|
40
|
+
response = Mock::Twilio::Webhooks::Messages.trigger(sid)
|
41
|
+
|
42
|
+
if response.success? && request.data["Body"].downcase.include?("inbound")
|
43
|
+
inbound_sid = prefix + SecureRandom.hex(16)
|
44
|
+
Mock::Twilio::Webhooks::InboundMessages.trigger(inbound_sid, request.data)
|
45
|
+
end
|
37
46
|
rescue => e
|
38
47
|
puts e
|
39
48
|
end
|
data/lib/mock/twilio/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Webhooks
|
6
|
+
class InboundMessages < Base
|
7
|
+
URL = "/api/v1/twilio_requests/inbound"
|
8
|
+
|
9
|
+
def self.trigger(sid, params)
|
10
|
+
raise Webhooks::RestError, "Invalid Inbound message data" if params['To'].empty? || params['From'].empty?
|
11
|
+
# Wait simulation from twilio
|
12
|
+
sleep DELAY.sample
|
13
|
+
|
14
|
+
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
15
|
+
|
16
|
+
data = inbound_data(sid, params)
|
17
|
+
|
18
|
+
signature = build_signature_for_request(request_url, data)
|
19
|
+
|
20
|
+
response = webhook_client.request(Mock::Twilio.host,
|
21
|
+
Mock::Twilio.port,
|
22
|
+
'POST',
|
23
|
+
URL,
|
24
|
+
nil,
|
25
|
+
data,
|
26
|
+
headers.merge!({ 'X-Twilio-Signature': signature }),
|
27
|
+
auth_twilio,
|
28
|
+
nil)
|
29
|
+
case response.status
|
30
|
+
when 200..204
|
31
|
+
response
|
32
|
+
when 400..600
|
33
|
+
raise Webhooks::RestError, Mock::Twilio::ErrorHandler.new(response).raise
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.inbound_data(sid, params)
|
38
|
+
{
|
39
|
+
"ToCountry": "US",
|
40
|
+
"ToState": "MS",
|
41
|
+
"SmsMessageSid": sid,
|
42
|
+
"NumMedia": "0",
|
43
|
+
"ToCity": "SARDIS",
|
44
|
+
"FromZip": "98315",
|
45
|
+
"SmsSid": sid,
|
46
|
+
"FromState": "WA",
|
47
|
+
"SmsStatus": "received",
|
48
|
+
"FromCity": "SILVERDALE",
|
49
|
+
"Body": "Inbound::Message mock reply",
|
50
|
+
"FromCountry": "US",
|
51
|
+
"To": params["To"],
|
52
|
+
"MessagingServiceSid": params['MessagingServiceSid'],
|
53
|
+
"ToZip": "38666",
|
54
|
+
"AddOns": "{\"status\":\"successful\",\"message\":null,\"code\":null,\"results\":{}}",
|
55
|
+
"NumSegments": "1",
|
56
|
+
"MessageSid": sid,
|
57
|
+
"AccountSid": ::Twilio.account_sid,
|
58
|
+
"From": params["From"],
|
59
|
+
"ApiVersion": "2010-04-01"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/mock/twilio.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative "twilio/webhooks/call_status_updates"
|
|
13
13
|
require_relative "twilio/webhooks/conferences"
|
14
14
|
require_relative "twilio/webhooks/customer_profiles"
|
15
15
|
require_relative "twilio/webhooks/brands"
|
16
|
+
require_relative "twilio/webhooks/inbound_messages"
|
16
17
|
require_relative "twilio/util/configuration"
|
17
18
|
require_relative "twilio/util/error_handler"
|
18
19
|
require_relative "twilio/util/generator"
|
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.
|
4
|
+
version: 1.0.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-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/mock/twilio/webhooks/calls.rb
|
118
118
|
- lib/mock/twilio/webhooks/conferences.rb
|
119
119
|
- lib/mock/twilio/webhooks/customer_profiles.rb
|
120
|
+
- lib/mock/twilio/webhooks/inbound_messages.rb
|
120
121
|
- lib/mock/twilio/webhooks/messages.rb
|
121
122
|
- lib/twilio/rest/messaging/v1/service/phone_number_decorator.rb
|
122
123
|
- sig/mock/twilio.rbs
|