openemail 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 (66) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +183 -0
  3. data/lib/openemail/api_paths.rb +249 -0
  4. data/lib/openemail/client.rb +69 -0
  5. data/lib/openemail/constants.rb +851 -0
  6. data/lib/openemail/credentials.rb +53 -0
  7. data/lib/openemail/decode.rb +34 -0
  8. data/lib/openemail/defaults.rb +111 -0
  9. data/lib/openemail/endpoint.rb +144 -0
  10. data/lib/openemail/errors.rb +121 -0
  11. data/lib/openemail/http.rb +172 -0
  12. data/lib/openemail/languages.rb +42 -0
  13. data/lib/openemail/pagination.rb +63 -0
  14. data/lib/openemail/protocol.rb +169 -0
  15. data/lib/openemail/raw_body.rb +83 -0
  16. data/lib/openemail/request_path.rb +50 -0
  17. data/lib/openemail/resource.rb +70 -0
  18. data/lib/openemail/resources/account.rb +64 -0
  19. data/lib/openemail/resources/addresses.rb +38 -0
  20. data/lib/openemail/resources/analytics.rb +17 -0
  21. data/lib/openemail/resources/app_host.rb +23 -0
  22. data/lib/openemail/resources/audiences.rb +90 -0
  23. data/lib/openemail/resources/billing.rb +64 -0
  24. data/lib/openemail/resources/branding.rb +24 -0
  25. data/lib/openemail/resources/broadcasts.rb +65 -0
  26. data/lib/openemail/resources/calendar.rb +59 -0
  27. data/lib/openemail/resources/chats.rb +31 -0
  28. data/lib/openemail/resources/contacts.rb +111 -0
  29. data/lib/openemail/resources/dns_connections.rb +19 -0
  30. data/lib/openemail/resources/domains.rb +153 -0
  31. data/lib/openemail/resources/drafts.rb +35 -0
  32. data/lib/openemail/resources/emails.rb +100 -0
  33. data/lib/openemail/resources/encryption.rb +19 -0
  34. data/lib/openemail/resources/exports.rb +27 -0
  35. data/lib/openemail/resources/files.rb +95 -0
  36. data/lib/openemail/resources/forms.rb +111 -0
  37. data/lib/openemail/resources/imports.rb +86 -0
  38. data/lib/openemail/resources/keys.rb +127 -0
  39. data/lib/openemail/resources/labels.rb +39 -0
  40. data/lib/openemail/resources/languages.rb +11 -0
  41. data/lib/openemail/resources/me.rb +19 -0
  42. data/lib/openemail/resources/members.rb +74 -0
  43. data/lib/openemail/resources/provider_imports.rb +40 -0
  44. data/lib/openemail/resources/roles.rb +39 -0
  45. data/lib/openemail/resources/rules.rb +57 -0
  46. data/lib/openemail/resources/security.rb +19 -0
  47. data/lib/openemail/resources/senders.rb +15 -0
  48. data/lib/openemail/resources/settings.rb +16 -0
  49. data/lib/openemail/resources/subscriptions.rb +30 -0
  50. data/lib/openemail/resources/support.rb +11 -0
  51. data/lib/openemail/resources/suppressions.rb +31 -0
  52. data/lib/openemail/resources/temp_mail.rb +67 -0
  53. data/lib/openemail/resources/templates.rb +151 -0
  54. data/lib/openemail/resources/threads.rb +104 -0
  55. data/lib/openemail/resources/tools.rb +19 -0
  56. data/lib/openemail/resources/tracking.rb +63 -0
  57. data/lib/openemail/resources/webhooks.rb +142 -0
  58. data/lib/openemail/resources/workspaces.rb +28 -0
  59. data/lib/openemail/results.rb +33 -0
  60. data/lib/openemail/transport.rb +272 -0
  61. data/lib/openemail/update_notice.rb +69 -0
  62. data/lib/openemail/version.rb +5 -0
  63. data/lib/openemail/webhook.rb +82 -0
  64. data/lib/openemail/wire.rb +95 -0
  65. data/lib/openemail.rb +125 -0
  66. metadata +109 -0
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Billing < Resource
6
+ def get(api_key: nil)
7
+ request(ApiPaths::BILLING, api_key:)
8
+ end
9
+
10
+ def list_plans(api_key: nil)
11
+ request(ApiPaths::BILLING_PLANS, api_key:)
12
+ end
13
+
14
+ def get_usage(days: nil, api_key: nil)
15
+ request(ApiPaths::BILLING_USAGE, query: query_params(days:), api_key:)
16
+ end
17
+
18
+ def list_alerts(api_key: nil)
19
+ request(ApiPaths::BILLING_ALERTS, api_key:)
20
+ end
21
+
22
+ def list_countries(api_key: nil)
23
+ request(ApiPaths::BILLING_COUNTRIES, api_key:)
24
+ end
25
+
26
+ def get_pay_as_you_go(api_key: nil)
27
+ request(ApiPaths::BILLING_PAY_AS_YOU_GO, api_key:)
28
+ end
29
+
30
+ def set_pay_as_you_go(body = nil, api_key: nil, **fields)
31
+ request(ApiPaths::BILLING_PAY_AS_YOU_GO, method: :patch, body: payload(body, fields), api_key:)
32
+ end
33
+
34
+ def set_pay_as_you_go_limit(body = nil, api_key: nil, **fields)
35
+ request(ApiPaths::BILLING_PAY_AS_YOU_GO_LIMIT, method: :put, body: payload(body, fields), api_key:)
36
+ end
37
+
38
+ def confirm_pay_as_you_go(api_key: nil)
39
+ request(ApiPaths::BILLING_PAY_AS_YOU_GO_CONFIRM, method: :post, api_key:)
40
+ end
41
+
42
+ def start_checkout(body = nil, api_key: nil, **fields)
43
+ request(ApiPaths::BILLING_CHECKOUT, method: :post, body: payload(body, fields), api_key:)
44
+ end
45
+
46
+ def open_portal(body = nil, api_key: nil, **fields)
47
+ request(ApiPaths::BILLING_PORTAL, method: :post, body: payload(body, fields), api_key:)
48
+ end
49
+
50
+ def list_invoices(page: nil, limit: nil, sort: nil, search: nil, api_key: nil)
51
+ request(ApiPaths::BILLING_INVOICES, query: query_params(page:, limit:, sort:, search:), api_key:)
52
+ end
53
+
54
+ def get_invoice(order_id, api_key: nil)
55
+ request(fill(ApiPaths::BILLING_INVOICE, orderId: order_id), api_key:)
56
+ end
57
+
58
+ def save_invoice_details(order_id, body = nil, api_key: nil, **fields)
59
+ request(fill(ApiPaths::BILLING_INVOICE_DETAILS, orderId: order_id), method: :put, body: payload(body, fields),
60
+ api_key:)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Branding < Resource
6
+ def get(api_key: nil)
7
+ request(ApiPaths::BRANDING, api_key:)
8
+ end
9
+
10
+ def update(body = nil, api_key: nil, **fields)
11
+ request(ApiPaths::BRANDING, method: :patch, body: payload(body, fields), repeatable: true, api_key:)
12
+ end
13
+
14
+ def upload_image(variant, data, content_type: nil, api_key: nil)
15
+ request(fill(ApiPaths::BRANDING_IMAGE, variant:), method: :put, raw: data,
16
+ content_type: raw_content_type(data, content_type), repeatable: true, api_key:)
17
+ end
18
+
19
+ def remove_image(variant, api_key: nil)
20
+ request(fill(ApiPaths::BRANDING_IMAGE, variant:), method: :delete, repeatable: true, api_key:)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Broadcasts < Resource
6
+ def preview(body = nil, api_key: nil, **fields)
7
+ request(ApiPaths::BROADCASTS_PREVIEW, method: :post, body: payload(body, fields).slice("audienceIds"),
8
+ repeatable: true, api_key:)
9
+ end
10
+
11
+ def send(body = nil, idempotency_key: nil, api_key: nil, **fields)
12
+ wire = payload(body, fields)
13
+ wire["scheduledAt"] = instant(wire["scheduledAt"]) if wire.key?("scheduledAt")
14
+ request(ApiPaths::BROADCASTS, method: :post, body: wire, idempotent: true, idempotency_key:, repeatable: true,
15
+ api_key:)
16
+ end
17
+
18
+ def list(audience_id: nil, limit: nil, cursor: nil, api_key: nil)
19
+ fetch_page(ApiPaths::BROADCASTS, query_params(audience_id:), limit:, cursor:, api_key:)
20
+ end
21
+
22
+ def list_all(audience_id: nil, limit: nil, cursor: nil, api_key: nil)
23
+ collect_all(ApiPaths::BROADCASTS, query_params(audience_id:), limit:, cursor:, api_key:)
24
+ end
25
+
26
+ def iterate(audience_id: nil, limit: nil, cursor: nil, api_key: nil, &)
27
+ iterate_pages(ApiPaths::BROADCASTS, query_params(audience_id:), limit:, cursor:, api_key:, &)
28
+ end
29
+
30
+ def get(id, api_key: nil)
31
+ request(fill(ApiPaths::BROADCAST, id:), api_key:)
32
+ end
33
+
34
+ def list_recipients(id, filter: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
35
+ fetch_page(fill(ApiPaths::BROADCAST_RECIPIENTS, id:), query_params(filter:, q:), limit:, cursor:, api_key:)
36
+ end
37
+
38
+ def list_all_recipients(id, filter: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
39
+ collect_all(fill(ApiPaths::BROADCAST_RECIPIENTS, id:), query_params(filter:, q:), limit:, cursor:, api_key:)
40
+ end
41
+
42
+ def iterate_recipients(id, filter: nil, q: nil, limit: nil, cursor: nil, api_key: nil, &)
43
+ iterate_pages(fill(ApiPaths::BROADCAST_RECIPIENTS, id:), query_params(filter:, q:), limit:, cursor:, api_key:, &)
44
+ end
45
+
46
+ def get_recipient(id, email_id, api_key: nil)
47
+ request(fill(ApiPaths::BROADCAST_RECIPIENT, id:, emailId: email_id), api_key:)
48
+ end
49
+
50
+ def stats(id, grain: nil, offset_minutes: nil, days: nil, minutes: nil, api_key: nil)
51
+ request(fill(ApiPaths::BROADCAST_STATS, id:), query: query_params(grain:, offset_minutes:, days:, minutes:),
52
+ api_key:)
53
+ end
54
+
55
+ def analytics(broadcast_ids: nil, days: nil, minutes: nil, grain: nil, offset_minutes: nil, api_key: nil)
56
+ query = query_params(broadcast_ids: joined(broadcast_ids), days:, minutes:, grain:, offset_minutes:)
57
+ request(ApiPaths::BROADCASTS_ANALYTICS, query:, api_key:)
58
+ end
59
+
60
+ def cancel(id, api_key: nil)
61
+ request(fill(ApiPaths::BROADCAST_CANCEL, id:), method: :post, repeatable: true, api_key:)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Calendar < Resource
6
+ def list_events(from:, to:, timezone: nil, limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::CALENDAR_EVENTS, range_query(from, to, timezone), limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all_events(from:, to:, timezone: nil, limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::CALENDAR_EVENTS, range_query(from, to, timezone), limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate_events(from:, to:, timezone: nil, limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::CALENDAR_EVENTS, range_query(from, to, timezone), limit:, cursor:, api_key:, &)
16
+ end
17
+
18
+ def get_event(id, api_key: nil)
19
+ request(fill(ApiPaths::CALENDAR_EVENT, id:), api_key:)
20
+ end
21
+
22
+ def get_event_ics(id, api_key: nil)
23
+ request(fill(ApiPaths::CALENDAR_EVENT_ICS, id:), accept: Protocol::CONTENT_TYPES[:CALENDAR], api_key:)
24
+ end
25
+
26
+ def create_event(body = nil, api_key: nil, **fields)
27
+ request(ApiPaths::CALENDAR_EVENTS, method: :post, body: event_wire(payload(body, fields)), api_key:)
28
+ end
29
+
30
+ def update_event(id, patch = nil, api_key: nil, **fields)
31
+ request(fill(ApiPaths::CALENDAR_EVENT, id:), method: :patch, body: event_wire(payload(patch, fields)), api_key:)
32
+ end
33
+
34
+ def delete_event(id, api_key: nil)
35
+ request(fill(ApiPaths::CALENDAR_EVENT, id:), method: :delete, api_key:)
36
+ end
37
+
38
+ def cancel_event(id, body = nil, api_key: nil, **fields)
39
+ request(fill(ApiPaths::CALENDAR_EVENT_CANCEL, id:), method: :post, body: payload(body, fields), api_key:)
40
+ end
41
+
42
+ def respond_to_event(id, body = nil, api_key: nil, **fields)
43
+ request(fill(ApiPaths::CALENDAR_EVENT_RESPOND, id:), method: :post, body: payload(body, fields), api_key:)
44
+ end
45
+
46
+ private
47
+
48
+ def range_query(from, to, timezone)
49
+ query_params(from: instant(from), to: instant(to), timezone:)
50
+ end
51
+
52
+ def event_wire(wire)
53
+ wire["start"] = instant(wire["start"]) if wire.key?("start")
54
+ wire["end"] = instant(wire["end"]) if wire.key?("end")
55
+ wire
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
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
+ end
30
+ end
31
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Contacts < Resource
6
+ def list(source: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::CONTACTS, query_params(source:, q:), limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all(source: nil, q: nil, limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::CONTACTS, query_params(source:, q:), limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate(source: nil, q: nil, limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::CONTACTS, query_params(source:, q:), 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, api_key: nil)
71
+ request(fill(ApiPaths::CONTACT_PHOTO, email:), method: :put, raw: data,
72
+ content_type: raw_content_type(data, content_type), repeatable: true, 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 activity(email, minutes: nil, grain: nil, offset_minutes: nil, api_key: nil)
100
+ request(fill(ApiPaths::CONTACT_ACTIVITY, email:), query: query_params(minutes:, grain:, offset_minutes:),
101
+ api_key:)
102
+ end
103
+
104
+ private
105
+
106
+ def people_query(q, email, sort, blocked)
107
+ query_params(q:, email:, sort:, blocked: flag(blocked))
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
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 get(id, api_key: nil)
11
+ request(fill(ApiPaths::DNS_CONNECTION, id:), api_key:)
12
+ end
13
+
14
+ def delete(id, api_key: nil)
15
+ request(fill(ApiPaths::DNS_CONNECTION, id:), method: :delete, api_key:)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Domains < Resource
6
+ def list(limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::DOMAINS, limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all(limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::DOMAINS, limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate(limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::DOMAINS, limit:, cursor:, api_key:, &)
16
+ end
17
+
18
+ def get(id, api_key: nil)
19
+ request(fill(ApiPaths::DOMAIN, id:), api_key:)
20
+ end
21
+
22
+ def create(body = nil, api_key: nil, **fields)
23
+ request(ApiPaths::DOMAINS, method: :post, body: payload(body, fields), api_key:)
24
+ end
25
+
26
+ def verify(id, api_key: nil)
27
+ request(fill(ApiPaths::DOMAIN_VERIFY, id:), method: :post, repeatable: true, api_key:)
28
+ end
29
+
30
+ def update(id, patch = nil, api_key: nil, **fields)
31
+ request(fill(ApiPaths::DOMAIN, id:), method: :patch, body: payload(patch, fields), repeatable: true, api_key:)
32
+ end
33
+
34
+ def delete(id, api_key: nil)
35
+ request(fill(ApiPaths::DOMAIN, id:), method: :delete, api_key:)
36
+ end
37
+
38
+ def get_logo(id, api_key: nil)
39
+ request(fill(ApiPaths::DOMAIN_LOGO, id:), api_key:)
40
+ end
41
+
42
+ def set_logo(id, body = nil, api_key: nil, **fields)
43
+ request(fill(ApiPaths::DOMAIN_LOGO, id:), method: :put, body: payload(body, fields), repeatable: true, api_key:)
44
+ end
45
+
46
+ def remove_logo(id, api_key: nil)
47
+ request(fill(ApiPaths::DOMAIN_LOGO, id:), method: :delete, repeatable: true, api_key:)
48
+ end
49
+
50
+ def set_logo_certificate(id, body = nil, api_key: nil, **fields)
51
+ request(fill(ApiPaths::DOMAIN_LOGO_CERTIFICATE, id:), method: :put, body: payload(body, fields),
52
+ repeatable: true, api_key:)
53
+ end
54
+
55
+ def remove_logo_certificate(id, api_key: nil)
56
+ request(fill(ApiPaths::DOMAIN_LOGO_CERTIFICATE, id:), method: :delete, repeatable: true, api_key:)
57
+ end
58
+
59
+ def list_addresses(id, limit: nil, cursor: nil, api_key: nil)
60
+ fetch_page(fill(ApiPaths::DOMAIN_ADDRESSES, id:), limit:, cursor:, api_key:)
61
+ end
62
+
63
+ def list_all_addresses(id, limit: nil, cursor: nil, api_key: nil)
64
+ collect_all(fill(ApiPaths::DOMAIN_ADDRESSES, id:), limit:, cursor:, api_key:)
65
+ end
66
+
67
+ def iterate_addresses(id, limit: nil, cursor: nil, api_key: nil, &)
68
+ iterate_pages(fill(ApiPaths::DOMAIN_ADDRESSES, id:), limit:, cursor:, api_key:, &)
69
+ end
70
+
71
+ def create_address(id, body = nil, api_key: nil, **fields)
72
+ request(fill(ApiPaths::DOMAIN_ADDRESSES, id:), method: :post, body: payload(body, fields), repeatable: true,
73
+ api_key:)
74
+ end
75
+
76
+ def get_address(id, address_id, api_key: nil)
77
+ request(fill(ApiPaths::DOMAIN_ADDRESS, id:, addressId: address_id), api_key:)
78
+ end
79
+
80
+ def update_address(id, address_id, patch = nil, api_key: nil, **fields)
81
+ request(fill(ApiPaths::DOMAIN_ADDRESS, id:, addressId: address_id), method: :patch,
82
+ body: payload(patch, fields), repeatable: true, api_key:)
83
+ end
84
+
85
+ def set_address_photo(id, address_id, data, content_type: nil, api_key: nil)
86
+ request(fill(ApiPaths::DOMAIN_ADDRESS_PHOTO, id:, addressId: address_id), method: :put, raw: data,
87
+ content_type: raw_content_type(data, content_type), repeatable: true, api_key:)
88
+ end
89
+
90
+ def remove_address_photo(id, address_id, api_key: nil)
91
+ request(fill(ApiPaths::DOMAIN_ADDRESS_PHOTO, id:, addressId: address_id), method: :delete, repeatable: true,
92
+ api_key:)
93
+ end
94
+
95
+ def delete_address(id, address_id, api_key: nil)
96
+ request(fill(ApiPaths::DOMAIN_ADDRESS, id:, addressId: address_id), method: :delete, api_key:)
97
+ end
98
+
99
+ def list_address_forwards(id, address_id, api_key: nil)
100
+ request(fill(ApiPaths::DOMAIN_ADDRESS_FORWARDS, id:, addressId: address_id), api_key:)
101
+ end
102
+
103
+ def add_address_forwards(id, address_id, body = nil, api_key: nil, **fields)
104
+ request(fill(ApiPaths::DOMAIN_ADDRESS_FORWARDS, id:, addressId: address_id), method: :post,
105
+ body: payload(body, fields), api_key:)
106
+ end
107
+
108
+ def update_address_forward(id, address_id, forward_id, patch = nil, api_key: nil, **fields)
109
+ request(fill(ApiPaths::DOMAIN_ADDRESS_FORWARD, id:, addressId: address_id, forwardId: forward_id),
110
+ method: :patch, body: payload(patch, fields), repeatable: true, api_key:)
111
+ end
112
+
113
+ def delete_address_forward(id, address_id, forward_id, api_key: nil)
114
+ request(fill(ApiPaths::DOMAIN_ADDRESS_FORWARD, id:, addressId: address_id, forwardId: forward_id),
115
+ method: :delete, api_key:)
116
+ end
117
+
118
+ def resend_address_forward_consent(id, address_id, forward_id, api_key: nil)
119
+ request(fill(ApiPaths::DOMAIN_ADDRESS_FORWARD_RESEND, id:, addressId: address_id, forwardId: forward_id),
120
+ method: :post, api_key:)
121
+ end
122
+
123
+ def list_address_members(id, address_id, api_key: nil)
124
+ request(fill(ApiPaths::DOMAIN_ADDRESS_MEMBERS, id:, addressId: address_id), api_key:)
125
+ end
126
+
127
+ def get_address_login(id, address_id, api_key: nil)
128
+ request(fill(ApiPaths::DOMAIN_ADDRESS_LOGIN, id:, addressId: address_id), api_key:)
129
+ end
130
+
131
+ def set_address_login(id, address_id, body = nil, api_key: nil, **fields)
132
+ request(fill(ApiPaths::DOMAIN_ADDRESS_LOGIN, id:, addressId: address_id), method: :put,
133
+ body: payload(body, fields), api_key:)
134
+ end
135
+
136
+ def delete_address_login(id, address_id, api_key: nil)
137
+ request(fill(ApiPaths::DOMAIN_ADDRESS_LOGIN, id:, addressId: address_id), method: :delete, api_key:)
138
+ end
139
+
140
+ def get_dns(id, refresh: nil, api_key: nil)
141
+ request(fill(ApiPaths::DOMAIN_DNS, id:), query: query_params(refresh:), api_key:)
142
+ end
143
+
144
+ def set_dns_zone(id, body = nil, api_key: nil, **fields)
145
+ request(fill(ApiPaths::DOMAIN_DNS, id:), method: :put, body: payload(body, fields), api_key:)
146
+ end
147
+
148
+ def sync_dns(id, body = nil, api_key: nil, **fields)
149
+ request(fill(ApiPaths::DOMAIN_DNS_SYNC, id:), method: :post, body: payload(body, fields), api_key:)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Drafts < Resource
6
+ def list(query: nil, limit: nil, cursor: nil, api_key: nil)
7
+ fetch_page(ApiPaths::DRAFTS, query_params(query:), style: PAGE_TOKEN, limit:, cursor:, api_key:)
8
+ end
9
+
10
+ def list_all(query: nil, limit: nil, cursor: nil, api_key: nil)
11
+ collect_all(ApiPaths::DRAFTS, query_params(query:), style: PAGE_TOKEN, limit:, cursor:, api_key:)
12
+ end
13
+
14
+ def iterate(query: nil, limit: nil, cursor: nil, api_key: nil, &)
15
+ iterate_pages(ApiPaths::DRAFTS, query_params(query:), style: PAGE_TOKEN, limit:, cursor:, api_key:, &)
16
+ end
17
+
18
+ def get(id, api_key: nil)
19
+ request(fill(ApiPaths::DRAFT, id:), api_key:)
20
+ end
21
+
22
+ def create(body = nil, api_key: nil, **fields)
23
+ request(ApiPaths::DRAFTS, method: :post, body: payload(body, fields), api_key:)
24
+ end
25
+
26
+ def update(id, body = nil, api_key: nil, **fields)
27
+ request(fill(ApiPaths::DRAFT, id:), method: :patch, body: payload(body, fields), api_key:)
28
+ end
29
+
30
+ def delete(id, api_key: nil)
31
+ request(fill(ApiPaths::DRAFT, id:), method: :delete, api_key:)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Emails < Resource
6
+ def send(body = nil, idempotency_key: nil, api_key: nil, **fields)
7
+ request(ApiPaths::EMAILS, method: :post, body: Wire.email(payload(body, fields)), idempotent: true,
8
+ idempotency_key:, repeatable: true, api_key:)
9
+ end
10
+
11
+ def send_batch(emails, idempotency_key: nil, api_key: nil)
12
+ wire = emails.map { |email| Wire.email(payload(email, {})) }
13
+ result = request(ApiPaths::EMAILS_BATCH, method: :post, body: {"emails" => wire}, idempotent: true,
14
+ idempotency_key:, repeatable: true, api_key:)
15
+ envelope = result.is_a?(Hash) ? result : {}
16
+
17
+ BatchResult.new(items: Pagination.items_of(envelope), sent: envelope[:sent], failed: envelope[:failed])
18
+ end
19
+
20
+ def translate(body = nil, api_key: nil, **fields)
21
+ request(ApiPaths::EMAILS_TRANSLATE, method: :post, body: payload(body, fields), api_key:)
22
+ end
23
+
24
+ def check(body = nil, api_key: nil, **fields)
25
+ request(ApiPaths::EMAILS_CHECK, method: :post, body: payload(body, fields), api_key:)
26
+ end
27
+
28
+ def list(status: nil, from: nil, broadcast_id: nil, scheduled_from: nil, scheduled_to: nil, limit: nil,
29
+ cursor: nil, api_key: nil)
30
+ fetch_page(ApiPaths::EMAILS, list_query(status, from, broadcast_id, scheduled_from, scheduled_to), limit:,
31
+ cursor:, api_key:)
32
+ end
33
+
34
+ def list_all(status: nil, from: nil, broadcast_id: nil, scheduled_from: nil, scheduled_to: nil, limit: nil,
35
+ cursor: nil, api_key: nil)
36
+ collect_all(ApiPaths::EMAILS, list_query(status, from, broadcast_id, scheduled_from, scheduled_to), limit:,
37
+ cursor:, api_key:)
38
+ end
39
+
40
+ def iterate(status: nil, from: nil, broadcast_id: nil, scheduled_from: nil, scheduled_to: nil, limit: nil,
41
+ cursor: nil, api_key: nil, &)
42
+ iterate_pages(ApiPaths::EMAILS, list_query(status, from, broadcast_id, scheduled_from, scheduled_to), limit:,
43
+ cursor:, api_key:, &)
44
+ end
45
+
46
+ def get(id, api_key: nil)
47
+ request(fill(ApiPaths::EMAIL, id:), api_key:)
48
+ end
49
+
50
+ def list_events(id, limit: nil, cursor: nil, api_key: nil)
51
+ fetch_page(fill(ApiPaths::EMAIL_EVENTS, id:), limit:, cursor:, api_key:)
52
+ end
53
+
54
+ def list_all_events(id, limit: nil, cursor: nil, api_key: nil)
55
+ collect_all(fill(ApiPaths::EMAIL_EVENTS, id:), limit:, cursor:, api_key:)
56
+ end
57
+
58
+ def iterate_events(id, limit: nil, cursor: nil, api_key: nil, &)
59
+ iterate_pages(fill(ApiPaths::EMAIL_EVENTS, id:), limit:, cursor:, api_key:, &)
60
+ end
61
+
62
+ def get_tracking(id, api_key: nil)
63
+ request(fill(ApiPaths::EMAIL_TRACKING, id:), api_key:)
64
+ end
65
+
66
+ def cancel(id, api_key: nil)
67
+ request(fill(ApiPaths::EMAIL_CANCEL, id:), method: :post, repeatable: true, api_key:)
68
+ end
69
+
70
+ def reschedule(id, scheduled_at, api_key: nil)
71
+ request(fill(ApiPaths::EMAIL, id:), method: :patch, body: {"scheduledAt" => instant(scheduled_at)},
72
+ repeatable: true, api_key:)
73
+ end
74
+
75
+ def update(id, patch = nil, api_key: nil, **fields)
76
+ request(fill(ApiPaths::EMAIL, id:), method: :patch, body: Wire.recipients(payload(patch, fields)),
77
+ repeatable: true, api_key:)
78
+ end
79
+
80
+ def compose(body = nil, api_key: nil, **fields)
81
+ request(ApiPaths::EMAILS_COMPOSE, method: :post, body: payload(body, fields), api_key:)
82
+ end
83
+
84
+ def rewrite(body = nil, api_key: nil, **fields)
85
+ request(ApiPaths::EMAILS_REWRITE, method: :post, body: payload(body, fields), api_key:)
86
+ end
87
+
88
+ def suggest_subject(body = nil, api_key: nil, **fields)
89
+ request(ApiPaths::EMAILS_SUBJECT, method: :post, body: payload(body, fields), api_key:)
90
+ end
91
+
92
+ private
93
+
94
+ def list_query(status, from, broadcast_id, scheduled_from, scheduled_to)
95
+ query_params(status: joined(status), from:, broadcast_id:, scheduled_from: instant(scheduled_from),
96
+ scheduled_to: instant(scheduled_to))
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenEmail
4
+ module Resources
5
+ class Encryption < Resource
6
+ def list_keys(api_key: nil)
7
+ fetch_list(ApiPaths::ENCRYPTION_KEYS, api_key:)
8
+ end
9
+
10
+ def publish_key(body = nil, api_key: nil, **fields)
11
+ request(ApiPaths::ENCRYPTION_KEYS, method: :post, body: payload(body, fields), api_key:)
12
+ end
13
+
14
+ def lookup_keys(addresses:, api_key: nil)
15
+ fetch_list(ApiPaths::ENCRYPTION_KEYS_LOOKUP, query_params(addresses: joined(addresses)), api_key:)
16
+ end
17
+ end
18
+ end
19
+ end