sendly 3.8.1 → 3.9.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: b353bcac8423f595cc655af69df19ac4af9afd9f3d830cc7ac0c59842ae7a73f
4
- data.tar.gz: ca2e303192d3b22856595bf9981eb28edd3c5ba5f500f544ffeda4783bd28893
3
+ metadata.gz: b564f46a8ec165fd80f89040c26500ab232c68cdff29779b64f3c00aeb4a0d81
4
+ data.tar.gz: ca4a52d6b2fedc6ff013fd15522f89f7332bc2c994074f00de2981514e268294
5
5
  SHA512:
6
- metadata.gz: fc1fd77a1fef96c5938c35b4dc948954e24974ae107a7744ddbcfb5d11a15fd744616b0053c2af19fd7cb7b3c8410de2751cb077e1697fb1b48061d10d52d71b
7
- data.tar.gz: c2f010e7116ad34275cf88132cc7a8f3874c1b95081597b250d41088780f1662a5367587a7d2b76123fdc4f6d3bf25b42180183e925bfeab58c43b516ee9d78b
6
+ metadata.gz: c00792a9939c92f353dce974493a583bf1ef86a48dcff2bf822679bd513fd5e481f649f297a0e496ff10f70f749436724a4d48d6d460dbb0129f66684a7b2708
7
+ data.tar.gz: 91cc0a4c85706f4169f3db2e17f04861a27d549b0b281328967101539bc728440744cd6c6efc118a620dab77fadffa81887bc9c9323935dc7a6f08d32b80b02b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sendly (3.8.1)
4
+ sendly (3.9.0)
5
5
  faraday (~> 2.0)
6
6
  faraday-retry (~> 2.0)
7
7
 
data/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/SendlyHQ/sendly-ruby/main/.github/header.svg" alt="Sendly Ruby SDK" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://rubygems.org/gems/sendly"><img src="https://img.shields.io/gem/v/sendly.svg?style=flat-square" alt="RubyGems" /></a>
7
+ <a href="https://github.com/SendlyHQ/sendly-ruby/blob/main/LICENSE"><img src="https://img.shields.io/github/license/SendlyHQ/sendly-ruby?style=flat-square" alt="license" /></a>
8
+ </p>
9
+
1
10
  # Sendly Ruby SDK
2
11
 
3
12
  Official Ruby SDK for the Sendly SMS API.
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,132 @@
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/send", body)
108
+ SendVerificationResponse.new(response)
109
+ end
110
+
111
+ def check(id, code:)
112
+ response = @client.post("/verify/#{id}/check", { code: code })
113
+ CheckVerificationResponse.new(response)
114
+ end
115
+
116
+ def get(id)
117
+ response = @client.get("/verify/#{id}")
118
+ Verification.new(response)
119
+ end
120
+
121
+ def list(limit: nil, status: nil, phone: nil)
122
+ params = {}
123
+ params[:limit] = limit if limit
124
+ params[:status] = status if status
125
+ params[:phone] = phone if phone
126
+
127
+ response = @client.get("/verify", params)
128
+ verifications = (response["verifications"] || []).map { |v| Verification.new(v) }
129
+ { verifications: verifications, pagination: response["pagination"] }
130
+ end
131
+ end
132
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sendly
4
- VERSION = "3.8.1"
4
+ VERSION = "3.9.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.1
4
+ version: 3.9.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,17 +127,19 @@ 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
134
- homepage: https://github.com/sendly-live/sendly-ruby
136
+ homepage: https://github.com/SendlyHQ/sendly-ruby
135
137
  licenses:
136
138
  - MIT
137
139
  metadata:
138
- homepage_uri: https://github.com/sendly-live/sendly-ruby
139
- source_code_uri: https://github.com/sendly-live/sendly-ruby
140
- changelog_uri: https://github.com/sendly-live/sendly-ruby/blob/main/CHANGELOG.md
140
+ homepage_uri: https://github.com/SendlyHQ/sendly-ruby
141
+ source_code_uri: https://github.com/SendlyHQ/sendly-ruby
142
+ changelog_uri: https://github.com/SendlyHQ/sendly-ruby/blob/main/CHANGELOG.md
141
143
  documentation_uri: https://sendly.live/docs
142
144
  post_install_message:
143
145
  rdoc_options: []