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 Wire
5
+ RECIPIENT_FIELDS = %w[to cc bcc].freeze
6
+ BASE64_TEXT = %r{\A(?:[A-Za-z0-9+/_-]{4})*(?:[A-Za-z0-9+/_-]{2}==|[A-Za-z0-9+/_-]{3}=)?\z}
7
+ BASE64_WHITESPACE = " \t\n\f\r"
8
+ ISO_INSTANT = "%Y-%m-%dT%H:%M:%S.%LZ"
9
+
10
+ module_function
11
+
12
+ def body(value, fields)
13
+ base = value.nil? ? {} : hash_of(value)
14
+ base.merge(fields).transform_keys(&:to_s)
15
+ end
16
+
17
+ def hash_of(value)
18
+ return value if value.is_a?(Hash)
19
+ return value.to_hash if value.respond_to?(:to_hash)
20
+
21
+ raise ArgumentError, Defaults::MESSAGES[:BODY_SHAPE]
22
+ end
23
+
24
+ def email(body)
25
+ with_attachments(recipients(body)).tap do |wire|
26
+ wire["followUpAt"] = instant(wire["followUpAt"]) if wire.key?("followUpAt")
27
+ end
28
+ end
29
+
30
+ def with_attachments(body)
31
+ body.dup.tap do |wire|
32
+ next unless wire.key?("attachments")
33
+
34
+ attachments = wire.delete("attachments")
35
+ wire["attachments"] = list(attachments).map { |attachment| attachment(attachment) } unless attachments.nil?
36
+ end
37
+ end
38
+
39
+ def recipients(body)
40
+ body.dup.tap do |wire|
41
+ RECIPIENT_FIELDS.each { |field| wire[field] = many(wire[field]) unless wire[field].nil? }
42
+ wire["scheduledAt"] = instant(wire["scheduledAt"]) if wire.key?("scheduledAt")
43
+ end
44
+ end
45
+
46
+ def many(value)
47
+ collection?(value) ? list(value) : [value]
48
+ end
49
+
50
+ def attachment(value)
51
+ entry = hash_of(value).transform_keys(&:to_s)
52
+ return {"fileId" => entry["fileId"]} if entry.key?("fileId")
53
+ return entry.slice("url", "filename", "contentType") if entry.key?("url")
54
+
55
+ wire = {"filename" => entry["filename"], "content" => content(entry["content"])}
56
+ wire["contentType"] = entry["contentType"] if entry.key?("contentType")
57
+ wire
58
+ end
59
+
60
+ def content(value)
61
+ return [RawBody.read(value)].pack("m0") unless value.is_a?(String) && value.encoding != Encoding::BINARY
62
+ return value if BASE64_TEXT.match?(value.delete(BASE64_WHITESPACE))
63
+
64
+ raise ArgumentError, Defaults::MESSAGES[:ATTACHMENT_CONTENT_SHAPE]
65
+ end
66
+
67
+ def instant(value)
68
+ return value.getutc.strftime(ISO_INSTANT) if value.respond_to?(:getutc)
69
+ return value.new_offset(0).strftime(ISO_INSTANT) if value.is_a?(DateTime)
70
+ return value.iso8601 if value.is_a?(Date)
71
+
72
+ value
73
+ end
74
+
75
+ def number(value)
76
+ return value if value.is_a?(Integer)
77
+ return value unless value.is_a?(Numeric) && value.finite?
78
+
79
+ (value == value.truncate) ? value.truncate : value.to_f
80
+ end
81
+
82
+ def scalar(value)
83
+ number(instant(value))
84
+ end
85
+
86
+ def collection?(value)
87
+ value.is_a?(Array) || value.is_a?(Set)
88
+ end
89
+
90
+ def list(value)
91
+ collection?(value) ? value.to_a : value
92
+ end
93
+
94
+ def json_ready(value)
95
+ case value
96
+ when Hash then value.to_h { |key, item| [key, json_ready(item)] }
97
+ when Array, Set then value.map { |item| json_ready(item) }
98
+ else scalar(value)
99
+ end
100
+ end
101
+ end
102
+ end
data/lib/nextmail.rb ADDED
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ipaddr"
4
+ require "json"
5
+ require "net/http"
6
+ require "openssl"
7
+ require "pathname"
8
+ require "securerandom"
9
+ require "time"
10
+ require "uri"
11
+
12
+ require_relative "nextmail/version"
13
+ require_relative "nextmail/constants"
14
+ require_relative "nextmail/protocol"
15
+ require_relative "nextmail/api_paths"
16
+ require_relative "nextmail/defaults"
17
+ require_relative "nextmail/errors"
18
+ require_relative "nextmail/credentials"
19
+ require_relative "nextmail/endpoint"
20
+ require_relative "nextmail/decode"
21
+ require_relative "nextmail/request_path"
22
+ require_relative "nextmail/raw_body"
23
+ require_relative "nextmail/wire"
24
+ require_relative "nextmail/image_crop"
25
+ require_relative "nextmail/http"
26
+ require_relative "nextmail/update_notice"
27
+ require_relative "nextmail/transport"
28
+ require_relative "nextmail/results"
29
+ require_relative "nextmail/pagination"
30
+ require_relative "nextmail/webhook"
31
+ require_relative "nextmail/languages"
32
+ require_relative "nextmail/resource"
33
+
34
+ Dir[File.join(__dir__, "nextmail", "resources", "*.rb")].sort.each { |path| require path }
35
+
36
+ require_relative "nextmail/client"
37
+
38
+ module Nextmail
39
+ @default_client = nil
40
+ @default_lock = Mutex.new
41
+
42
+ class << self
43
+ def new(...)
44
+ Client.new(...)
45
+ end
46
+
47
+ def create_client(key = nil, api_key: nil, access_token: nil, base_url: nil, **options)
48
+ raise ArgumentError, Defaults::MESSAGES[:KEY_TWICE] unless key.nil? || api_key.nil?
49
+
50
+ api_key = key if api_key.nil?
51
+ explicit = !api_key.nil? || !access_token.nil?
52
+ api_key = from_environment(Protocol::ENV_VARS[:API_KEY]) unless explicit
53
+ access_token = from_environment(Protocol::ENV_VARS[:ACCESS_TOKEN]) unless explicit || !api_key.nil?
54
+ base_url = Endpoint.normalise(base_url || from_environment(Protocol::ENV_VARS[:BASE_URL]))
55
+
56
+ Client.new(api_key:, access_token:, base_url:, **options)
57
+ end
58
+
59
+ def init(...)
60
+ created = create_client(...)
61
+ @default_lock.synchronize { @default_client = created }
62
+ end
63
+
64
+ def client
65
+ @default_lock.synchronize { @default_client ||= create_client }
66
+ end
67
+
68
+ def reset_client
69
+ @default_lock.synchronize { @default_client = nil }
70
+ end
71
+
72
+ def create_temp_mail(base_url: nil, inbox_token: nil, adapter: nil, max_retries: nil, timeout: nil, user_agent: nil,
73
+ headers: nil, disable_update_notice: false)
74
+ base_url = Endpoint.normalise(base_url || from_environment(Protocol::ENV_VARS[:BASE_URL]))
75
+ transport = Transport.new(base_url:, inbox_token:, adapter:, max_retries:, timeout:, user_agent:, headers:,
76
+ disable_update_notice:)
77
+ Resources::TempMail.new(transport)
78
+ end
79
+
80
+ def verify_webhook_signature(payload:, headers:, secret:, tolerance_seconds: nil)
81
+ Webhook.verify(payload:, headers:, secret:, tolerance_seconds:)
82
+ end
83
+
84
+ def to_base64(bytes)
85
+ [RawBody.read(bytes)].pack("m0")
86
+ end
87
+
88
+ def api_key?(value)
89
+ Credentials.api_key?(value)
90
+ end
91
+
92
+ def access_token?(value)
93
+ Credentials.access_token?(value)
94
+ end
95
+
96
+ def sealed?(message)
97
+ encryption = message[:encryption] || message["encryption"]
98
+ return false unless encryption.is_a?(Hash)
99
+
100
+ Protocol::SEALED_ENCRYPTION_FORMATS.include?(encryption[:format] || encryption["format"])
101
+ end
102
+
103
+ def resolve_language(input)
104
+ Languages.resolve(input)
105
+ end
106
+
107
+ def language_by_code(code)
108
+ Languages.by_code(code)
109
+ end
110
+
111
+ def rtl_language?(code)
112
+ Languages.rtl?(code)
113
+ end
114
+
115
+ Client::NAMESPACES.each_key do |name|
116
+ define_method(name) { client.public_send(name) }
117
+ end
118
+
119
+ private
120
+
121
+ def from_environment(name)
122
+ value = ENV.fetch(name, nil)
123
+ (value.nil? || value.empty?) ? nil : value
124
+ end
125
+ end
126
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nextmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nextmail
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-10-25 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Send email and broadcasts, work with threads, drafts, labels, templates,
13
+ rules, webhooks, tracking, contacts, audiences, sign-up forms, domains, suppressions,
14
+ files, API keys, roles, members, mailbox imports and disposable inboxes from Ruby.
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/nextmail.rb
21
+ - lib/nextmail/api_paths.rb
22
+ - lib/nextmail/client.rb
23
+ - lib/nextmail/constants.rb
24
+ - lib/nextmail/credentials.rb
25
+ - lib/nextmail/decode.rb
26
+ - lib/nextmail/defaults.rb
27
+ - lib/nextmail/endpoint.rb
28
+ - lib/nextmail/errors.rb
29
+ - lib/nextmail/http.rb
30
+ - lib/nextmail/image_crop.rb
31
+ - lib/nextmail/languages.rb
32
+ - lib/nextmail/pagination.rb
33
+ - lib/nextmail/protocol.rb
34
+ - lib/nextmail/raw_body.rb
35
+ - lib/nextmail/request_path.rb
36
+ - lib/nextmail/resource.rb
37
+ - lib/nextmail/resources/account.rb
38
+ - lib/nextmail/resources/addresses.rb
39
+ - lib/nextmail/resources/analytics.rb
40
+ - lib/nextmail/resources/app_host.rb
41
+ - lib/nextmail/resources/audiences.rb
42
+ - lib/nextmail/resources/automations.rb
43
+ - lib/nextmail/resources/billing.rb
44
+ - lib/nextmail/resources/bookings.rb
45
+ - lib/nextmail/resources/branding.rb
46
+ - lib/nextmail/resources/broadcasts.rb
47
+ - lib/nextmail/resources/calendar.rb
48
+ - lib/nextmail/resources/chats.rb
49
+ - lib/nextmail/resources/connected_mailboxes.rb
50
+ - lib/nextmail/resources/connectors.rb
51
+ - lib/nextmail/resources/contacts.rb
52
+ - lib/nextmail/resources/dns_connections.rb
53
+ - lib/nextmail/resources/domains.rb
54
+ - lib/nextmail/resources/drafts.rb
55
+ - lib/nextmail/resources/emails.rb
56
+ - lib/nextmail/resources/encryption.rb
57
+ - lib/nextmail/resources/events.rb
58
+ - lib/nextmail/resources/exports.rb
59
+ - lib/nextmail/resources/files.rb
60
+ - lib/nextmail/resources/follow_ups.rb
61
+ - lib/nextmail/resources/forms.rb
62
+ - lib/nextmail/resources/imports.rb
63
+ - lib/nextmail/resources/keys.rb
64
+ - lib/nextmail/resources/knowledge.rb
65
+ - lib/nextmail/resources/labels.rb
66
+ - lib/nextmail/resources/languages.rb
67
+ - lib/nextmail/resources/me.rb
68
+ - lib/nextmail/resources/members.rb
69
+ - lib/nextmail/resources/out_of_office.rb
70
+ - lib/nextmail/resources/provider_imports.rb
71
+ - lib/nextmail/resources/roles.rb
72
+ - lib/nextmail/resources/rules.rb
73
+ - lib/nextmail/resources/security.rb
74
+ - lib/nextmail/resources/segments.rb
75
+ - lib/nextmail/resources/senders.rb
76
+ - lib/nextmail/resources/sending.rb
77
+ - lib/nextmail/resources/settings.rb
78
+ - lib/nextmail/resources/signatures.rb
79
+ - lib/nextmail/resources/subscriptions.rb
80
+ - lib/nextmail/resources/support.rb
81
+ - lib/nextmail/resources/suppressions.rb
82
+ - lib/nextmail/resources/tasks.rb
83
+ - lib/nextmail/resources/temp_mail.rb
84
+ - lib/nextmail/resources/templates.rb
85
+ - lib/nextmail/resources/threads.rb
86
+ - lib/nextmail/resources/tools.rb
87
+ - lib/nextmail/resources/tracking.rb
88
+ - lib/nextmail/resources/webhooks.rb
89
+ - lib/nextmail/resources/workspaces.rb
90
+ - lib/nextmail/results.rb
91
+ - lib/nextmail/transport.rb
92
+ - lib/nextmail/update_notice.rb
93
+ - lib/nextmail/version.rb
94
+ - lib/nextmail/webhook.rb
95
+ - lib/nextmail/wire.rb
96
+ homepage: https://nextmail.sh
97
+ licenses:
98
+ - Nonstandard
99
+ metadata:
100
+ homepage_uri: https://nextmail.sh
101
+ documentation_uri: https://nextmail.sh/docs/ruby
102
+ changelog_uri: https://nextmail.sh/docs/ruby/changelog
103
+ bug_tracker_uri: https://nextmail.sh/contact
104
+ rubygems_mfa_required: 'true'
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '3.2'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.6.3
120
+ specification_version: 4
121
+ summary: The official Ruby SDK for the Nextmail API.
122
+ test_files: []