nextmail 0.0.1 → 0.1.1
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/README.md +27 -1
- data/lib/nextmail/api_paths.rb +29 -0
- data/lib/nextmail/client.rb +6 -0
- data/lib/nextmail/constants.rb +238 -4
- data/lib/nextmail/defaults.rb +10 -0
- data/lib/nextmail/event_stream.rb +120 -0
- data/lib/nextmail/http.rb +64 -0
- data/lib/nextmail/live_event_stream.rb +169 -0
- data/lib/nextmail/protocol.rb +46 -3
- data/lib/nextmail/resources/calendar.rb +106 -12
- data/lib/nextmail/resources/contacts.rb +24 -9
- data/lib/nextmail/resources/emails.rb +5 -0
- data/lib/nextmail/resources/live_events.rb +21 -0
- data/lib/nextmail/resources/notifications.rb +37 -0
- data/lib/nextmail/resources/share_links.rb +32 -0
- data/lib/nextmail/resources/shared.rb +15 -0
- data/lib/nextmail/resources/signups.rb +15 -0
- data/lib/nextmail/resources/tasks.rb +6 -6
- data/lib/nextmail/resources/templates.rb +4 -4
- data/lib/nextmail/resources/threads.rb +16 -0
- data/lib/nextmail/resources/tools.rb +12 -0
- data/lib/nextmail/resources/traffic.rb +36 -0
- data/lib/nextmail/results.rb +6 -0
- data/lib/nextmail/transport.rb +118 -3
- data/lib/nextmail/version.rb +1 -1
- data/lib/nextmail/wire.rb +14 -0
- data/lib/nextmail.rb +10 -0
- metadata +10 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nextmail
|
|
4
|
+
module Resources
|
|
5
|
+
class LiveEvents < Resource
|
|
6
|
+
def initialize(transport, timing: Protocol::LIVE_STREAM_TIMING)
|
|
7
|
+
super(transport)
|
|
8
|
+
@timing = timing
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def stream(types: nil, address: nil, last_event_id: nil, api_key: nil, &)
|
|
12
|
+
query = query_params(types: joined(types), address:)
|
|
13
|
+
events = Enumerator.new do |yielder|
|
|
14
|
+
LiveEventStream.new(@transport, query:, last_event_id:, api_key:, timing: @timing).run(yielder)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
each_or_enumerator(events, &)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nextmail
|
|
4
|
+
module Resources
|
|
5
|
+
class Notifications < Resource
|
|
6
|
+
def list(limit: nil, cursor: nil, api_key: nil)
|
|
7
|
+
envelope = request(ApiPaths::NOTIFICATIONS, query: query_params(limit:, cursor:), api_key:)
|
|
8
|
+
envelope = {} unless envelope.is_a?(Hash)
|
|
9
|
+
next_cursor = Pagination.cursor_of(envelope[:nextCursor])
|
|
10
|
+
|
|
11
|
+
NotificationPage.new(
|
|
12
|
+
items: Pagination.items_of(envelope),
|
|
13
|
+
unread_count: envelope[:unreadCount] || 0,
|
|
14
|
+
has_more: Pagination.more?(envelope, next_cursor),
|
|
15
|
+
next_cursor:
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def unread_count(api_key: nil)
|
|
20
|
+
request(ApiPaths::NOTIFICATIONS_UNREAD_COUNT, api_key:)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def mark_read(ids, api_key: nil)
|
|
24
|
+
request(ApiPaths::NOTIFICATIONS_READ, method: :post, body: {"ids" => ids}, repeatable: true, api_key:)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def mark_all_read(api_key: nil)
|
|
28
|
+
request(ApiPaths::NOTIFICATIONS_READ_ALL, method: :post, repeatable: true, api_key:)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def clear(decline_invitations: nil, api_key: nil)
|
|
32
|
+
request(ApiPaths::NOTIFICATIONS_CLEAR, method: :post,
|
|
33
|
+
body: decline_invitations.nil? ? {} : {"declineInvitations" => decline_invitations}, repeatable: true, api_key:)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nextmail
|
|
4
|
+
module Resources
|
|
5
|
+
class ShareLinks < Resource
|
|
6
|
+
def list(kind: nil, limit: nil, cursor: nil, api_key: nil)
|
|
7
|
+
fetch_page(ApiPaths::SHARE_LINKS, query_params(kind:), limit:, cursor:, api_key:)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list_all(kind: nil, limit: nil, cursor: nil, api_key: nil)
|
|
11
|
+
collect_all(ApiPaths::SHARE_LINKS, query_params(kind:), limit:, cursor:, api_key:)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def iterate(kind: nil, limit: nil, cursor: nil, api_key: nil, &)
|
|
15
|
+
iterate_pages(ApiPaths::SHARE_LINKS, query_params(kind:), limit:, cursor:, api_key:, &)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get(kind, item_id, api_key: nil)
|
|
19
|
+
request(fill(ApiPaths::SHARE_LINK, kind:, itemId: item_id), api_key:)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def set(kind, item_id, body = nil, api_key: nil, **fields)
|
|
23
|
+
request(fill(ApiPaths::SHARE_LINK, kind:, itemId: item_id), method: :put, body: payload(body, fields),
|
|
24
|
+
repeatable: true, api_key:)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def delete(kind, item_id, api_key: nil)
|
|
28
|
+
request(fill(ApiPaths::SHARE_LINK, kind:, itemId: item_id), method: :delete, api_key:)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nextmail
|
|
4
|
+
module Resources
|
|
5
|
+
class Shared < Resource
|
|
6
|
+
def get(token, api_key: nil)
|
|
7
|
+
request(fill(ApiPaths::SHARED_ITEM, token:), api_key:)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def copy(token, api_key: nil)
|
|
11
|
+
request(fill(ApiPaths::SHARED_ITEM_COPY, token:), method: :post, api_key:)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nextmail
|
|
4
|
+
module Resources
|
|
5
|
+
class Signups < Resource
|
|
6
|
+
def create(body = nil, api_key: nil, **fields)
|
|
7
|
+
request(ApiPaths::SIGNUPS, method: :post, body: payload(body, fields), anonymous: true)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def verify(sign_up_id, code, api_key: nil)
|
|
11
|
+
request(fill(ApiPaths::SIGNUP_VERIFY, id: sign_up_id), method: :post, body: {code:}, anonymous: true)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
module Nextmail
|
|
4
4
|
module Resources
|
|
5
5
|
class Tasks < Resource
|
|
6
|
-
def list(status: nil, limit: nil, cursor: nil, api_key: nil)
|
|
7
|
-
fetch_page(ApiPaths::TASKS, query_params(status:), limit:, cursor:, api_key:)
|
|
6
|
+
def list(status: nil, chat_id: nil, limit: nil, cursor: nil, api_key: nil)
|
|
7
|
+
fetch_page(ApiPaths::TASKS, query_params(status:, chat_id:), limit:, cursor:, api_key:)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def list_all(status: nil, limit: nil, cursor: nil, api_key: nil)
|
|
11
|
-
collect_all(ApiPaths::TASKS, query_params(status:), limit:, cursor:, api_key:)
|
|
10
|
+
def list_all(status: nil, chat_id: nil, limit: nil, cursor: nil, api_key: nil)
|
|
11
|
+
collect_all(ApiPaths::TASKS, query_params(status:, chat_id:), limit:, cursor:, api_key:)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def iterate(status: nil, limit: nil, cursor: nil, api_key: nil, &)
|
|
15
|
-
iterate_pages(ApiPaths::TASKS, query_params(status:), limit:, cursor:, api_key:, &)
|
|
14
|
+
def iterate(status: nil, chat_id: nil, limit: nil, cursor: nil, api_key: nil, &)
|
|
15
|
+
iterate_pages(ApiPaths::TASKS, query_params(status:, chat_id:), limit:, cursor:, api_key:, &)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def get(id, api_key: nil)
|
|
@@ -15,16 +15,16 @@ module Nextmail
|
|
|
15
15
|
iterate_pages(ApiPaths::TEMPLATES, query_params(status:, search:, sort:), limit:, cursor:, api_key:, &)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def list_starters(api_key: nil)
|
|
19
|
-
fetch_list(ApiPaths::TEMPLATE_STARTERS, api_key:)
|
|
18
|
+
def list_starters(category: nil, api_key: nil)
|
|
19
|
+
fetch_list(ApiPaths::TEMPLATE_STARTERS, query_params(category:), api_key:)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def list_fonts(api_key: nil)
|
|
23
23
|
fetch_list(ApiPaths::TEMPLATE_FONTS, api_key:)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def get_starter(slug, api_key: nil)
|
|
27
|
-
request(fill(ApiPaths::TEMPLATE_STARTER, slug:), api_key:)
|
|
26
|
+
def get_starter(slug, style: nil, api_key: nil)
|
|
27
|
+
request(fill(ApiPaths::TEMPLATE_STARTER, slug:), query: query_params(style:), api_key:)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def render(body = nil, api_key: nil, **fields)
|
|
@@ -92,6 +92,10 @@ module Nextmail
|
|
|
92
92
|
request(fill(ApiPaths::THREAD_DELIVERY, id:), query: query_params(address:), api_key:)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
+
def list_automations(id, api_key: nil)
|
|
96
|
+
fetch_list(fill(ApiPaths::THREAD_AUTOMATIONS, id:), api_key:)
|
|
97
|
+
end
|
|
98
|
+
|
|
95
99
|
def get_event(id, api_key: nil)
|
|
96
100
|
request(fill(ApiPaths::THREAD_EVENT, id:), api_key:)
|
|
97
101
|
end
|
|
@@ -123,6 +127,11 @@ module Nextmail
|
|
|
123
127
|
request(ApiPaths::THREADS_COUNTS, query: query_params(address:, hide_labelled: flag(hide_labelled)), api_key:)
|
|
124
128
|
end
|
|
125
129
|
|
|
130
|
+
def wait_for_email(address: nil, from: nil, subject: nil, since: nil, timeout: nil, api_key: nil)
|
|
131
|
+
request(ApiPaths::THREADS_WAIT, query: query_params(address:, from:, subject:, since: instant(since), timeout:),
|
|
132
|
+
timeout: wait_deadline(timeout), api_key:)
|
|
133
|
+
end
|
|
134
|
+
|
|
126
135
|
def summary(id, api_key: nil)
|
|
127
136
|
request(fill(ApiPaths::THREAD_SUMMARY, id:), api_key:)
|
|
128
137
|
end
|
|
@@ -213,6 +222,13 @@ module Nextmail
|
|
|
213
222
|
def file_link_query(include_revoked)
|
|
214
223
|
query_params(include_revoked: flag(include_revoked))
|
|
215
224
|
end
|
|
225
|
+
|
|
226
|
+
def wait_deadline(timeout)
|
|
227
|
+
wait = timeout.nil? ? Protocol::THREAD_WAIT[:DEFAULT_TIMEOUT_SECONDS] : timeout
|
|
228
|
+
raise ArgumentError, Defaults::MESSAGES[:WAIT_TIMEOUT_SHAPE] unless wait.is_a?(Numeric)
|
|
229
|
+
|
|
230
|
+
wait + Protocol::THREAD_WAIT[:DEADLINE_MARGIN_SECONDS]
|
|
231
|
+
end
|
|
216
232
|
end
|
|
217
233
|
end
|
|
218
234
|
end
|
|
@@ -15,6 +15,18 @@ module Nextmail
|
|
|
15
15
|
request(ApiPaths::TOOLS_DELIVERABILITY, query: query_params(domain:), api_key:)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def check_spf(domain, api_key: nil)
|
|
19
|
+
request(ApiPaths::TOOLS_SPF, query: query_params(domain:), api_key:)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def check_dkim(domain, selector: nil, api_key: nil)
|
|
23
|
+
request(ApiPaths::TOOLS_DKIM, query: query_params(domain:, selector:), api_key:)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def check_mx(domain, api_key: nil)
|
|
27
|
+
request(ApiPaths::TOOLS_MX, query: query_params(domain:), api_key:)
|
|
28
|
+
end
|
|
29
|
+
|
|
18
30
|
def read_verification_code(body = nil, api_key: nil, **fields)
|
|
19
31
|
request(ApiPaths::TOOLS_VERIFICATION_CODE, method: :post, body: payload(body, fields), api_key:)
|
|
20
32
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nextmail
|
|
4
|
+
module Resources
|
|
5
|
+
class Traffic < Resource
|
|
6
|
+
def list(domain_id: nil, direction: nil, outcomes: nil, address: nil, recipient: nil, since: nil, until: nil,
|
|
7
|
+
limit: nil, cursor: nil, api_key: nil)
|
|
8
|
+
query = traffic_query(domain_id, direction, outcomes, address, recipient, since,
|
|
9
|
+
binding.local_variable_get(:until))
|
|
10
|
+
fetch_page(ApiPaths::TRAFFIC, query, limit:, cursor:, api_key:)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list_all(domain_id: nil, direction: nil, outcomes: nil, address: nil, recipient: nil, since: nil,
|
|
14
|
+
until: nil, limit: nil, cursor: nil, api_key: nil)
|
|
15
|
+
query = traffic_query(domain_id, direction, outcomes, address, recipient, since,
|
|
16
|
+
binding.local_variable_get(:until))
|
|
17
|
+
collect_all(ApiPaths::TRAFFIC, query, limit:, cursor:, api_key:)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def iterate(domain_id: nil, direction: nil, outcomes: nil, address: nil, recipient: nil, since: nil,
|
|
21
|
+
until: nil, limit: nil, cursor: nil, api_key: nil, &)
|
|
22
|
+
query = traffic_query(domain_id, direction, outcomes, address, recipient, since,
|
|
23
|
+
binding.local_variable_get(:until))
|
|
24
|
+
iterate_pages(ApiPaths::TRAFFIC, query, limit:, cursor:, api_key:, &)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def traffic_query(domain_id, direction, outcomes, address, recipient, since, until_value)
|
|
30
|
+
outcome = (outcomes.nil? || outcomes.empty?) ? nil : joined(outcomes)
|
|
31
|
+
log_window_query(since, until_value)
|
|
32
|
+
.merge(query_params(domain_id:, direction:, outcome:, address:, recipient:))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/nextmail/results.rb
CHANGED
|
@@ -19,6 +19,12 @@ module Nextmail
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
NotificationPage = Data.define(:items, :unread_count, :has_more, :next_cursor) do
|
|
23
|
+
def has_more?
|
|
24
|
+
has_more
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
22
28
|
AddressBookPage = Data.define(:unrestricted, :addresses, :domains, :has_more, :next_cursor) do
|
|
23
29
|
def has_more?
|
|
24
30
|
has_more
|
data/lib/nextmail/transport.rb
CHANGED
|
@@ -43,6 +43,21 @@ module Nextmail
|
|
|
43
43
|
deliver(outbound, repeatable.nil? ? Protocol::RETRY[:METHODS].include?(verb) : repeatable, accept, binary)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
def stream(path, query: nil, headers: nil, accept: nil, api_key: nil, timeout: nil, idle_timeout: nil, &)
|
|
47
|
+
raise ArgumentError, Defaults::MESSAGES[:STREAM_BLOCK_REQUIRED] unless block_given?
|
|
48
|
+
|
|
49
|
+
outbound = HttpRequest.new(
|
|
50
|
+
method: Protocol::HTTP_METHODS[:GET],
|
|
51
|
+
url: Endpoint.build_url(@base_url, path, query),
|
|
52
|
+
headers: headers_for(body: nil, raw: nil, content_type: nil, api_key:, inbox_token: nil, anonymous: false,
|
|
53
|
+
idempotent: false, idempotency_key: nil, accept:, extra: headers),
|
|
54
|
+
body: nil,
|
|
55
|
+
timeout: seconds(timeout.nil? ? @timeout : timeout_option(timeout))
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
open_stream(outbound, idle_timeout.nil? ? nil : seconds(timeout_option(idle_timeout)), &)
|
|
59
|
+
end
|
|
60
|
+
|
|
46
61
|
def inspect
|
|
47
62
|
"#<#{self.class.name} base_url=#{@base_url.inspect}>"
|
|
48
63
|
end
|
|
@@ -81,20 +96,116 @@ module Nextmail
|
|
|
81
96
|
response = @adapter.call(outbound)
|
|
82
97
|
HttpResponse.new(status: Integer(response.status), headers: header_table(response.headers), body: response.body.to_s)
|
|
83
98
|
rescue Timeout::Error => error
|
|
84
|
-
|
|
99
|
+
timed_out(outbound.timeout, error)
|
|
85
100
|
rescue *PROGRAMMING_ERRORS
|
|
86
101
|
raise
|
|
87
102
|
rescue => error
|
|
103
|
+
unreachable(error)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def timed_out(seconds, error)
|
|
107
|
+
NetworkError.new(format(Defaults::MESSAGES[:TIMED_OUT], seconds:), original: error, timeout: true)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def unreachable(error)
|
|
88
111
|
NetworkError.new(format(Defaults::MESSAGES[:UNREACHABLE], base_url: @base_url, reason: error.message),
|
|
89
112
|
original: error)
|
|
90
113
|
end
|
|
91
114
|
|
|
115
|
+
def open_stream(outbound, idle)
|
|
116
|
+
refusal = nil
|
|
117
|
+
result = nil
|
|
118
|
+
inside = false
|
|
119
|
+
|
|
120
|
+
begin
|
|
121
|
+
receive_stream(outbound, idle) do |response|
|
|
122
|
+
if response.ok?
|
|
123
|
+
inside = true
|
|
124
|
+
result = yield response.with(body: guarded_chunks(response.body, idle))
|
|
125
|
+
inside = false
|
|
126
|
+
else
|
|
127
|
+
refusal = refused(response)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
rescue Timeout::Error => error
|
|
131
|
+
raise if inside
|
|
132
|
+
|
|
133
|
+
raise timed_out(outbound.timeout, error)
|
|
134
|
+
rescue *PROGRAMMING_ERRORS
|
|
135
|
+
raise
|
|
136
|
+
rescue => error
|
|
137
|
+
raise if inside
|
|
138
|
+
|
|
139
|
+
raise unreachable(error)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
raise api_error(refusal, retry_after(refusal.header(Protocol::HEADER_KEYS[:RETRY_AFTER]))) unless refusal.nil?
|
|
143
|
+
|
|
144
|
+
result
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def receive_stream(outbound, idle)
|
|
148
|
+
unless @adapter.respond_to?(:stream)
|
|
149
|
+
whole = @adapter.call(outbound)
|
|
150
|
+
return yield HttpStream.new(status: Integer(whole.status), headers: header_table(whole.headers),
|
|
151
|
+
body: [whole.body.to_s])
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
@adapter.stream(outbound, idle_timeout: idle) do |response|
|
|
155
|
+
yield HttpStream.new(status: Integer(response.status), headers: header_table(response.headers),
|
|
156
|
+
body: response.body)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def refused(response)
|
|
161
|
+
body = begin
|
|
162
|
+
response.read
|
|
163
|
+
rescue *PROGRAMMING_ERRORS
|
|
164
|
+
raise
|
|
165
|
+
rescue
|
|
166
|
+
""
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
HttpResponse.new(status: response.status, headers: response.headers, body:)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def guarded_chunks(body, idle)
|
|
173
|
+
Enumerator.new do |chunks|
|
|
174
|
+
inside = false
|
|
175
|
+
|
|
176
|
+
begin
|
|
177
|
+
body.each do |chunk|
|
|
178
|
+
inside = true
|
|
179
|
+
chunks << chunk
|
|
180
|
+
inside = false
|
|
181
|
+
end
|
|
182
|
+
rescue *PROGRAMMING_ERRORS
|
|
183
|
+
raise
|
|
184
|
+
rescue => error
|
|
185
|
+
raise if inside
|
|
186
|
+
|
|
187
|
+
raise stream_failure(error, idle)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def stream_failure(error, idle)
|
|
193
|
+
timeout = error.is_a?(Timeout::Error)
|
|
194
|
+
if timeout && !idle.nil?
|
|
195
|
+
return NetworkError.new(format(Defaults::MESSAGES[:STREAM_IDLE], seconds: idle), original: error, timeout:)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
NetworkError.new(format(Defaults::MESSAGES[:STREAM_BROKEN], base_url: @base_url, reason: error.message),
|
|
199
|
+
original: error, timeout:)
|
|
200
|
+
end
|
|
201
|
+
|
|
92
202
|
def header_table(headers)
|
|
93
203
|
(headers || {}).to_h { |name, value| [name.to_s.downcase, value.is_a?(Array) ? value.join(", ") : value.to_s] }
|
|
94
204
|
end
|
|
95
205
|
|
|
96
|
-
def headers_for(body:, raw:, content_type:, api_key:, inbox_token:, anonymous:, idempotent:, idempotency_key:, accept
|
|
97
|
-
|
|
206
|
+
def headers_for(body:, raw:, content_type:, api_key:, inbox_token:, anonymous:, idempotent:, idempotency_key:, accept:,
|
|
207
|
+
extra: nil)
|
|
208
|
+
headers = @headers.merge(extra_headers(extra)).merge(
|
|
98
209
|
Protocol::HEADER_KEYS[:ACCEPT] => accept || Protocol::CONTENT_TYPES[:JSON],
|
|
99
210
|
Protocol::HEADER_KEYS[:USER_AGENT] => @user_agent
|
|
100
211
|
)
|
|
@@ -141,6 +252,10 @@ module Nextmail
|
|
|
141
252
|
"#{Protocol::IDEMPOTENCY_KEY_PREFIX}#{SecureRandom.uuid}"
|
|
142
253
|
end
|
|
143
254
|
|
|
255
|
+
def extra_headers(extra)
|
|
256
|
+
(extra || {}).to_h { |name, value| [header_name(name), header_value(value)] }
|
|
257
|
+
end
|
|
258
|
+
|
|
144
259
|
def header_name(name)
|
|
145
260
|
text = name.to_s
|
|
146
261
|
raise ArgumentError, Defaults::MESSAGES[:HEADER_SHAPE] unless HEADER_NAME.match?(text)
|
data/lib/nextmail/version.rb
CHANGED
data/lib/nextmail/wire.rb
CHANGED
|
@@ -27,6 +27,20 @@ module Nextmail
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def email_raw(body)
|
|
31
|
+
recipients(body).tap do |wire|
|
|
32
|
+
wire["raw"] = raw(wire["raw"]) if wire.key?("raw")
|
|
33
|
+
wire["followUpAt"] = instant(wire["followUpAt"]) if wire.key?("followUpAt")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def raw(value)
|
|
38
|
+
return [RawBody.read(value)].pack("m0") unless value.is_a?(String) && value.encoding != Encoding::BINARY
|
|
39
|
+
return value if BASE64_TEXT.match?(value.delete(BASE64_WHITESPACE))
|
|
40
|
+
|
|
41
|
+
raise ArgumentError, Defaults::MESSAGES[:RAW_MESSAGE_SHAPE]
|
|
42
|
+
end
|
|
43
|
+
|
|
30
44
|
def with_attachments(body)
|
|
31
45
|
body.dup.tap do |wire|
|
|
32
46
|
next unless wire.key?("attachments")
|
data/lib/nextmail.rb
CHANGED
|
@@ -23,8 +23,10 @@ require_relative "nextmail/raw_body"
|
|
|
23
23
|
require_relative "nextmail/wire"
|
|
24
24
|
require_relative "nextmail/image_crop"
|
|
25
25
|
require_relative "nextmail/http"
|
|
26
|
+
require_relative "nextmail/event_stream"
|
|
26
27
|
require_relative "nextmail/update_notice"
|
|
27
28
|
require_relative "nextmail/transport"
|
|
29
|
+
require_relative "nextmail/live_event_stream"
|
|
28
30
|
require_relative "nextmail/results"
|
|
29
31
|
require_relative "nextmail/pagination"
|
|
30
32
|
require_relative "nextmail/webhook"
|
|
@@ -77,6 +79,14 @@ module Nextmail
|
|
|
77
79
|
Resources::TempMail.new(transport)
|
|
78
80
|
end
|
|
79
81
|
|
|
82
|
+
def create_signups(base_url: nil, adapter: nil, max_retries: nil, timeout: nil, user_agent: nil, headers: nil,
|
|
83
|
+
disable_update_notice: false)
|
|
84
|
+
base_url = Endpoint.normalise(base_url || from_environment(Protocol::ENV_VARS[:BASE_URL]))
|
|
85
|
+
transport = Transport.new(base_url:, adapter:, max_retries:, timeout:, user_agent:, headers:,
|
|
86
|
+
disable_update_notice:)
|
|
87
|
+
Resources::Signups.new(transport)
|
|
88
|
+
end
|
|
89
|
+
|
|
80
90
|
def verify_webhook_signature(payload:, headers:, secret:, tolerance_seconds: nil)
|
|
81
91
|
Webhook.verify(payload:, headers:, secret:, tolerance_seconds:)
|
|
82
92
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nextmail
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nextmail
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-11-01 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Send email and broadcasts, work with threads, drafts, labels, templates,
|
|
13
13
|
rules, webhooks, tracking, contacts, audiences, sign-up forms, domains, suppressions,
|
|
@@ -26,9 +26,11 @@ files:
|
|
|
26
26
|
- lib/nextmail/defaults.rb
|
|
27
27
|
- lib/nextmail/endpoint.rb
|
|
28
28
|
- lib/nextmail/errors.rb
|
|
29
|
+
- lib/nextmail/event_stream.rb
|
|
29
30
|
- lib/nextmail/http.rb
|
|
30
31
|
- lib/nextmail/image_crop.rb
|
|
31
32
|
- lib/nextmail/languages.rb
|
|
33
|
+
- lib/nextmail/live_event_stream.rb
|
|
32
34
|
- lib/nextmail/pagination.rb
|
|
33
35
|
- lib/nextmail/protocol.rb
|
|
34
36
|
- lib/nextmail/raw_body.rb
|
|
@@ -64,8 +66,10 @@ files:
|
|
|
64
66
|
- lib/nextmail/resources/knowledge.rb
|
|
65
67
|
- lib/nextmail/resources/labels.rb
|
|
66
68
|
- lib/nextmail/resources/languages.rb
|
|
69
|
+
- lib/nextmail/resources/live_events.rb
|
|
67
70
|
- lib/nextmail/resources/me.rb
|
|
68
71
|
- lib/nextmail/resources/members.rb
|
|
72
|
+
- lib/nextmail/resources/notifications.rb
|
|
69
73
|
- lib/nextmail/resources/out_of_office.rb
|
|
70
74
|
- lib/nextmail/resources/provider_imports.rb
|
|
71
75
|
- lib/nextmail/resources/roles.rb
|
|
@@ -75,7 +79,10 @@ files:
|
|
|
75
79
|
- lib/nextmail/resources/senders.rb
|
|
76
80
|
- lib/nextmail/resources/sending.rb
|
|
77
81
|
- lib/nextmail/resources/settings.rb
|
|
82
|
+
- lib/nextmail/resources/share_links.rb
|
|
83
|
+
- lib/nextmail/resources/shared.rb
|
|
78
84
|
- lib/nextmail/resources/signatures.rb
|
|
85
|
+
- lib/nextmail/resources/signups.rb
|
|
79
86
|
- lib/nextmail/resources/subscriptions.rb
|
|
80
87
|
- lib/nextmail/resources/support.rb
|
|
81
88
|
- lib/nextmail/resources/suppressions.rb
|
|
@@ -85,6 +92,7 @@ files:
|
|
|
85
92
|
- lib/nextmail/resources/threads.rb
|
|
86
93
|
- lib/nextmail/resources/tools.rb
|
|
87
94
|
- lib/nextmail/resources/tracking.rb
|
|
95
|
+
- lib/nextmail/resources/traffic.rb
|
|
88
96
|
- lib/nextmail/resources/webhooks.rb
|
|
89
97
|
- lib/nextmail/resources/workspaces.rb
|
|
90
98
|
- lib/nextmail/results.rb
|