sendly 3.8.2 → 3.10.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: c6f94a917e0e9fe4109e3edc96008fc4381797e46e494f22834f74b4905cdd9c
4
- data.tar.gz: fcf628838872a190ae6e4c54e2b9be79689d3f1500bac36938daff8e1b6df38e
3
+ metadata.gz: 7758a53dce946b2294f1760a7e4741c4bdc927da246ab81d6f5cf3425518a1fd
4
+ data.tar.gz: b8cecc7352f2da3eb75bd66fc722a1cb7c2d4a2f49b148ed41ae10ed742e64a7
5
5
  SHA512:
6
- metadata.gz: b07d5bcaadfabd4f532cc27e3179dea0a5356b27492fde834682ae033565feea85a6a0254dfdaa30a927851e08f668b9b4bf09f4dac59cb232d3a5cb6b30033d
7
- data.tar.gz: 40741e416c8d3a91abd08414c5066180828a582af6782250b7975c50c8b653167cf960067acb1bde3e8e9501abfc7572914da7b547efcc4ff7289281dbaff41d
6
+ metadata.gz: 73549a842bc7be6923f04917bfc4ddc52822d20ba36cec9fdf50ea4d2110cdd1529d3f5cca56b301f7e9e15167db1140f67164ff92ca071af35fd648a3879d39
7
+ data.tar.gz: 428c9df2724d1deafce9ee04e7d47aa7bd99c3d896e61a8306ef469666e572a0a9a766d56d34d5e11ce0fb92377e3d316873c8db3012f50b7fbdbc1efb50d108
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sendly (3.8.2)
4
+ sendly (3.10.0)
5
5
  faraday (~> 2.0)
6
6
  faraday-retry (~> 2.0)
7
7
 
data/lib/sendly/client.rb CHANGED
@@ -59,6 +59,20 @@ module Sendly
59
59
  @account ||= AccountResource.new(self)
60
60
  end
61
61
 
62
+ # Access the Verify resource
63
+ #
64
+ # @return [Sendly::VerifyResource]
65
+ def verify
66
+ @verify ||= VerifyResource.new(self)
67
+ end
68
+
69
+ # Access the Templates resource
70
+ #
71
+ # @return [Sendly::TemplatesResource]
72
+ def templates
73
+ @templates ||= TemplatesResource.new(self)
74
+ end
75
+
62
76
  # Make a GET request
63
77
  #
64
78
  # @param path [String] API path
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendly
4
+ class Template
5
+ attr_reader :id, :name, :body, :type, :locale, :variables, :is_default,
6
+ :is_published, :created_at, :updated_at
7
+
8
+ TYPES = %w[preset custom].freeze
9
+
10
+ def initialize(data)
11
+ @id = data["id"]
12
+ @name = data["name"]
13
+ @body = data["body"]
14
+ @type = data["type"] || "custom"
15
+ @locale = data["locale"]
16
+ @variables = data["variables"] || []
17
+ @is_default = data["isDefault"] || data["is_default"] || false
18
+ @is_published = data["isPublished"] || data["is_published"] || false
19
+ @created_at = parse_time(data["createdAt"] || data["created_at"])
20
+ @updated_at = parse_time(data["updatedAt"] || data["updated_at"])
21
+ end
22
+
23
+ def preset?
24
+ type == "preset"
25
+ end
26
+
27
+ def custom?
28
+ type == "custom"
29
+ end
30
+
31
+ def published?
32
+ is_published
33
+ end
34
+
35
+ def to_h
36
+ {
37
+ id: id, name: name, body: body, type: type, locale: locale,
38
+ variables: variables, is_default: is_default, is_published: is_published,
39
+ created_at: created_at&.iso8601, updated_at: updated_at&.iso8601
40
+ }.compact
41
+ end
42
+
43
+ private
44
+
45
+ def parse_time(value)
46
+ return nil if value.nil?
47
+ Time.parse(value)
48
+ rescue ArgumentError
49
+ nil
50
+ end
51
+ end
52
+
53
+ class TemplatesResource
54
+ def initialize(client)
55
+ @client = client
56
+ end
57
+
58
+ def list(limit: nil, type: nil, locale: nil)
59
+ params = {}
60
+ params[:limit] = limit if limit
61
+ params[:type] = type if type
62
+ params[:locale] = locale if locale
63
+
64
+ response = @client.get("/verify/templates", params)
65
+ templates = (response["templates"] || []).map { |t| Template.new(t) }
66
+ { templates: templates, pagination: response["pagination"] }
67
+ end
68
+
69
+ def get(id)
70
+ response = @client.get("/verify/templates/#{id}")
71
+ Template.new(response)
72
+ end
73
+
74
+ def create(name:, body:, locale: nil, is_published: nil)
75
+ request_body = { name: name, body: body }
76
+ request_body[:locale] = locale if locale
77
+ request_body[:isPublished] = is_published unless is_published.nil?
78
+
79
+ response = @client.post("/verify/templates", request_body)
80
+ Template.new(response)
81
+ end
82
+
83
+ def update(id, name: nil, body: nil, locale: nil, is_published: nil)
84
+ request_body = {}
85
+ request_body[:name] = name if name
86
+ request_body[:body] = body if body
87
+ request_body[:locale] = locale if locale
88
+ request_body[:isPublished] = is_published unless is_published.nil?
89
+
90
+ response = @client.patch("/verify/templates/#{id}", request_body)
91
+ Template.new(response)
92
+ end
93
+
94
+ def delete(id)
95
+ @client.delete("/verify/templates/#{id}")
96
+ end
97
+
98
+ def publish(id)
99
+ response = @client.post("/verify/templates/#{id}/publish")
100
+ Template.new(response)
101
+ end
102
+
103
+ def unpublish(id)
104
+ response = @client.post("/verify/templates/#{id}/unpublish")
105
+ Template.new(response)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendly
4
+ class Verification
5
+ attr_reader :id, :status, :phone, :delivery_status, :attempts, :max_attempts,
6
+ :channel, :expires_at, :verified_at, :created_at, :sandbox,
7
+ :app_name, :template_id, :profile_id, :metadata
8
+
9
+ STATUSES = %w[pending verified expired failed].freeze
10
+ CHANNELS = %w[sms whatsapp email].freeze
11
+
12
+ def initialize(data)
13
+ @id = data["id"]
14
+ @status = data["status"]
15
+ @phone = data["phone"]
16
+ @delivery_status = data["deliveryStatus"] || data["delivery_status"]
17
+ @attempts = data["attempts"] || 0
18
+ @max_attempts = data["maxAttempts"] || data["max_attempts"] || 3
19
+ @channel = data["channel"] || "sms"
20
+ @expires_at = parse_time(data["expiresAt"] || data["expires_at"])
21
+ @verified_at = parse_time(data["verifiedAt"] || data["verified_at"])
22
+ @created_at = parse_time(data["createdAt"] || data["created_at"])
23
+ @sandbox = data["sandbox"] || false
24
+ @app_name = data["appName"] || data["app_name"]
25
+ @template_id = data["templateId"] || data["template_id"]
26
+ @profile_id = data["profileId"] || data["profile_id"]
27
+ @metadata = data["metadata"] || {}
28
+ end
29
+
30
+ def pending?
31
+ status == "pending"
32
+ end
33
+
34
+ def verified?
35
+ status == "verified"
36
+ end
37
+
38
+ def expired?
39
+ status == "expired"
40
+ end
41
+
42
+ def failed?
43
+ status == "failed"
44
+ end
45
+
46
+ def to_h
47
+ {
48
+ id: id, status: status, phone: phone, delivery_status: delivery_status,
49
+ attempts: attempts, max_attempts: max_attempts, channel: channel,
50
+ expires_at: expires_at&.iso8601, verified_at: verified_at&.iso8601,
51
+ created_at: created_at&.iso8601, sandbox: sandbox, app_name: app_name,
52
+ template_id: template_id, profile_id: profile_id, metadata: metadata
53
+ }.compact
54
+ end
55
+
56
+ private
57
+
58
+ def parse_time(value)
59
+ return nil if value.nil?
60
+ Time.parse(value)
61
+ rescue ArgumentError
62
+ nil
63
+ end
64
+ end
65
+
66
+ class SendVerificationResponse
67
+ attr_reader :verification, :code
68
+
69
+ def initialize(data)
70
+ @verification = Verification.new(data["verification"])
71
+ @code = data["code"]
72
+ end
73
+ end
74
+
75
+ class CheckVerificationResponse
76
+ attr_reader :valid, :status, :verification
77
+
78
+ def initialize(data)
79
+ @valid = data["valid"]
80
+ @status = data["status"]
81
+ @verification = data["verification"] ? Verification.new(data["verification"]) : nil
82
+ end
83
+
84
+ def valid?
85
+ valid
86
+ end
87
+ end
88
+
89
+ class VerifyResource
90
+ def initialize(client)
91
+ @client = client
92
+ end
93
+
94
+ def send(phone:, channel: nil, code_length: nil, expires_in: nil, max_attempts: nil,
95
+ template_id: nil, profile_id: nil, app_name: nil, locale: nil, metadata: nil)
96
+ body = { phone: phone }
97
+ body[:channel] = channel if channel
98
+ body[:codeLength] = code_length if code_length
99
+ body[:expiresIn] = expires_in if expires_in
100
+ body[:maxAttempts] = max_attempts if max_attempts
101
+ body[:templateId] = template_id if template_id
102
+ body[:profileId] = profile_id if profile_id
103
+ body[:appName] = app_name if app_name
104
+ body[:locale] = locale if locale
105
+ body[:metadata] = metadata if metadata
106
+
107
+ response = @client.post("/verify", body)
108
+ SendVerificationResponse.new(response)
109
+ end
110
+
111
+ def resend(id)
112
+ response = @client.post("/verify/#{id}/resend")
113
+ SendVerificationResponse.new(response)
114
+ end
115
+
116
+ def check(id, code:)
117
+ response = @client.post("/verify/#{id}/check", { code: code })
118
+ CheckVerificationResponse.new(response)
119
+ end
120
+
121
+ def get(id)
122
+ response = @client.get("/verify/#{id}")
123
+ Verification.new(response)
124
+ end
125
+
126
+ def list(limit: nil, status: nil, phone: nil)
127
+ params = {}
128
+ params[:limit] = limit if limit
129
+ params[:status] = status if status
130
+ params[:phone] = phone if phone
131
+
132
+ response = @client.get("/verify", params)
133
+ verifications = (response["verifications"] || []).map { |v| Verification.new(v) }
134
+ { verifications: verifications, pagination: response["pagination"] }
135
+ end
136
+ end
137
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sendly
4
- VERSION = "3.8.2"
4
+ VERSION = "3.10.0"
5
5
  end
data/lib/sendly.rb CHANGED
@@ -11,6 +11,8 @@ require_relative "sendly/messages"
11
11
  require_relative "sendly/webhooks"
12
12
  require_relative "sendly/webhooks_resource"
13
13
  require_relative "sendly/account_resource"
14
+ require_relative "sendly/verify"
15
+ require_relative "sendly/templates_resource"
14
16
 
15
17
  # Sendly Ruby SDK
16
18
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendly
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.2
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sendly
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-04 00:00:00.000000000 Z
11
+ date: 2026-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -127,7 +127,9 @@ files:
127
127
  - lib/sendly/client.rb
128
128
  - lib/sendly/errors.rb
129
129
  - lib/sendly/messages.rb
130
+ - lib/sendly/templates_resource.rb
130
131
  - lib/sendly/types.rb
132
+ - lib/sendly/verify.rb
131
133
  - lib/sendly/version.rb
132
134
  - lib/sendly/webhooks.rb
133
135
  - lib/sendly/webhooks_resource.rb