nextmail 0.0.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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +183 -0
  3. data/lib/nextmail/api_paths.rb +447 -0
  4. data/lib/nextmail/client.rb +81 -0
  5. data/lib/nextmail/constants.rb +1621 -0
  6. data/lib/nextmail/credentials.rb +53 -0
  7. data/lib/nextmail/decode.rb +34 -0
  8. data/lib/nextmail/defaults.rb +114 -0
  9. data/lib/nextmail/endpoint.rb +144 -0
  10. data/lib/nextmail/errors.rb +121 -0
  11. data/lib/nextmail/http.rb +172 -0
  12. data/lib/nextmail/image_crop.rb +38 -0
  13. data/lib/nextmail/languages.rb +42 -0
  14. data/lib/nextmail/pagination.rb +63 -0
  15. data/lib/nextmail/protocol.rb +221 -0
  16. data/lib/nextmail/raw_body.rb +83 -0
  17. data/lib/nextmail/request_path.rb +50 -0
  18. data/lib/nextmail/resource.rb +109 -0
  19. data/lib/nextmail/resources/account.rb +155 -0
  20. data/lib/nextmail/resources/addresses.rb +38 -0
  21. data/lib/nextmail/resources/analytics.rb +19 -0
  22. data/lib/nextmail/resources/app_host.rb +23 -0
  23. data/lib/nextmail/resources/audiences.rb +95 -0
  24. data/lib/nextmail/resources/automations.rb +125 -0
  25. data/lib/nextmail/resources/billing.rb +76 -0
  26. data/lib/nextmail/resources/bookings.rb +100 -0
  27. data/lib/nextmail/resources/branding.rb +24 -0
  28. data/lib/nextmail/resources/broadcasts.rb +102 -0
  29. data/lib/nextmail/resources/calendar.rb +153 -0
  30. data/lib/nextmail/resources/chats.rb +62 -0
  31. data/lib/nextmail/resources/connected_mailboxes.rb +35 -0
  32. data/lib/nextmail/resources/connectors.rb +75 -0
  33. data/lib/nextmail/resources/contacts.rb +197 -0
  34. data/lib/nextmail/resources/dns_connections.rb +23 -0
  35. data/lib/nextmail/resources/domains.rb +264 -0
  36. data/lib/nextmail/resources/drafts.rb +36 -0
  37. data/lib/nextmail/resources/emails.rb +120 -0
  38. data/lib/nextmail/resources/encryption.rb +19 -0
  39. data/lib/nextmail/resources/events.rb +22 -0
  40. data/lib/nextmail/resources/exports.rb +27 -0
  41. data/lib/nextmail/resources/files.rb +82 -0
  42. data/lib/nextmail/resources/follow_ups.rb +21 -0
  43. data/lib/nextmail/resources/forms.rb +112 -0
  44. data/lib/nextmail/resources/imports.rb +106 -0
  45. data/lib/nextmail/resources/keys.rb +126 -0
  46. data/lib/nextmail/resources/knowledge.rb +137 -0
  47. data/lib/nextmail/resources/labels.rb +43 -0
  48. data/lib/nextmail/resources/languages.rb +11 -0
  49. data/lib/nextmail/resources/me.rb +57 -0
  50. data/lib/nextmail/resources/members.rb +100 -0
  51. data/lib/nextmail/resources/out_of_office.rb +28 -0
  52. data/lib/nextmail/resources/provider_imports.rb +48 -0
  53. data/lib/nextmail/resources/roles.rb +39 -0
  54. data/lib/nextmail/resources/rules.rb +73 -0
  55. data/lib/nextmail/resources/security.rb +39 -0
  56. data/lib/nextmail/resources/segments.rb +31 -0
  57. data/lib/nextmail/resources/senders.rb +19 -0
  58. data/lib/nextmail/resources/sending.rb +23 -0
  59. data/lib/nextmail/resources/settings.rb +16 -0
  60. data/lib/nextmail/resources/signatures.rb +41 -0
  61. data/lib/nextmail/resources/subscriptions.rb +55 -0
  62. data/lib/nextmail/resources/support.rb +11 -0
  63. data/lib/nextmail/resources/suppressions.rb +43 -0
  64. data/lib/nextmail/resources/tasks.rb +95 -0
  65. data/lib/nextmail/resources/temp_mail.rb +67 -0
  66. data/lib/nextmail/resources/templates.rb +153 -0
  67. data/lib/nextmail/resources/threads.rb +218 -0
  68. data/lib/nextmail/resources/tools.rb +35 -0
  69. data/lib/nextmail/resources/tracking.rb +72 -0
  70. data/lib/nextmail/resources/webhooks.rb +170 -0
  71. data/lib/nextmail/resources/workspaces.rb +40 -0
  72. data/lib/nextmail/results.rb +33 -0
  73. data/lib/nextmail/transport.rb +272 -0
  74. data/lib/nextmail/update_notice.rb +69 -0
  75. data/lib/nextmail/version.rb +5 -0
  76. data/lib/nextmail/webhook.rb +82 -0
  77. data/lib/nextmail/wire.rb +102 -0
  78. data/lib/nextmail.rb +126 -0
  79. metadata +122 -0
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class Broadcasts < Resource
6
+ def preview(body = nil, api_key: nil, **fields)
7
+ request(ApiPaths::BROADCASTS_PREVIEW, method: :post,
8
+ body: payload(body, fields).slice("audienceIds", "excludeAudienceIds", "segmentId"), repeatable: true,
9
+ api_key:)
10
+ end
11
+
12
+ def send(body = nil, idempotency_key: nil, api_key: nil, **fields)
13
+ wire = payload(body, fields)
14
+ wire["scheduledAt"] = instant(wire["scheduledAt"]) if wire.key?("scheduledAt")
15
+ request(ApiPaths::BROADCASTS, method: :post, body: wire, idempotent: true, idempotency_key:, repeatable: true,
16
+ api_key:)
17
+ end
18
+
19
+ def list(audience_id: nil, limit: nil, cursor: nil, api_key: nil)
20
+ fetch_page(ApiPaths::BROADCASTS, query_params(audience_id:), limit:, cursor:, api_key:)
21
+ end
22
+
23
+ def list_all(audience_id: nil, limit: nil, cursor: nil, api_key: nil)
24
+ collect_all(ApiPaths::BROADCASTS, query_params(audience_id:), limit:, cursor:, api_key:)
25
+ end
26
+
27
+ def iterate(audience_id: nil, limit: nil, cursor: nil, api_key: nil, &)
28
+ iterate_pages(ApiPaths::BROADCASTS, query_params(audience_id:), limit:, cursor:, api_key:, &)
29
+ end
30
+
31
+ def get(id, api_key: nil)
32
+ request(fill(ApiPaths::BROADCAST, id:), api_key:)
33
+ end
34
+
35
+ def list_recipients(id, filter: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
36
+ fetch_page(fill(ApiPaths::BROADCAST_RECIPIENTS, id:), query_params(filter:, q:), limit:, cursor:, api_key:)
37
+ end
38
+
39
+ def list_all_recipients(id, filter: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
40
+ collect_all(fill(ApiPaths::BROADCAST_RECIPIENTS, id:), query_params(filter:, q:), limit:, cursor:, api_key:)
41
+ end
42
+
43
+ def iterate_recipients(id, filter: nil, q: nil, limit: nil, cursor: nil, api_key: nil, &)
44
+ iterate_pages(fill(ApiPaths::BROADCAST_RECIPIENTS, id:), query_params(filter:, q:), limit:, cursor:, api_key:, &)
45
+ end
46
+
47
+ def get_recipient(id, email_id, api_key: nil)
48
+ request(fill(ApiPaths::BROADCAST_RECIPIENT, id:, emailId: email_id), api_key:)
49
+ end
50
+
51
+ def stats(id, grain: nil, offset_minutes: nil, days: nil, minutes: nil, since: nil, api_key: nil)
52
+ query = query_params(grain:, offset_minutes:, days:, minutes:, since: instant(since))
53
+ request(fill(ApiPaths::BROADCAST_STATS, id:), query:, api_key:)
54
+ end
55
+
56
+ def analytics(broadcast_ids: nil, days: nil, minutes: nil, since: nil, grain: nil, offset_minutes: nil,
57
+ api_key: nil)
58
+ query = query_params(broadcast_ids: joined(broadcast_ids), days:, minutes:, since: instant(since), grain:,
59
+ offset_minutes:)
60
+ request(ApiPaths::BROADCASTS_ANALYTICS, query:, api_key:)
61
+ end
62
+
63
+ def cancel(id, api_key: nil)
64
+ request(fill(ApiPaths::BROADCAST_CANCEL, id:), method: :post, repeatable: true, api_key:)
65
+ end
66
+
67
+ def create_draft(body = nil, api_key: nil, **fields)
68
+ request(ApiPaths::BROADCAST_DRAFTS, method: :post, body: payload(body, fields), api_key:)
69
+ end
70
+
71
+ def update(id, patch = nil, api_key: nil, **fields)
72
+ request(fill(ApiPaths::BROADCAST, id:), method: :patch, body: scheduled_wire(payload(patch, fields)),
73
+ repeatable: true, api_key:)
74
+ end
75
+
76
+ def send_draft(id, body = nil, api_key: nil, **fields)
77
+ request(fill(ApiPaths::BROADCAST_SEND, id:), method: :post, body: scheduled_wire(payload(body, fields)),
78
+ api_key:)
79
+ end
80
+
81
+ def duplicate(id, api_key: nil)
82
+ request(fill(ApiPaths::BROADCAST_DUPLICATE, id:), method: :post, api_key:)
83
+ end
84
+
85
+ def resend(id, body = nil, api_key: nil, **fields)
86
+ request(fill(ApiPaths::BROADCAST_RESEND, id:), method: :post, body: scheduled_wire(payload(body, fields)),
87
+ api_key:)
88
+ end
89
+
90
+ def send_test(body = nil, api_key: nil, **fields)
91
+ request(ApiPaths::BROADCASTS_TEST, method: :post, body: payload(body, fields), api_key:)
92
+ end
93
+
94
+ private
95
+
96
+ def scheduled_wire(wire)
97
+ wire["scheduledAt"] = instant(wire["scheduledAt"]) if wire.key?("scheduledAt")
98
+ wire
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class Calendar < Resource
6
+ def list_events(from:, to:, timezone: nil, include_team: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
7
+ query = range_query(from, to, timezone, include_team, q)
8
+ fetch_page(ApiPaths::CALENDAR_EVENTS, query, limit:, cursor:, api_key:)
9
+ end
10
+
11
+ def list_all_events(from:, to:, timezone: nil, include_team: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
12
+ query = range_query(from, to, timezone, include_team, q)
13
+ collect_all(ApiPaths::CALENDAR_EVENTS, query, limit:, cursor:, api_key:)
14
+ end
15
+
16
+ def iterate_events(from:, to:, timezone: nil, include_team: nil, q: nil, limit: nil, cursor: nil, api_key: nil,
17
+ &)
18
+ query = range_query(from, to, timezone, include_team, q)
19
+ iterate_pages(ApiPaths::CALENDAR_EVENTS, query, limit:, cursor:, api_key:, &)
20
+ end
21
+
22
+ def get_event(id, api_key: nil)
23
+ request(fill(ApiPaths::CALENDAR_EVENT, id:), api_key:)
24
+ end
25
+
26
+ def get_event_ics(id, api_key: nil)
27
+ request(fill(ApiPaths::CALENDAR_EVENT_ICS, id:), accept: Protocol::CONTENT_TYPES[:CALENDAR], api_key:)
28
+ end
29
+
30
+ def create_event(body = nil, api_key: nil, **fields)
31
+ request(ApiPaths::CALENDAR_EVENTS, method: :post, body: event_wire(payload(body, fields)), api_key:)
32
+ end
33
+
34
+ def update_event(id, patch = nil, api_key: nil, **fields)
35
+ request(fill(ApiPaths::CALENDAR_EVENT, id:), method: :patch, body: event_wire(payload(patch, fields)), api_key:)
36
+ end
37
+
38
+ def delete_event(id, scope: nil, occurrence_start: nil, api_key: nil)
39
+ query = query_params(scope:, occurrence_start: instant(occurrence_start))
40
+ request(fill(ApiPaths::CALENDAR_EVENT, id:), method: :delete, query:, api_key:)
41
+ end
42
+
43
+ def cancel_event(id, body = nil, api_key: nil, **fields)
44
+ request(fill(ApiPaths::CALENDAR_EVENT_CANCEL, id:), method: :post, body: scope_wire(payload(body, fields)), api_key:)
45
+ end
46
+
47
+ def hide_event(id, api_key: nil)
48
+ request(fill(ApiPaths::CALENDAR_EVENT_HIDE, id:), method: :post, api_key:)
49
+ end
50
+
51
+ def unhide_event(id, api_key: nil)
52
+ request(fill(ApiPaths::CALENDAR_EVENT_UNHIDE, id:), method: :post, api_key:)
53
+ end
54
+
55
+ def free_busy(emails:, from:, to:, timezone: nil, duration_minutes: nil, api_key: nil)
56
+ query = query_params(from: instant(from), to: instant(to), timezone:, emails: joined(emails), duration_minutes:)
57
+ request(ApiPaths::CALENDAR_FREE_BUSY, query:, api_key:)
58
+ end
59
+
60
+ def respond_to_event(id, body = nil, api_key: nil, **fields)
61
+ request(fill(ApiPaths::CALENDAR_EVENT_RESPOND, id:), method: :post, body: answer_wire(payload(body, fields)), api_key:)
62
+ end
63
+
64
+ def decline_proposal(id, body = nil, api_key: nil, **fields)
65
+ request(fill(ApiPaths::CALENDAR_EVENT_DECLINE_PROPOSAL, id:), method: :post, body: payload(body, fields), api_key:)
66
+ end
67
+
68
+ def list_feeds(api_key: nil)
69
+ fetch_list(ApiPaths::CALENDAR_FEEDS, api_key:)
70
+ end
71
+
72
+ def create_feed(body = nil, api_key: nil, **fields)
73
+ request(ApiPaths::CALENDAR_FEEDS, method: :post, body: payload(body, fields), api_key:)
74
+ end
75
+
76
+ def reset_feed(id, api_key: nil)
77
+ request(fill(ApiPaths::CALENDAR_FEED_RESET, id:), method: :post, api_key:)
78
+ end
79
+
80
+ def delete_feed(id, api_key: nil)
81
+ request(fill(ApiPaths::CALENDAR_FEED, id:), method: :delete, api_key:)
82
+ end
83
+
84
+ def list_subscriptions(api_key: nil)
85
+ fetch_list(ApiPaths::CALENDAR_SUBSCRIPTIONS, api_key:)
86
+ end
87
+
88
+ def create_subscription(body = nil, api_key: nil, **fields)
89
+ request(ApiPaths::CALENDAR_SUBSCRIPTIONS, method: :post, body: payload(body, fields), api_key:)
90
+ end
91
+
92
+ def update_subscription(id, patch = nil, api_key: nil, **fields)
93
+ request(fill(ApiPaths::CALENDAR_SUBSCRIPTION, id:), method: :patch, body: payload(patch, fields), api_key:)
94
+ end
95
+
96
+ def refresh_subscription(id, api_key: nil)
97
+ request(fill(ApiPaths::CALENDAR_SUBSCRIPTION_REFRESH, id:), method: :post, api_key:)
98
+ end
99
+
100
+ def delete_subscription(id, api_key: nil)
101
+ request(fill(ApiPaths::CALENDAR_SUBSCRIPTION, id:), method: :delete, api_key:)
102
+ end
103
+
104
+ def import_ics(data, filename: nil, api_key: nil)
105
+ request(ApiPaths::CALENDAR_IMPORTS, method: :post, query: query_params(filename: optional_upload_name(data, filename)),
106
+ raw: data, content_type: Protocol::CONTENT_TYPES[:CALENDAR], api_key:)
107
+ end
108
+
109
+ def list_imports(limit: nil, cursor: nil, api_key: nil)
110
+ fetch_page(ApiPaths::CALENDAR_IMPORTS, limit:, cursor:, api_key:)
111
+ end
112
+
113
+ def list_all_imports(limit: nil, cursor: nil, api_key: nil)
114
+ collect_all(ApiPaths::CALENDAR_IMPORTS, limit:, cursor:, api_key:)
115
+ end
116
+
117
+ def iterate_imports(limit: nil, cursor: nil, api_key: nil, &)
118
+ iterate_pages(ApiPaths::CALENDAR_IMPORTS, limit:, cursor:, api_key:, &)
119
+ end
120
+
121
+ def get_import(id, api_key: nil)
122
+ request(fill(ApiPaths::CALENDAR_IMPORT, id:), api_key:)
123
+ end
124
+
125
+ def undo_import(id, api_key: nil)
126
+ request(fill(ApiPaths::CALENDAR_IMPORT_UNDO, id:), method: :post, api_key:)
127
+ end
128
+
129
+ private
130
+
131
+ def range_query(from, to, timezone, include_team, q)
132
+ query_params(from: instant(from), to: instant(to), timezone:, include_team: flag(include_team), q:)
133
+ end
134
+
135
+ def event_wire(wire)
136
+ wire["start"] = instant(wire["start"]) if wire.key?("start")
137
+ wire["end"] = instant(wire["end"]) if wire.key?("end")
138
+ scope_wire(wire)
139
+ end
140
+
141
+ def scope_wire(wire)
142
+ wire["occurrenceStart"] = instant(wire["occurrenceStart"]) if wire.key?("occurrenceStart")
143
+ wire
144
+ end
145
+
146
+ def answer_wire(wire)
147
+ wire["proposedStart"] = instant(wire["proposedStart"]) if wire.key?("proposedStart")
148
+ wire["proposedEnd"] = instant(wire["proposedEnd"]) if wire.key?("proposedEnd")
149
+ wire
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class Chats < Resource
6
+ def list(q: nil, sort: nil, limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::CHATS, query_params(q:, sort:), limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all(q: nil, sort: nil, limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::CHATS, query_params(q:, sort:), limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate(q: nil, sort: nil, limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::CHATS, query_params(q:, sort:), limit:, cursor:, api_key:, &)
16
+ end
17
+
18
+ def get(id, api_key: nil)
19
+ request(fill(ApiPaths::CHAT, id:), api_key:)
20
+ end
21
+
22
+ def rename(id, title, api_key: nil)
23
+ request(fill(ApiPaths::CHAT, id:), method: :patch, body: {"title" => title}, repeatable: true, api_key:)
24
+ end
25
+
26
+ def delete(id, api_key: nil)
27
+ request(fill(ApiPaths::CHAT, id:), method: :delete, api_key:)
28
+ end
29
+
30
+ def list_messages(id, order: nil, limit: nil, cursor: nil, api_key: nil)
31
+ fetch_page(fill(ApiPaths::CHAT_MESSAGES, id:), query_params(order:), limit:, cursor:, api_key:)
32
+ end
33
+
34
+ def list_all_messages(id, order: nil, limit: nil, cursor: nil, api_key: nil)
35
+ collect_all(fill(ApiPaths::CHAT_MESSAGES, id:), query_params(order:), limit:, cursor:, api_key:)
36
+ end
37
+
38
+ def iterate_messages(id, order: nil, limit: nil, cursor: nil, api_key: nil, &)
39
+ iterate_pages(fill(ApiPaths::CHAT_MESSAGES, id:), query_params(order:), limit:, cursor:, api_key:, &)
40
+ end
41
+
42
+ def send_message(id, body = nil, timeout: nil, api_key: nil, **fields)
43
+ request(fill(ApiPaths::CHAT_MESSAGES, id:), method: :post, body: Wire.with_attachments(payload(body, fields)),
44
+ timeout: turn_timeout(timeout), api_key:)
45
+ end
46
+
47
+ def stop_turn(id, body = nil, api_key: nil, **fields)
48
+ request(fill(ApiPaths::CHAT_STOP, id:), method: :post, body: payload(body, fields), api_key:)
49
+ end
50
+
51
+ def approve_tool_call(id, tool_call_id, body = nil, timeout: nil, api_key: nil, **fields)
52
+ request(fill(ApiPaths::CHAT_TOOL_CALL_APPROVE, id:, toolCallId: tool_call_id), method: :post,
53
+ body: payload(body, fields), timeout: turn_timeout(timeout), api_key:)
54
+ end
55
+
56
+ def deny_tool_call(id, tool_call_id, timeout: nil, api_key: nil)
57
+ request(fill(ApiPaths::CHAT_TOOL_CALL_DENY, id:, toolCallId: tool_call_id), method: :post,
58
+ timeout: turn_timeout(timeout), api_key:)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class ConnectedMailboxes < Resource
6
+ def list(q: nil, api_key: nil)
7
+ fetch_list(ApiPaths::CONNECTED_MAILBOXES, query_params(q:), api_key:)
8
+ end
9
+
10
+ def get(id, api_key: nil)
11
+ request(fill(ApiPaths::CONNECTED_MAILBOX, id:), api_key:)
12
+ end
13
+
14
+ def discover(email, api_key: nil)
15
+ request(ApiPaths::CONNECTED_MAILBOX_SETTINGS, query: query_params(email:), api_key:)
16
+ end
17
+
18
+ def connect(body = nil, api_key: nil, **fields)
19
+ request(ApiPaths::CONNECTED_MAILBOXES, method: :post, body: payload(body, fields), api_key:)
20
+ end
21
+
22
+ def update(id, patch = nil, api_key: nil, **fields)
23
+ request(fill(ApiPaths::CONNECTED_MAILBOX, id:), method: :patch, body: payload(patch, fields), api_key:)
24
+ end
25
+
26
+ def sync(id, api_key: nil)
27
+ request(fill(ApiPaths::CONNECTED_MAILBOX_SYNC, id:), method: :post, repeatable: true, api_key:)
28
+ end
29
+
30
+ def disconnect(id, api_key: nil)
31
+ request(fill(ApiPaths::CONNECTED_MAILBOX, id:), method: :delete, repeatable: true, api_key:)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class Connectors < Resource
6
+ def list_apps(search: nil, category: nil, limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::CONNECTOR_APPS, query_params(search:, category:), limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all_apps(search: nil, category: nil, limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::CONNECTOR_APPS, query_params(search:, category:), limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate_apps(search: nil, category: nil, limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::CONNECTOR_APPS, query_params(search:, category:), limit:, cursor:, api_key:, &)
16
+ end
17
+
18
+ def get_app(slug, api_key: nil)
19
+ request(fill(ApiPaths::CONNECTOR_APP, slug:), api_key:)
20
+ end
21
+
22
+ def list_categories(api_key: nil)
23
+ fetch_list(ApiPaths::CONNECTOR_CATEGORIES, api_key:)
24
+ end
25
+
26
+ def list(scope: nil, status: nil, app: nil, api_key: nil)
27
+ fetch_list(ApiPaths::CONNECTORS, query_params(scope:, status:, app:), api_key:)
28
+ end
29
+
30
+ def get(id, api_key: nil)
31
+ request(fill(ApiPaths::CONNECTOR, id:), api_key:)
32
+ end
33
+
34
+ def connect(body = nil, api_key: nil, **fields)
35
+ request(ApiPaths::CONNECTORS, method: :post, body: payload(body, fields), api_key:)
36
+ end
37
+
38
+ def update(id, patch = nil, api_key: nil, **fields)
39
+ request(fill(ApiPaths::CONNECTOR, id:), method: :patch, body: payload(patch, fields), api_key:)
40
+ end
41
+
42
+ def disconnect(id, api_key: nil)
43
+ request(fill(ApiPaths::CONNECTOR, id:), method: :delete, repeatable: true, api_key:)
44
+ end
45
+
46
+ def reconnect(id, api_key: nil)
47
+ request(fill(ApiPaths::CONNECTOR_RECONNECT, id:), method: :post, api_key:)
48
+ end
49
+
50
+ def list_actions(id, search: nil, limit: nil, api_key: nil)
51
+ fetch_list(fill(ApiPaths::CONNECTOR_ACTIONS, id:), query_params(search:, limit:), api_key:)
52
+ end
53
+
54
+ def get_action(id, action, api_key: nil)
55
+ request(fill(ApiPaths::CONNECTOR_ACTION, id:, action:), api_key:)
56
+ end
57
+
58
+ def run_action(id, action, body = nil, api_key: nil, **fields)
59
+ request(fill(ApiPaths::CONNECTOR_ACTION_RUN, id:, action:), method: :post, body: payload(body, fields), api_key:)
60
+ end
61
+
62
+ def list_calls(connector_id: nil, scope: nil, limit: nil, cursor: nil, api_key: nil)
63
+ fetch_page(ApiPaths::CONNECTOR_CALLS, query_params(connector_id:, scope:), limit:, cursor:, api_key:)
64
+ end
65
+
66
+ def list_all_calls(connector_id: nil, scope: nil, limit: nil, cursor: nil, api_key: nil)
67
+ collect_all(ApiPaths::CONNECTOR_CALLS, query_params(connector_id:, scope:), limit:, cursor:, api_key:)
68
+ end
69
+
70
+ def iterate_calls(connector_id: nil, scope: nil, limit: nil, cursor: nil, api_key: nil, &)
71
+ iterate_pages(ApiPaths::CONNECTOR_CALLS, query_params(connector_id:, scope:), limit:, cursor:, api_key:, &)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class Contacts < Resource
6
+ def list(source: nil, audience_id: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::CONTACTS, query_params(source:, q:, audience_id:), limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all(source: nil, audience_id: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::CONTACTS, query_params(source:, q:, audience_id:), limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate(source: nil, audience_id: nil, q: nil, limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::CONTACTS, query_params(source:, q:, audience_id:), limit:, cursor:, api_key:, &)
16
+ end
17
+
18
+ def get(email, api_key: nil)
19
+ request(fill(ApiPaths::CONTACT, email:), api_key:)
20
+ end
21
+
22
+ def create(body = nil, api_key: nil, **fields)
23
+ request(ApiPaths::CONTACTS, method: :post, body: payload(body, fields), api_key:)
24
+ end
25
+
26
+ def update(email, patch = nil, api_key: nil, **fields)
27
+ request(fill(ApiPaths::CONTACT, email:), method: :patch, body: payload(patch, fields), repeatable: true,
28
+ api_key:)
29
+ end
30
+
31
+ def delete(email, api_key: nil)
32
+ request(fill(ApiPaths::CONTACT, email:), method: :delete, api_key:)
33
+ end
34
+
35
+ def set_audiences(email, body = nil, api_key: nil, **fields)
36
+ request(fill(ApiPaths::CONTACT_AUDIENCES, email:), method: :put, body: payload(body, fields), repeatable: true,
37
+ api_key:)
38
+ end
39
+
40
+ def list_people(q: nil, email: nil, sort: nil, blocked: nil, limit: nil, cursor: nil, api_key: nil)
41
+ query = Pagination.page_query(people_query(q, email, sort, blocked), CURSOR, limit, cursor)
42
+ envelope = request(ApiPaths::CONTACTS_PEOPLE, query:, api_key:)
43
+ envelope = {} unless envelope.is_a?(Hash)
44
+ next_cursor = Pagination.cursor_of(envelope[:nextCursor])
45
+
46
+ PeoplePage.new(
47
+ items: Pagination.items_of(envelope),
48
+ has_more: Pagination.more?(envelope, next_cursor),
49
+ next_cursor:,
50
+ seen: envelope[:seen] == true
51
+ )
52
+ end
53
+
54
+ def list_all_people(q: nil, email: nil, sort: nil, blocked: nil, limit: nil, cursor: nil, api_key: nil)
55
+ collect_all(ApiPaths::CONTACTS_PEOPLE, people_query(q, email, sort, blocked), limit:, cursor:, api_key:)
56
+ end
57
+
58
+ def iterate_people(q: nil, email: nil, sort: nil, blocked: nil, limit: nil, cursor: nil, api_key: nil, &)
59
+ iterate_pages(ApiPaths::CONTACTS_PEOPLE, people_query(q, email, sort, blocked), limit:, cursor:, api_key:, &)
60
+ end
61
+
62
+ def save(email, body = nil, api_key: nil, **fields)
63
+ request(fill(ApiPaths::CONTACT, email:), method: :put, body: payload(body, fields), repeatable: true, api_key:)
64
+ end
65
+
66
+ def delete_many(emails, api_key: nil)
67
+ request(ApiPaths::CONTACTS_BATCH_DELETE, method: :post, body: {"emails" => emails}, repeatable: true, api_key:)
68
+ end
69
+
70
+ def set_photo(email, data, content_type: nil, crop: nil, api_key: nil)
71
+ request(fill(ApiPaths::CONTACT_PHOTO, email:), method: :put, query: crop_query(crop), raw: data,
72
+ content_type: raw_content_type(data, content_type), repeatable: true, timeout: upload_timeout, api_key:)
73
+ end
74
+
75
+ def remove_photo(email, api_key: nil)
76
+ request(fill(ApiPaths::CONTACT_PHOTO, email:), method: :delete, repeatable: true, api_key:)
77
+ end
78
+
79
+ def block(email, api_key: nil)
80
+ request(fill(ApiPaths::CONTACT_BLOCK, email:), method: :post, repeatable: true, api_key:)
81
+ end
82
+
83
+ def unblock(email, api_key: nil)
84
+ request(fill(ApiPaths::CONTACT_BLOCK, email:), method: :delete, repeatable: true, api_key:)
85
+ end
86
+
87
+ def list_threads(email, q: nil, sort: nil, limit: nil, cursor: nil, api_key: nil)
88
+ fetch_page(fill(ApiPaths::CONTACT_THREADS, email:), query_params(q:, sort:), limit:, cursor:, api_key:)
89
+ end
90
+
91
+ def list_all_threads(email, q: nil, sort: nil, limit: nil, cursor: nil, api_key: nil)
92
+ collect_all(fill(ApiPaths::CONTACT_THREADS, email:), query_params(q:, sort:), limit:, cursor:, api_key:)
93
+ end
94
+
95
+ def iterate_threads(email, q: nil, sort: nil, limit: nil, cursor: nil, api_key: nil, &)
96
+ iterate_pages(fill(ApiPaths::CONTACT_THREADS, email:), query_params(q:, sort:), limit:, cursor:, api_key:, &)
97
+ end
98
+
99
+ def list_events(email, name: nil, limit: nil, cursor: nil, api_key: nil)
100
+ fetch_page(fill(ApiPaths::CONTACT_EVENTS, email:), query_params(name:), limit:, cursor:, api_key:)
101
+ end
102
+
103
+ def list_all_events(email, name: nil, limit: nil, cursor: nil, api_key: nil)
104
+ collect_all(fill(ApiPaths::CONTACT_EVENTS, email:), query_params(name:), limit:, cursor:, api_key:)
105
+ end
106
+
107
+ def iterate_events(email, name: nil, limit: nil, cursor: nil, api_key: nil, &)
108
+ iterate_pages(fill(ApiPaths::CONTACT_EVENTS, email:), query_params(name:), limit:, cursor:, api_key:, &)
109
+ end
110
+
111
+ def activity(email, minutes: nil, from: nil, to: nil, grain: nil, offset_minutes: nil, api_key: nil)
112
+ query = query_params(minutes:, grain:, offset_minutes:, from: instant(from), to: instant(to))
113
+ request(fill(ApiPaths::CONTACT_ACTIVITY, email:), query:, api_key:)
114
+ end
115
+
116
+ def list_cards(email: nil, without_email: nil, kind: nil, group_id: nil, limit: nil, cursor: nil, api_key: nil)
117
+ query = card_query(email, without_email, kind, group_id)
118
+ fetch_page(ApiPaths::CONTACT_CARDS, query, limit:, cursor:, api_key:)
119
+ end
120
+
121
+ def list_all_cards(email: nil, without_email: nil, kind: nil, group_id: nil, limit: nil, cursor: nil, api_key: nil)
122
+ query = card_query(email, without_email, kind, group_id)
123
+ collect_all(ApiPaths::CONTACT_CARDS, query, limit:, cursor:, api_key:)
124
+ end
125
+
126
+ def iterate_cards(email: nil, without_email: nil, kind: nil, group_id: nil, limit: nil, cursor: nil, api_key: nil,
127
+ &)
128
+ query = card_query(email, without_email, kind, group_id)
129
+ iterate_pages(ApiPaths::CONTACT_CARDS, query, limit:, cursor:, api_key:, &)
130
+ end
131
+
132
+ def get_card(id, api_key: nil)
133
+ request(fill(ApiPaths::CONTACT_CARD, id:), api_key:)
134
+ end
135
+
136
+ def create_card(body = nil, api_key: nil, **fields)
137
+ request(ApiPaths::CONTACT_CARDS, method: :post, body: payload(body, fields), api_key:)
138
+ end
139
+
140
+ def update_card(id, patch = nil, api_key: nil, **fields)
141
+ request(fill(ApiPaths::CONTACT_CARD, id:), method: :patch, body: payload(patch, fields), repeatable: true,
142
+ api_key:)
143
+ end
144
+
145
+ def delete_card(id, api_key: nil)
146
+ request(fill(ApiPaths::CONTACT_CARD, id:), method: :delete, api_key:)
147
+ end
148
+
149
+ def find_duplicate_cards(api_key: nil)
150
+ request(ApiPaths::CONTACT_CARD_DUPLICATES, api_key:)
151
+ end
152
+
153
+ def merge_cards(id, body = nil, api_key: nil, **fields)
154
+ request(fill(ApiPaths::CONTACT_CARD_MERGE, id:), method: :post, body: payload(body, fields), api_key:)
155
+ end
156
+
157
+ def list_birthdays(from:, to:, timezone: nil, api_key: nil)
158
+ fetch_list(ApiPaths::CONTACT_BIRTHDAYS, query_params(from: instant(from), to: instant(to), timezone:), api_key:)
159
+ end
160
+
161
+ def import_vcf(data, filename: nil, api_key: nil)
162
+ request(ApiPaths::CONTACT_IMPORTS, method: :post, query: query_params(filename: optional_upload_name(data, filename)),
163
+ raw: data, content_type: Protocol::CONTENT_TYPES[:VCARD], api_key:)
164
+ end
165
+
166
+ def list_imports(limit: nil, cursor: nil, api_key: nil)
167
+ fetch_page(ApiPaths::CONTACT_IMPORTS, limit:, cursor:, api_key:)
168
+ end
169
+
170
+ def list_all_imports(limit: nil, cursor: nil, api_key: nil)
171
+ collect_all(ApiPaths::CONTACT_IMPORTS, limit:, cursor:, api_key:)
172
+ end
173
+
174
+ def iterate_imports(limit: nil, cursor: nil, api_key: nil, &)
175
+ iterate_pages(ApiPaths::CONTACT_IMPORTS, limit:, cursor:, api_key:, &)
176
+ end
177
+
178
+ def get_import(id, api_key: nil)
179
+ request(fill(ApiPaths::CONTACT_IMPORT, id:), api_key:)
180
+ end
181
+
182
+ def undo_import(id, api_key: nil)
183
+ request(fill(ApiPaths::CONTACT_IMPORT_UNDO, id:), method: :post, api_key:)
184
+ end
185
+
186
+ private
187
+
188
+ def people_query(q, email, sort, blocked)
189
+ query_params(q:, email:, sort:, blocked: flag(blocked))
190
+ end
191
+
192
+ def card_query(email, without_email, kind, group_id)
193
+ query_params(email:, without_email: flag(without_email), kind:, group_id:)
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nextmail
4
+ module Resources
5
+ class DnsConnections < Resource
6
+ def list(api_key: nil)
7
+ request(ApiPaths::DNS_CONNECTIONS, api_key:)
8
+ end
9
+
10
+ def start(api_key: nil)
11
+ request(ApiPaths::DNS_CONNECTIONS, method: :post, api_key:)
12
+ end
13
+
14
+ def get(id, api_key: nil)
15
+ request(fill(ApiPaths::DNS_CONNECTION, id:), api_key:)
16
+ end
17
+
18
+ def delete(id, api_key: nil)
19
+ request(fill(ApiPaths::DNS_CONNECTION, id:), method: :delete, api_key:)
20
+ end
21
+ end
22
+ end
23
+ end