sentdm 0.30.0 → 0.31.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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +29 -1
- data/lib/sentdm/internal/contacts_page.rb +115 -0
- data/lib/sentdm/internal/conversations_page.rb +115 -0
- data/lib/sentdm/internal/templates_page.rb +115 -0
- data/lib/sentdm/internal/webhook_events_page.rb +115 -0
- data/lib/sentdm/internal/webhooks_page.rb +115 -0
- data/lib/sentdm/models/api_response_of_conversation_messages_list.rb +0 -1
- data/lib/sentdm/models/contact_list_params.rb +13 -13
- data/lib/sentdm/models/contact_response.rb +1 -0
- data/lib/sentdm/models/conversation_list_messages_params.rb +5 -5
- data/lib/sentdm/models/conversation_list_params.rb +5 -5
- data/lib/sentdm/models/template.rb +1 -0
- data/lib/sentdm/models/template_list_params.rb +17 -17
- data/lib/sentdm/models/webhook_list_events_params.rb +5 -5
- data/lib/sentdm/models/webhook_list_events_response.rb +108 -168
- data/lib/sentdm/models/webhook_list_params.rb +11 -11
- data/lib/sentdm/models/webhook_response.rb +1 -0
- data/lib/sentdm/resources/contacts.rb +8 -7
- data/lib/sentdm/resources/conversations.rb +10 -8
- data/lib/sentdm/resources/templates.rb +10 -9
- data/lib/sentdm/resources/webhooks.rb +12 -10
- data/lib/sentdm/version.rb +1 -1
- data/lib/sentdm.rb +5 -3
- data/rbi/sentdm/internal/contacts_page.rbi +71 -0
- data/rbi/sentdm/internal/conversations_page.rbi +71 -0
- data/rbi/sentdm/internal/templates_page.rbi +71 -0
- data/rbi/sentdm/internal/webhook_events_page.rbi +71 -0
- data/rbi/sentdm/internal/webhooks_page.rbi +71 -0
- data/rbi/sentdm/models/contact_list_params.rbi +19 -13
- data/rbi/sentdm/models/conversation_list_messages_params.rbi +12 -6
- data/rbi/sentdm/models/conversation_list_params.rbi +16 -5
- data/rbi/sentdm/models/template_list_params.rbi +22 -16
- data/rbi/sentdm/models/webhook_list_events_params.rbi +12 -6
- data/rbi/sentdm/models/webhook_list_events_response.rbi +114 -263
- data/rbi/sentdm/models/webhook_list_params.rbi +16 -10
- data/rbi/sentdm/resources/contacts.rbi +6 -6
- data/rbi/sentdm/resources/conversations.rbi +14 -6
- data/rbi/sentdm/resources/templates.rbi +7 -7
- data/rbi/sentdm/resources/webhooks.rbi +12 -8
- data/sig/sentdm/internal/contacts_page.rbs +41 -0
- data/sig/sentdm/internal/conversations_page.rbs +41 -0
- data/sig/sentdm/internal/templates_page.rbs +44 -0
- data/sig/sentdm/internal/webhook_events_page.rbs +41 -0
- data/sig/sentdm/internal/webhooks_page.rbs +41 -0
- data/sig/sentdm/models/contact_list_params.rbs +11 -7
- data/sig/sentdm/models/conversation_list_messages_params.rbs +8 -4
- data/sig/sentdm/models/conversation_list_params.rbs +8 -4
- data/sig/sentdm/models/template_list_params.rbs +14 -10
- data/sig/sentdm/models/webhook_list_events_params.rbs +8 -4
- data/sig/sentdm/models/webhook_list_events_response.rbs +63 -127
- data/sig/sentdm/models/webhook_list_params.rbs +11 -7
- data/sig/sentdm/resources/contacts.rbs +3 -3
- data/sig/sentdm/resources/conversations.rbs +6 -6
- data/sig/sentdm/resources/templates.rbs +3 -3
- data/sig/sentdm/resources/webhooks.rbs +6 -6
- metadata +16 -10
- data/lib/sentdm/models/contact_list_response.rb +0 -65
- data/lib/sentdm/models/template_list_response.rb +0 -65
- data/lib/sentdm/models/webhook_list_response.rb +0 -65
- data/rbi/sentdm/models/contact_list_response.rbi +0 -128
- data/rbi/sentdm/models/template_list_response.rbi +0 -128
- data/rbi/sentdm/models/webhook_list_response.rbi +0 -128
- data/sig/sentdm/models/contact_list_response.rbs +0 -67
- data/sig/sentdm/models/template_list_response.rbs +0 -65
- data/sig/sentdm/models/webhook_list_response.rbs +0 -67
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc53282fa9d44937f4eca7cd2519066c9230dd80c07e757976aaf19ed84bc4cd
|
|
4
|
+
data.tar.gz: ae37ec96f9bbd5415b93931e5f5b45f86bf2cfd9aa5496c3e48a4e4cf55c601c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad4d72570b0f014b5c0ae8ed154c6eda9cbf18fe6b765bd2159ac2468474c85dfba17e0d662f38c987ea0330eceb7e77d33137ebbb7df2591c65bae1f5415342
|
|
7
|
+
data.tar.gz: 6c941c5ce504b94a154865c6d1fa3ddcfcf90f58889e0514c0f74c89c324eb0c3312b55cd8ad4f5a32274b8ac28e8d65805496be73ad757621fd1a5a19e30c2e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.31.0](https://github.com/sentdm/sent-dm-ruby/compare/v0.30.0...v0.31.0) (2026-09-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Highlights
|
|
7
|
+
|
|
8
|
+
The contacts, templates, webhooks, webhook events, conversations, and conversation messages list methods now return a page you can iterate instead of a single response body. Iterate the result and the SDK fetches each page as it goes. This changes those methods' return type, so code that read the response body directly needs to iterate the page, or read its items, instead.
|
|
9
|
+
|
|
10
|
+
`page` and `page_size` are now optional on those calls. You don't have to pass them to list anything.
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **api:** configure page_number pagination for the v3 list endpoints ([d23828b](https://github.com/sentdm/sent-dm-ruby/commit/d23828b500a4b683f9036f63d40e79c466699b2f))
|
|
15
|
+
|
|
3
16
|
## [0.30.0](https://github.com/sentdm/sent-dm-ruby/compare/v0.29.0...v0.30.0) (2026-09-09)
|
|
4
17
|
|
|
5
18
|
|
data/README.md
CHANGED
|
@@ -17,7 +17,7 @@ To use this gem, install via Bundler by adding the following to your application
|
|
|
17
17
|
<!-- x-release-please-start-version -->
|
|
18
18
|
|
|
19
19
|
```ruby
|
|
20
|
-
gem "sentdm", "~> 0.
|
|
20
|
+
gem "sentdm", "~> 0.31.0"
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
<!-- x-release-please-end -->
|
|
@@ -45,6 +45,34 @@ response = sent.messages.send_(
|
|
|
45
45
|
puts(response.data)
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
### Pagination
|
|
49
|
+
|
|
50
|
+
List methods in the Sent API are paginated.
|
|
51
|
+
|
|
52
|
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
page = sent.webhooks.list
|
|
56
|
+
|
|
57
|
+
# Fetch single item from page.
|
|
58
|
+
webhook = page.data&.webhooks[0]
|
|
59
|
+
puts(webhook.id)
|
|
60
|
+
|
|
61
|
+
# Automatically fetches more pages as needed.
|
|
62
|
+
page.auto_paging_each do |webhook|
|
|
63
|
+
puts(webhook.id)
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Alternatively, you can use the `#next_page?` and `#next_page` methods for more granular control working with pages.
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
if page.next_page?
|
|
71
|
+
new_page = page.next_page
|
|
72
|
+
puts(new_page.data&.webhooks[0].id)
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
48
76
|
### Handling errors
|
|
49
77
|
|
|
50
78
|
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Sentdm::Errors::APIError` will be thrown:
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sentdm
|
|
4
|
+
module Internal
|
|
5
|
+
# @generic Elem
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# if contacts_page.has_next?
|
|
9
|
+
# contacts_page = contacts_page.next_page
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# contacts_page.auto_paging_each do |contact|
|
|
14
|
+
# puts(contact)
|
|
15
|
+
# end
|
|
16
|
+
class ContactsPage
|
|
17
|
+
include Sentdm::Internal::Type::BasePage
|
|
18
|
+
|
|
19
|
+
# @return [Data]
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# @return [Boolean]
|
|
23
|
+
def next_page?
|
|
24
|
+
data&.pagination&.has_more
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @raise [Sentdm::HTTP::Error]
|
|
28
|
+
# @return [self]
|
|
29
|
+
def next_page
|
|
30
|
+
unless next_page?
|
|
31
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
|
32
|
+
raise RuntimeError.new(message)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
req = Sentdm::Internal::Util.deep_merge(
|
|
36
|
+
@req,
|
|
37
|
+
{query: {page: @req.fetch(:query).fetch(:page, 1).to_i.succ}}
|
|
38
|
+
)
|
|
39
|
+
@client.request(req)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param blk [Proc]
|
|
43
|
+
#
|
|
44
|
+
# @yieldparam [generic<Elem>]
|
|
45
|
+
def auto_paging_each(&blk)
|
|
46
|
+
unless block_given?
|
|
47
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
page = self
|
|
51
|
+
loop do
|
|
52
|
+
page.data&.contacts&.each(&blk)
|
|
53
|
+
|
|
54
|
+
break unless page.next_page?
|
|
55
|
+
page = page.next_page
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @api private
|
|
60
|
+
#
|
|
61
|
+
# @param client [Sentdm::Internal::Transport::BaseClient]
|
|
62
|
+
# @param req [Hash{Symbol=>Object}]
|
|
63
|
+
# @param headers [Hash{String=>String}]
|
|
64
|
+
# @param page_data [Hash{Symbol=>Object}]
|
|
65
|
+
def initialize(client:, req:, headers:, page_data:)
|
|
66
|
+
super
|
|
67
|
+
|
|
68
|
+
case page_data
|
|
69
|
+
in {data: Hash | nil => data}
|
|
70
|
+
if (contacts = data[:contacts]).is_a?(Array)
|
|
71
|
+
data = {**data, contacts: contacts.map { Sentdm::Internal::Type::Converter.coerce(@model, _1) }}
|
|
72
|
+
end
|
|
73
|
+
@data = Sentdm::Internal::Type::Converter.coerce(Sentdm::Internal::ContactsPage::Data, data)
|
|
74
|
+
else
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @return [String]
|
|
81
|
+
def inspect
|
|
82
|
+
model = Sentdm::Internal::Type::Converter.inspect(@model, depth: 1)
|
|
83
|
+
|
|
84
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class Data < Sentdm::Internal::Type::BaseModel
|
|
88
|
+
# @!attribute contacts
|
|
89
|
+
#
|
|
90
|
+
# @return [Array<Object>, nil]
|
|
91
|
+
optional :contacts, Sentdm::Internal::Type::ArrayOf[Sentdm::Internal::Type::Unknown]
|
|
92
|
+
|
|
93
|
+
# @!attribute pagination
|
|
94
|
+
#
|
|
95
|
+
# @return [Data::Pagination, nil]
|
|
96
|
+
optional :pagination, -> { Data::Pagination }
|
|
97
|
+
|
|
98
|
+
# @!method initialize(contacts: nil, pagination: nil)
|
|
99
|
+
# @param contacts [Array<Object>]
|
|
100
|
+
# @param pagination [Data::Pagination]
|
|
101
|
+
|
|
102
|
+
# @see Data#pagination
|
|
103
|
+
class Pagination < Sentdm::Internal::Type::BaseModel
|
|
104
|
+
# @!attribute has_more
|
|
105
|
+
#
|
|
106
|
+
# @return [Boolean, nil]
|
|
107
|
+
optional :has_more, Sentdm::Internal::Type::Boolean
|
|
108
|
+
|
|
109
|
+
# @!method initialize(has_more: nil)
|
|
110
|
+
# @param has_more [Boolean]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sentdm
|
|
4
|
+
module Internal
|
|
5
|
+
# @generic Elem
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# if conversations_page.has_next?
|
|
9
|
+
# conversations_page = conversations_page.next_page
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# conversations_page.auto_paging_each do |conversation|
|
|
14
|
+
# puts(conversation)
|
|
15
|
+
# end
|
|
16
|
+
class ConversationsPage
|
|
17
|
+
include Sentdm::Internal::Type::BasePage
|
|
18
|
+
|
|
19
|
+
# @return [Data]
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# @return [Boolean]
|
|
23
|
+
def next_page?
|
|
24
|
+
data&.pagination&.has_more
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @raise [Sentdm::HTTP::Error]
|
|
28
|
+
# @return [self]
|
|
29
|
+
def next_page
|
|
30
|
+
unless next_page?
|
|
31
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
|
32
|
+
raise RuntimeError.new(message)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
req = Sentdm::Internal::Util.deep_merge(
|
|
36
|
+
@req,
|
|
37
|
+
{query: {page: @req.fetch(:query).fetch(:page, 1).to_i.succ}}
|
|
38
|
+
)
|
|
39
|
+
@client.request(req)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param blk [Proc]
|
|
43
|
+
#
|
|
44
|
+
# @yieldparam [generic<Elem>]
|
|
45
|
+
def auto_paging_each(&blk)
|
|
46
|
+
unless block_given?
|
|
47
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
page = self
|
|
51
|
+
loop do
|
|
52
|
+
page.data&.messages&.each(&blk)
|
|
53
|
+
|
|
54
|
+
break unless page.next_page?
|
|
55
|
+
page = page.next_page
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @api private
|
|
60
|
+
#
|
|
61
|
+
# @param client [Sentdm::Internal::Transport::BaseClient]
|
|
62
|
+
# @param req [Hash{Symbol=>Object}]
|
|
63
|
+
# @param headers [Hash{String=>String}]
|
|
64
|
+
# @param page_data [Hash{Symbol=>Object}]
|
|
65
|
+
def initialize(client:, req:, headers:, page_data:)
|
|
66
|
+
super
|
|
67
|
+
|
|
68
|
+
case page_data
|
|
69
|
+
in {data: Hash | nil => data}
|
|
70
|
+
if (messages = data[:messages]).is_a?(Array)
|
|
71
|
+
data = {**data, messages: messages.map { Sentdm::Internal::Type::Converter.coerce(@model, _1) }}
|
|
72
|
+
end
|
|
73
|
+
@data = Sentdm::Internal::Type::Converter.coerce(Sentdm::Internal::ConversationsPage::Data, data)
|
|
74
|
+
else
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @return [String]
|
|
81
|
+
def inspect
|
|
82
|
+
model = Sentdm::Internal::Type::Converter.inspect(@model, depth: 1)
|
|
83
|
+
|
|
84
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class Data < Sentdm::Internal::Type::BaseModel
|
|
88
|
+
# @!attribute messages
|
|
89
|
+
#
|
|
90
|
+
# @return [Array<Object>, nil]
|
|
91
|
+
optional :messages, Sentdm::Internal::Type::ArrayOf[Sentdm::Internal::Type::Unknown]
|
|
92
|
+
|
|
93
|
+
# @!attribute pagination
|
|
94
|
+
#
|
|
95
|
+
# @return [Data::Pagination, nil]
|
|
96
|
+
optional :pagination, -> { Data::Pagination }
|
|
97
|
+
|
|
98
|
+
# @!method initialize(messages: nil, pagination: nil)
|
|
99
|
+
# @param messages [Array<Object>]
|
|
100
|
+
# @param pagination [Data::Pagination]
|
|
101
|
+
|
|
102
|
+
# @see Data#pagination
|
|
103
|
+
class Pagination < Sentdm::Internal::Type::BaseModel
|
|
104
|
+
# @!attribute has_more
|
|
105
|
+
#
|
|
106
|
+
# @return [Boolean, nil]
|
|
107
|
+
optional :has_more, Sentdm::Internal::Type::Boolean
|
|
108
|
+
|
|
109
|
+
# @!method initialize(has_more: nil)
|
|
110
|
+
# @param has_more [Boolean]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sentdm
|
|
4
|
+
module Internal
|
|
5
|
+
# @generic Elem
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# if templates_page.has_next?
|
|
9
|
+
# templates_page = templates_page.next_page
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# templates_page.auto_paging_each do |template|
|
|
14
|
+
# puts(template)
|
|
15
|
+
# end
|
|
16
|
+
class TemplatesPage
|
|
17
|
+
include Sentdm::Internal::Type::BasePage
|
|
18
|
+
|
|
19
|
+
# @return [Data]
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# @return [Boolean]
|
|
23
|
+
def next_page?
|
|
24
|
+
data&.pagination&.has_more
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @raise [Sentdm::HTTP::Error]
|
|
28
|
+
# @return [self]
|
|
29
|
+
def next_page
|
|
30
|
+
unless next_page?
|
|
31
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
|
32
|
+
raise RuntimeError.new(message)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
req = Sentdm::Internal::Util.deep_merge(
|
|
36
|
+
@req,
|
|
37
|
+
{query: {page: @req.fetch(:query).fetch(:page, 1).to_i.succ}}
|
|
38
|
+
)
|
|
39
|
+
@client.request(req)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param blk [Proc]
|
|
43
|
+
#
|
|
44
|
+
# @yieldparam [generic<Elem>]
|
|
45
|
+
def auto_paging_each(&blk)
|
|
46
|
+
unless block_given?
|
|
47
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
page = self
|
|
51
|
+
loop do
|
|
52
|
+
page.data&.templates&.each(&blk)
|
|
53
|
+
|
|
54
|
+
break unless page.next_page?
|
|
55
|
+
page = page.next_page
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @api private
|
|
60
|
+
#
|
|
61
|
+
# @param client [Sentdm::Internal::Transport::BaseClient]
|
|
62
|
+
# @param req [Hash{Symbol=>Object}]
|
|
63
|
+
# @param headers [Hash{String=>String}]
|
|
64
|
+
# @param page_data [Hash{Symbol=>Object}]
|
|
65
|
+
def initialize(client:, req:, headers:, page_data:)
|
|
66
|
+
super
|
|
67
|
+
|
|
68
|
+
case page_data
|
|
69
|
+
in {data: Hash | nil => data}
|
|
70
|
+
if (templates = data[:templates]).is_a?(Array)
|
|
71
|
+
data = {**data, templates: templates.map { Sentdm::Internal::Type::Converter.coerce(@model, _1) }}
|
|
72
|
+
end
|
|
73
|
+
@data = Sentdm::Internal::Type::Converter.coerce(Sentdm::Internal::TemplatesPage::Data, data)
|
|
74
|
+
else
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @return [String]
|
|
81
|
+
def inspect
|
|
82
|
+
model = Sentdm::Internal::Type::Converter.inspect(@model, depth: 1)
|
|
83
|
+
|
|
84
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class Data < Sentdm::Internal::Type::BaseModel
|
|
88
|
+
# @!attribute pagination
|
|
89
|
+
#
|
|
90
|
+
# @return [Data::Pagination, nil]
|
|
91
|
+
optional :pagination, -> { Data::Pagination }
|
|
92
|
+
|
|
93
|
+
# @!attribute templates
|
|
94
|
+
#
|
|
95
|
+
# @return [Array<Object>, nil]
|
|
96
|
+
optional :templates, Sentdm::Internal::Type::ArrayOf[Sentdm::Internal::Type::Unknown]
|
|
97
|
+
|
|
98
|
+
# @!method initialize(pagination: nil, templates: nil)
|
|
99
|
+
# @param pagination [Data::Pagination]
|
|
100
|
+
# @param templates [Array<Object>]
|
|
101
|
+
|
|
102
|
+
# @see Data#pagination
|
|
103
|
+
class Pagination < Sentdm::Internal::Type::BaseModel
|
|
104
|
+
# @!attribute has_more
|
|
105
|
+
#
|
|
106
|
+
# @return [Boolean, nil]
|
|
107
|
+
optional :has_more, Sentdm::Internal::Type::Boolean
|
|
108
|
+
|
|
109
|
+
# @!method initialize(has_more: nil)
|
|
110
|
+
# @param has_more [Boolean]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sentdm
|
|
4
|
+
module Internal
|
|
5
|
+
# @generic Elem
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# if webhook_events_page.has_next?
|
|
9
|
+
# webhook_events_page = webhook_events_page.next_page
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# webhook_events_page.auto_paging_each do |webhook|
|
|
14
|
+
# puts(webhook)
|
|
15
|
+
# end
|
|
16
|
+
class WebhookEventsPage
|
|
17
|
+
include Sentdm::Internal::Type::BasePage
|
|
18
|
+
|
|
19
|
+
# @return [Data]
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# @return [Boolean]
|
|
23
|
+
def next_page?
|
|
24
|
+
data&.pagination&.has_more
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @raise [Sentdm::HTTP::Error]
|
|
28
|
+
# @return [self]
|
|
29
|
+
def next_page
|
|
30
|
+
unless next_page?
|
|
31
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
|
32
|
+
raise RuntimeError.new(message)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
req = Sentdm::Internal::Util.deep_merge(
|
|
36
|
+
@req,
|
|
37
|
+
{query: {page: @req.fetch(:query).fetch(:page, 1).to_i.succ}}
|
|
38
|
+
)
|
|
39
|
+
@client.request(req)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param blk [Proc]
|
|
43
|
+
#
|
|
44
|
+
# @yieldparam [generic<Elem>]
|
|
45
|
+
def auto_paging_each(&blk)
|
|
46
|
+
unless block_given?
|
|
47
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
page = self
|
|
51
|
+
loop do
|
|
52
|
+
page.data&.events&.each(&blk)
|
|
53
|
+
|
|
54
|
+
break unless page.next_page?
|
|
55
|
+
page = page.next_page
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @api private
|
|
60
|
+
#
|
|
61
|
+
# @param client [Sentdm::Internal::Transport::BaseClient]
|
|
62
|
+
# @param req [Hash{Symbol=>Object}]
|
|
63
|
+
# @param headers [Hash{String=>String}]
|
|
64
|
+
# @param page_data [Hash{Symbol=>Object}]
|
|
65
|
+
def initialize(client:, req:, headers:, page_data:)
|
|
66
|
+
super
|
|
67
|
+
|
|
68
|
+
case page_data
|
|
69
|
+
in {data: Hash | nil => data}
|
|
70
|
+
if (events = data[:events]).is_a?(Array)
|
|
71
|
+
data = {**data, events: events.map { Sentdm::Internal::Type::Converter.coerce(@model, _1) }}
|
|
72
|
+
end
|
|
73
|
+
@data = Sentdm::Internal::Type::Converter.coerce(Sentdm::Internal::WebhookEventsPage::Data, data)
|
|
74
|
+
else
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @return [String]
|
|
81
|
+
def inspect
|
|
82
|
+
model = Sentdm::Internal::Type::Converter.inspect(@model, depth: 1)
|
|
83
|
+
|
|
84
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class Data < Sentdm::Internal::Type::BaseModel
|
|
88
|
+
# @!attribute events
|
|
89
|
+
#
|
|
90
|
+
# @return [Array<Object>, nil]
|
|
91
|
+
optional :events, Sentdm::Internal::Type::ArrayOf[Sentdm::Internal::Type::Unknown]
|
|
92
|
+
|
|
93
|
+
# @!attribute pagination
|
|
94
|
+
#
|
|
95
|
+
# @return [Data::Pagination, nil]
|
|
96
|
+
optional :pagination, -> { Data::Pagination }
|
|
97
|
+
|
|
98
|
+
# @!method initialize(events: nil, pagination: nil)
|
|
99
|
+
# @param events [Array<Object>]
|
|
100
|
+
# @param pagination [Data::Pagination]
|
|
101
|
+
|
|
102
|
+
# @see Data#pagination
|
|
103
|
+
class Pagination < Sentdm::Internal::Type::BaseModel
|
|
104
|
+
# @!attribute has_more
|
|
105
|
+
#
|
|
106
|
+
# @return [Boolean, nil]
|
|
107
|
+
optional :has_more, Sentdm::Internal::Type::Boolean
|
|
108
|
+
|
|
109
|
+
# @!method initialize(has_more: nil)
|
|
110
|
+
# @param has_more [Boolean]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sentdm
|
|
4
|
+
module Internal
|
|
5
|
+
# @generic Elem
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# if webhooks_page.has_next?
|
|
9
|
+
# webhooks_page = webhooks_page.next_page
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# webhooks_page.auto_paging_each do |webhook|
|
|
14
|
+
# puts(webhook)
|
|
15
|
+
# end
|
|
16
|
+
class WebhooksPage
|
|
17
|
+
include Sentdm::Internal::Type::BasePage
|
|
18
|
+
|
|
19
|
+
# @return [Data]
|
|
20
|
+
attr_accessor :data
|
|
21
|
+
|
|
22
|
+
# @return [Boolean]
|
|
23
|
+
def next_page?
|
|
24
|
+
data&.pagination&.has_more
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @raise [Sentdm::HTTP::Error]
|
|
28
|
+
# @return [self]
|
|
29
|
+
def next_page
|
|
30
|
+
unless next_page?
|
|
31
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
|
32
|
+
raise RuntimeError.new(message)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
req = Sentdm::Internal::Util.deep_merge(
|
|
36
|
+
@req,
|
|
37
|
+
{query: {page: @req.fetch(:query).fetch(:page, 1).to_i.succ}}
|
|
38
|
+
)
|
|
39
|
+
@client.request(req)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param blk [Proc]
|
|
43
|
+
#
|
|
44
|
+
# @yieldparam [generic<Elem>]
|
|
45
|
+
def auto_paging_each(&blk)
|
|
46
|
+
unless block_given?
|
|
47
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
page = self
|
|
51
|
+
loop do
|
|
52
|
+
page.data&.webhooks&.each(&blk)
|
|
53
|
+
|
|
54
|
+
break unless page.next_page?
|
|
55
|
+
page = page.next_page
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @api private
|
|
60
|
+
#
|
|
61
|
+
# @param client [Sentdm::Internal::Transport::BaseClient]
|
|
62
|
+
# @param req [Hash{Symbol=>Object}]
|
|
63
|
+
# @param headers [Hash{String=>String}]
|
|
64
|
+
# @param page_data [Hash{Symbol=>Object}]
|
|
65
|
+
def initialize(client:, req:, headers:, page_data:)
|
|
66
|
+
super
|
|
67
|
+
|
|
68
|
+
case page_data
|
|
69
|
+
in {data: Hash | nil => data}
|
|
70
|
+
if (webhooks = data[:webhooks]).is_a?(Array)
|
|
71
|
+
data = {**data, webhooks: webhooks.map { Sentdm::Internal::Type::Converter.coerce(@model, _1) }}
|
|
72
|
+
end
|
|
73
|
+
@data = Sentdm::Internal::Type::Converter.coerce(Sentdm::Internal::WebhooksPage::Data, data)
|
|
74
|
+
else
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @return [String]
|
|
81
|
+
def inspect
|
|
82
|
+
model = Sentdm::Internal::Type::Converter.inspect(@model, depth: 1)
|
|
83
|
+
|
|
84
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class Data < Sentdm::Internal::Type::BaseModel
|
|
88
|
+
# @!attribute pagination
|
|
89
|
+
#
|
|
90
|
+
# @return [Data::Pagination, nil]
|
|
91
|
+
optional :pagination, -> { Data::Pagination }
|
|
92
|
+
|
|
93
|
+
# @!attribute webhooks
|
|
94
|
+
#
|
|
95
|
+
# @return [Array<Object>, nil]
|
|
96
|
+
optional :webhooks, Sentdm::Internal::Type::ArrayOf[Sentdm::Internal::Type::Unknown]
|
|
97
|
+
|
|
98
|
+
# @!method initialize(pagination: nil, webhooks: nil)
|
|
99
|
+
# @param pagination [Data::Pagination]
|
|
100
|
+
# @param webhooks [Array<Object>]
|
|
101
|
+
|
|
102
|
+
# @see Data#pagination
|
|
103
|
+
class Pagination < Sentdm::Internal::Type::BaseModel
|
|
104
|
+
# @!attribute has_more
|
|
105
|
+
#
|
|
106
|
+
# @return [Boolean, nil]
|
|
107
|
+
optional :has_more, Sentdm::Internal::Type::Boolean
|
|
108
|
+
|
|
109
|
+
# @!method initialize(has_more: nil)
|
|
110
|
+
# @param has_more [Boolean]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|