sendio 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +31 -0
- data/LICENSE +22 -0
- data/NOTICE +1 -0
- data/README.md +210 -0
- data/app/controllers/action_mailbox/ingresses/sendio/inbound_emails_controller.rb +95 -0
- data/lib/sendio/action_mailbox/engine.rb +19 -0
- data/lib/sendio/action_mailbox/message_builder.rb +162 -0
- data/lib/sendio/action_mailbox.rb +5 -0
- data/lib/sendio/api_keys.rb +32 -0
- data/lib/sendio/automations/runs.rb +22 -0
- data/lib/sendio/automations/templates.rb +29 -0
- data/lib/sendio/automations.rb +64 -0
- data/lib/sendio/batch.rb +36 -0
- data/lib/sendio/broadcasts.rb +180 -0
- data/lib/sendio/client.rb +19 -0
- data/lib/sendio/contact_properties.rb +106 -0
- data/lib/sendio/contacts/imports.rb +64 -0
- data/lib/sendio/contacts/segments.rb +66 -0
- data/lib/sendio/contacts/topics.rb +80 -0
- data/lib/sendio/contacts.rb +131 -0
- data/lib/sendio/domains.rb +60 -0
- data/lib/sendio/emails/attachments.rb +67 -0
- data/lib/sendio/emails/receiving/attachments.rb +69 -0
- data/lib/sendio/emails/receiving.rb +51 -0
- data/lib/sendio/emails.rb +124 -0
- data/lib/sendio/errors.rb +59 -0
- data/lib/sendio/events.rb +46 -0
- data/lib/sendio/logs.rb +20 -0
- data/lib/sendio/mailboxes.rb +87 -0
- data/lib/sendio/mailer.rb +241 -0
- data/lib/sendio/multipart_request.rb +67 -0
- data/lib/sendio/oauth_grants.rb +20 -0
- data/lib/sendio/pagination_helper.rb +30 -0
- data/lib/sendio/railtie.rb +14 -0
- data/lib/sendio/request.rb +122 -0
- data/lib/sendio/response.rb +154 -0
- data/lib/sendio/segments.rb +38 -0
- data/lib/sendio/suppressions/batch.rb +44 -0
- data/lib/sendio/suppressions.rb +64 -0
- data/lib/sendio/templates.rb +50 -0
- data/lib/sendio/topics.rb +38 -0
- data/lib/sendio/usage.rb +14 -0
- data/lib/sendio/version.rb +5 -0
- data/lib/sendio/webhooks.rb +329 -0
- data/lib/sendio.rb +78 -0
- metadata +119 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sendio
|
|
4
|
+
# Response wrapper that maintains backwards compatibility while exposing headers
|
|
5
|
+
#
|
|
6
|
+
# This class wraps API responses and behaves like a Hash for backwards compatibility,
|
|
7
|
+
# while also providing access to response headers via the #headers method.
|
|
8
|
+
#
|
|
9
|
+
# @example Backwards compatible hash access
|
|
10
|
+
# response = Sendio::Emails.send(params)
|
|
11
|
+
# response[:id] # => "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
|
|
12
|
+
#
|
|
13
|
+
# @example Accessing response headers
|
|
14
|
+
# response = Sendio::Emails.send(params)
|
|
15
|
+
# response.headers # => {"content-type" => "application/json", ...}
|
|
16
|
+
# response.headers['x-ratelimit-remaining'] # => "50"
|
|
17
|
+
class Response
|
|
18
|
+
include Enumerable
|
|
19
|
+
|
|
20
|
+
# @param data [Hash] The response data
|
|
21
|
+
# @param headers [Hash, HTTParty::Response] The response headers
|
|
22
|
+
def initialize(data, headers)
|
|
23
|
+
@data = data.is_a?(Hash) ? data : {}
|
|
24
|
+
@headers = normalize_headers(headers)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Access response headers
|
|
28
|
+
# @return [Hash] Response headers as a hash with lowercase string keys
|
|
29
|
+
attr_reader :headers
|
|
30
|
+
|
|
31
|
+
# Hash-like access via []
|
|
32
|
+
# @param key [Symbol, String] The key to access
|
|
33
|
+
# @return [Object] The value at the key
|
|
34
|
+
def [](key)
|
|
35
|
+
@data[key]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Hash-like assignment via []=
|
|
39
|
+
# @param key [Symbol, String] The key to set
|
|
40
|
+
# @param value [Object] The value to set
|
|
41
|
+
def []=(key, value)
|
|
42
|
+
@data[key] = value
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Dig into nested hash structure
|
|
46
|
+
# @param keys [Array<Symbol, String>] Keys to dig through
|
|
47
|
+
# @return [Object] The value at the nested key path
|
|
48
|
+
def dig(*keys)
|
|
49
|
+
@data.dig(*keys)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Convert to plain hash
|
|
53
|
+
# @return [Hash] The underlying data hash
|
|
54
|
+
def to_h
|
|
55
|
+
@data
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
alias to_hash to_h
|
|
59
|
+
|
|
60
|
+
# Serialize response data without response headers
|
|
61
|
+
# @return [String] JSON representation of the response data
|
|
62
|
+
def to_json(*args)
|
|
63
|
+
@data.to_json(*args)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Serialize response data for encoders that call as_json, such as ActiveSupport
|
|
67
|
+
# @param args [Array] Options forwarded to Hash#as_json when it is defined
|
|
68
|
+
# @return [Hash] The response data in as_json form
|
|
69
|
+
def as_json(*args)
|
|
70
|
+
@data.respond_to?(:as_json) ? @data.as_json(*args) : @data
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Get all keys from the data
|
|
74
|
+
# @return [Array] Array of keys
|
|
75
|
+
def keys
|
|
76
|
+
@data.keys
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Get all values from the data
|
|
80
|
+
# @return [Array] Array of values
|
|
81
|
+
def values
|
|
82
|
+
@data.values
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Check if key exists
|
|
86
|
+
# @param key [Symbol, String] The key to check
|
|
87
|
+
# @return [Boolean] True if key exists
|
|
88
|
+
def key?(key)
|
|
89
|
+
@data.key?(key)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
alias has_key? key?
|
|
93
|
+
|
|
94
|
+
# Enable enumeration over the data
|
|
95
|
+
def each(&block)
|
|
96
|
+
@data.each(&block)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Transform keys in the underlying data
|
|
100
|
+
# @return [Sendio::Response] Self for chaining
|
|
101
|
+
def transform_keys!(&block)
|
|
102
|
+
@data.transform_keys!(&block)
|
|
103
|
+
self
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Check if response is empty
|
|
107
|
+
# @return [Boolean] True if data is empty
|
|
108
|
+
def empty?
|
|
109
|
+
@data.empty?
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Respond to hash-like methods
|
|
113
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
114
|
+
@data.respond_to?(method_name) || super
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Delegate unknown methods to the underlying data hash
|
|
118
|
+
def method_missing(method_name, *args, &block)
|
|
119
|
+
if @data.respond_to?(method_name)
|
|
120
|
+
result = @data.send(method_name, *args, &block)
|
|
121
|
+
# If the method returns the hash itself, return self to maintain wrapper
|
|
122
|
+
result.equal?(@data) ? self : result
|
|
123
|
+
else
|
|
124
|
+
super
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# String representation for debugging
|
|
129
|
+
# @return [String] String representation of the response
|
|
130
|
+
def inspect
|
|
131
|
+
"#<Sendio::Response data=#{@data.inspect} headers=#{@headers.keys.inspect}>"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
# Normalize headers to a simple hash with lowercase string keys
|
|
137
|
+
# @param headers [Hash, HTTParty::Response, nil] The headers to normalize
|
|
138
|
+
# @return [Hash] Normalized headers hash
|
|
139
|
+
def normalize_headers(headers)
|
|
140
|
+
return {} if headers.nil?
|
|
141
|
+
|
|
142
|
+
# Handle HTTParty::Response object
|
|
143
|
+
headers = headers.headers if headers.respond_to?(:headers)
|
|
144
|
+
|
|
145
|
+
# Convert to hash and normalize keys to lowercase strings
|
|
146
|
+
case headers
|
|
147
|
+
when Hash
|
|
148
|
+
headers.to_h.transform_keys { |k| k.to_s.downcase }
|
|
149
|
+
else
|
|
150
|
+
{}
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sendio
|
|
4
|
+
# Segments api wrapper
|
|
5
|
+
module Segments
|
|
6
|
+
class << self
|
|
7
|
+
# https://developer.send.io/docs/api
|
|
8
|
+
def create(params)
|
|
9
|
+
path = "segments"
|
|
10
|
+
Sendio::Request.new(path, params, "post").perform
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# https://developer.send.io/docs/api
|
|
14
|
+
def get(segment_id = "")
|
|
15
|
+
path = "segments/#{segment_id}"
|
|
16
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# https://developer.send.io/docs/api
|
|
20
|
+
def update(params = {})
|
|
21
|
+
path = "segments/#{params[:segment_id]}"
|
|
22
|
+
Sendio::Request.new(path, { name: params[:name] }, "patch").perform
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# https://developer.send.io/docs/api
|
|
26
|
+
def list(params = {})
|
|
27
|
+
path = Sendio::PaginationHelper.build_paginated_path("segments", params)
|
|
28
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# https://developer.send.io/docs/api
|
|
32
|
+
def remove(segment_id = "")
|
|
33
|
+
path = "segments/#{segment_id}"
|
|
34
|
+
Sendio::Request.new(path, {}, "delete").perform
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sendio
|
|
4
|
+
module Suppressions
|
|
5
|
+
# Suppressions Batch API wrapper
|
|
6
|
+
module Batch
|
|
7
|
+
class << self
|
|
8
|
+
#
|
|
9
|
+
# Add up to 100 email addresses to the suppression list at once. Addresses that
|
|
10
|
+
# are already suppressed come back with their existing suppression instead of failing.
|
|
11
|
+
#
|
|
12
|
+
# @param params [Hash] the parameters
|
|
13
|
+
# @option params [Array<String>] :emails the email addresses to suppress (required, 1 to 100).
|
|
14
|
+
# The API lowercases and trims them.
|
|
15
|
+
#
|
|
16
|
+
# https://developer.send.io/docs/api
|
|
17
|
+
def add(params)
|
|
18
|
+
Sendio::Request.new("suppressions/batch/add", params, "post").perform
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Remove up to 100 suppressions at once, either by email address or by
|
|
23
|
+
# suppression ID. Provide exactly one of `emails` or `ids`.
|
|
24
|
+
#
|
|
25
|
+
# @param params [Hash] the parameters
|
|
26
|
+
# @option params [Array<String>] :emails the email addresses to remove (1 to 100)
|
|
27
|
+
# @option params [Array<String>] :ids the suppression IDs to remove (1 to 100), as UUIDs
|
|
28
|
+
#
|
|
29
|
+
# https://developer.send.io/docs/api
|
|
30
|
+
def remove(params)
|
|
31
|
+
normalized = params.transform_keys(&:to_sym)
|
|
32
|
+
emails = normalized[:emails]
|
|
33
|
+
ids = normalized[:ids]
|
|
34
|
+
raise ArgumentError, "Missing required `emails` or `ids` field" if emails.nil? && ids.nil?
|
|
35
|
+
raise ArgumentError, "Provide either `emails` or `ids`, but not both" if !emails.nil? && !ids.nil?
|
|
36
|
+
|
|
37
|
+
# The API rejects a null `emails`/`ids`, so the unused key is omitted rather than sent as nil.
|
|
38
|
+
body = emails.nil? ? { ids: ids } : { emails: emails }
|
|
39
|
+
Sendio::Request.new("suppressions/batch/remove", body, "post").perform
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sendio
|
|
4
|
+
# Suppressions API wrapper
|
|
5
|
+
module Suppressions
|
|
6
|
+
class << self
|
|
7
|
+
#
|
|
8
|
+
# Add an email address to the suppression list. Suppressed addresses are
|
|
9
|
+
# skipped by future sends. Adding an address that is already suppressed
|
|
10
|
+
# succeeds and returns the existing suppression.
|
|
11
|
+
#
|
|
12
|
+
# @param params [Hash] the parameters
|
|
13
|
+
# @option params [String] :email the email address to suppress (required).
|
|
14
|
+
# The API lowercases and trims it.
|
|
15
|
+
#
|
|
16
|
+
# https://developer.send.io/docs/api
|
|
17
|
+
def add(params)
|
|
18
|
+
Sendio::Request.new("suppressions", params, "post").perform
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Retrieve a list of suppressions. Each entry has `id`, `email`, `origin`,
|
|
23
|
+
# `source_id` and `created_at`; unlike `get`, list entries carry no `object` key.
|
|
24
|
+
#
|
|
25
|
+
# @param params [Hash] optional filtering and pagination parameters
|
|
26
|
+
# @option params [String] :origin filter by origin: 'bounce', 'complaint' or 'manual'
|
|
27
|
+
# @option params [Integer] :limit number of results to return (1-100)
|
|
28
|
+
# @option params [String] :after cursor for forward pagination
|
|
29
|
+
# @option params [String] :before cursor for backward pagination
|
|
30
|
+
#
|
|
31
|
+
# https://developer.send.io/docs/api
|
|
32
|
+
def list(params = {})
|
|
33
|
+
path = Sendio::PaginationHelper.build_paginated_path("suppressions", params)
|
|
34
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Retrieve a single suppression. The API returns 404 'Suppression not found'
|
|
39
|
+
# when the address or ID is not suppressed.
|
|
40
|
+
#
|
|
41
|
+
# @param id_or_email [String] the suppression ID or the suppressed email address (required)
|
|
42
|
+
#
|
|
43
|
+
# https://developer.send.io/docs/api
|
|
44
|
+
def get(id_or_email)
|
|
45
|
+
raise ArgumentError, "Missing required `id_or_email` field" if id_or_email.nil? || id_or_email.empty?
|
|
46
|
+
|
|
47
|
+
Sendio::Request.new("suppressions/#{ERB::Util.url_encode(id_or_email)}", {}, "get").perform
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# Remove a single suppression, which allows sending to that address again.
|
|
52
|
+
# The API returns 404 'Suppression not found' when the address or ID is not suppressed.
|
|
53
|
+
#
|
|
54
|
+
# @param id_or_email [String] the suppression ID or the suppressed email address (required)
|
|
55
|
+
#
|
|
56
|
+
# https://developer.send.io/docs/api
|
|
57
|
+
def remove(id_or_email)
|
|
58
|
+
raise ArgumentError, "Missing required `id_or_email` field" if id_or_email.nil? || id_or_email.empty?
|
|
59
|
+
|
|
60
|
+
Sendio::Request.new("suppressions/#{ERB::Util.url_encode(id_or_email)}", {}, "delete").perform
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sendio
|
|
4
|
+
# Templates api wrapper
|
|
5
|
+
module Templates
|
|
6
|
+
class << self
|
|
7
|
+
# https://developer.send.io/docs/api
|
|
8
|
+
def create(params = {})
|
|
9
|
+
path = "templates"
|
|
10
|
+
Sendio::Request.new(path, params, "post").perform
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# https://developer.send.io/docs/api
|
|
14
|
+
def get(template_id = "")
|
|
15
|
+
path = "templates/#{template_id}"
|
|
16
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# https://developer.send.io/docs/api
|
|
20
|
+
def update(template_id, params = {})
|
|
21
|
+
path = "templates/#{template_id}"
|
|
22
|
+
Sendio::Request.new(path, params, "patch").perform
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# https://developer.send.io/docs/api
|
|
26
|
+
def publish(template_id = "")
|
|
27
|
+
path = "templates/#{template_id}/publish"
|
|
28
|
+
Sendio::Request.new(path, {}, "post").perform
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# https://developer.send.io/docs/api
|
|
32
|
+
def duplicate(template_id = "")
|
|
33
|
+
path = "templates/#{template_id}/duplicate"
|
|
34
|
+
Sendio::Request.new(path, {}, "post").perform
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# https://developer.send.io/docs/api
|
|
38
|
+
def list(params = {})
|
|
39
|
+
path = Sendio::PaginationHelper.build_paginated_path("templates", params)
|
|
40
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# https://developer.send.io/docs/api
|
|
44
|
+
def remove(template_id = "")
|
|
45
|
+
path = "templates/#{template_id}"
|
|
46
|
+
Sendio::Request.new(path, {}, "delete").perform
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sendio
|
|
4
|
+
# Topics api wrapper
|
|
5
|
+
module Topics
|
|
6
|
+
class << self
|
|
7
|
+
# https://developer.send.io/docs/api
|
|
8
|
+
def create(params = {})
|
|
9
|
+
path = "topics"
|
|
10
|
+
Sendio::Request.new(path, params, "post").perform
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# https://developer.send.io/docs/api
|
|
14
|
+
def get(topic_id = "")
|
|
15
|
+
path = "topics/#{topic_id}"
|
|
16
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# https://developer.send.io/docs/api
|
|
20
|
+
def update(params = {})
|
|
21
|
+
path = "topics/#{params[:topic_id]}"
|
|
22
|
+
Sendio::Request.new(path, params, "patch").perform
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# https://developer.send.io/docs/api
|
|
26
|
+
def list(params = {})
|
|
27
|
+
path = Sendio::PaginationHelper.build_paginated_path("topics", params)
|
|
28
|
+
Sendio::Request.new(path, {}, "get").perform
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# https://developer.send.io/docs/api
|
|
32
|
+
def remove(topic_id = "")
|
|
33
|
+
path = "topics/#{topic_id}"
|
|
34
|
+
Sendio::Request.new(path, {}, "delete").perform
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/sendio/usage.rb
ADDED