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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3da0ed4a9e8746dd8609affeb9cf316a156dafa9a20b0da5e5307c37ea95ad0
4
- data.tar.gz: 647d377b97c2fc7951ecd61f3caeb100b5d4ceeb8e1a8d788a5ba0b623a60ef9
3
+ metadata.gz: ad98e587f9dba0c2812169dfc04958634e683ebc2e2208b1d693e7de8f90b543
4
+ data.tar.gz: 1515528e3fcbe515f6831f21fa859214a8c2d274cb79ad4341db5808550d1a77
5
5
  SHA512:
6
- metadata.gz: 375a364348e16d823426c5670e22a900f52d50d5ee9ac2405f80cd6cd9e3cd7052e20d2d8511f50d44036f579ce273d8a2929908f470fd01aeeaf576e0ec6993
7
- data.tar.gz: 97361223e531df80107ed916fa9f81774a9a8694a2e9df8b7acc5dd58468f02c10616df901e798d88f3be3e93b9f1cd4b4c8a3952525ab618378ea1d5a520063
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
@@ -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
@@ -1,5 +1,11 @@
1
1
  module Twi
2
2
  class Error < StandardError
3
+ attr_reader :code
4
+
5
+ def initialize(attributes = {})
6
+ @code = attributes[:code]
7
+ super attributes[:message]
8
+ end
3
9
  end
4
10
 
5
11
  class ExistingConversationError < Error
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
- # todo rescue and then set @code
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
- if Twi.mock.conversation_error[:code] == 50438
6
- raise ExistingConversationError.new(Twi.mock.conversation_error[:message])
7
- elsif Twi.mock.conversation_error[:code] == 50214
8
- Twi.mock.conversation_error = nil
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]
@@ -4,9 +4,16 @@ module Twi
4
4
  def id = @params[:id]
5
5
 
6
6
  def create
7
- @id = "SM#{rand}"
8
- @status = 'delivered'
9
- # todo rescue and then set @code
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, :message, :conversation, :conversation_error, :medium
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twi
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo