twi 0.3.0 → 0.3.2
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 +8 -0
- data/lib/twi/conversation.rb +6 -0
- data/lib/twi/delivery.rb +8 -0
- data/lib/twi/error.rb +6 -0
- data/lib/twi/message.rb +8 -1
- data/lib/twi/mock/conversation.rb +5 -6
- data/lib/twi/mock/message.rb +10 -3
- data/lib/twi/mock.rb +4 -1
- data/lib/twi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad98e587f9dba0c2812169dfc04958634e683ebc2e2208b1d693e7de8f90b543
|
|
4
|
+
data.tar.gz: 1515528e3fcbe515f6831f21fa859214a8c2d274cb79ad4341db5808550d1a77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20029e35bb9768472e97be71146d350879ea694453e835f248892f78306e8aa41d4da8d8a497ee71144f62d6f3d0a82a537d0aa3647ba2d7d83697502a24dbd5
|
|
7
|
+
data.tar.gz: 3f766ce5571a8cc438ea37c2bc2aed10f92ea1aa5f12606fca36691a7ab86fb2486651f8d74478fc794bdf3187f67be5789b394b810ac86bf2dbcd52fd14cb50
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [0.3.2] - 2026-06-01
|
|
2
|
+
|
|
3
|
+
- [New] Add Twi::Message.url_for, Twi::Delivery.url_for, Twi::Delivery.unsubscribed?
|
|
4
|
+
|
|
5
|
+
## [0.3.1] - 2026-06-01
|
|
6
|
+
|
|
7
|
+
- [New] Raise Twi::Error, not Twilio::REST::RestError
|
|
8
|
+
|
|
1
9
|
## [0.3.0] - 2026-05-27
|
|
2
10
|
|
|
3
11
|
- [New] Add Twi::Message#create
|
data/lib/twi/conversation.rb
CHANGED
|
@@ -30,6 +30,12 @@ module Twi
|
|
|
30
30
|
conversation.delete
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def url
|
|
34
|
+
url = "/console/conversations/services/#{Twi.lio.conversation_sid}/conversations/#{id}/messages"
|
|
35
|
+
query = "currentFrameUrl=#{CGI.escape url}"
|
|
36
|
+
"https://console.twilio.com/us1/develop/conversations/manage/services?#{query}"
|
|
37
|
+
end
|
|
38
|
+
|
|
33
39
|
def create_message(content:, image_ids: [])
|
|
34
40
|
conversation.messages.create **message_params_for(content, image_ids)
|
|
35
41
|
end
|
data/lib/twi/delivery.rb
CHANGED
|
@@ -12,6 +12,14 @@ module Twi
|
|
|
12
12
|
# @return [String, nil] error code
|
|
13
13
|
def code = @params['ErrorCode']
|
|
14
14
|
|
|
15
|
+
# @return [String] documentation URL for given error code.
|
|
16
|
+
def self.url_for(code)
|
|
17
|
+
"https://www.twilio.com/docs/api/errors/#{code}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [Boolean] whether the delivery failed because the recipient unsubscribed.
|
|
21
|
+
def self.unsubscribed?(code) = code.eql? '21610'
|
|
22
|
+
|
|
15
23
|
# @return [Hash] the shape of the payload send by Twilio to the callback URL.
|
|
16
24
|
def self.params_for(id:, status:, code: nil)
|
|
17
25
|
{ SmsSid: id, MessageStatus: status, ErrorCode: code }
|
data/lib/twi/error.rb
CHANGED
data/lib/twi/message.rb
CHANGED
|
@@ -30,6 +30,12 @@ module Twi
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# @return [String] log URL for given message.
|
|
34
|
+
def self.url_for(id)
|
|
35
|
+
account_sid = Twi.lio.account_sid
|
|
36
|
+
"https://console.twilio.com/us1/monitor/logs/sms/#{account_sid}/#{id}"
|
|
37
|
+
end
|
|
38
|
+
|
|
33
39
|
attr_reader :status
|
|
34
40
|
|
|
35
41
|
# Sends a message.
|
|
@@ -39,7 +45,8 @@ module Twi
|
|
|
39
45
|
|
|
40
46
|
@id = message.sid
|
|
41
47
|
@status = message.status
|
|
42
|
-
|
|
48
|
+
rescue Twilio::REST::RestError => error
|
|
49
|
+
raise Error, error
|
|
43
50
|
end
|
|
44
51
|
|
|
45
52
|
# @return [Hash] the shape of the payload send by Twilio to the callback URL.
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
module Twi
|
|
2
2
|
class Mock::Conversation < Conversation
|
|
3
3
|
def create_with(participants:)
|
|
4
|
-
if Twi.mock.conversation_error
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
raise TooManyConversationsError
|
|
4
|
+
if error = Twi.mock.conversation_error
|
|
5
|
+
Twi.mock.conversation_error = nil
|
|
6
|
+
case error[:code]
|
|
7
|
+
when 50438 then raise ExistingConversationError.new(error)
|
|
8
|
+
when 50214 then raise TooManyConversationsError.new(error)
|
|
10
9
|
end
|
|
11
10
|
elsif Twi.mock.conversation
|
|
12
11
|
@id = Twi.mock.conversation[:id]
|
data/lib/twi/mock/message.rb
CHANGED
|
@@ -4,9 +4,16 @@ module Twi
|
|
|
4
4
|
def id = @params[:id]
|
|
5
5
|
|
|
6
6
|
def create
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if error = Twi.mock.message_error
|
|
8
|
+
Twi.mock.message_error = nil
|
|
9
|
+
raise Error, error
|
|
10
|
+
elsif Twi.mock.message
|
|
11
|
+
@id = Twi.mock.message[:id]
|
|
12
|
+
@status = Twi.mock.message[:status]
|
|
13
|
+
else
|
|
14
|
+
@id = "SM#{rand}"
|
|
15
|
+
@status = 'delivered'
|
|
16
|
+
end
|
|
10
17
|
end
|
|
11
18
|
end
|
|
12
19
|
end
|
data/lib/twi/mock.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
module Twi
|
|
2
2
|
class Mock
|
|
3
|
-
attr_accessor :phone, :phone_error
|
|
3
|
+
attr_accessor :phone, :phone_error
|
|
4
|
+
attr_accessor :message, :message_error
|
|
5
|
+
attr_accessor :conversation, :conversation_error
|
|
6
|
+
attr_accessor :medium
|
|
4
7
|
end
|
|
5
8
|
end
|
data/lib/twi/version.rb
CHANGED