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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +31 -0
  3. data/LICENSE +22 -0
  4. data/NOTICE +1 -0
  5. data/README.md +210 -0
  6. data/app/controllers/action_mailbox/ingresses/sendio/inbound_emails_controller.rb +95 -0
  7. data/lib/sendio/action_mailbox/engine.rb +19 -0
  8. data/lib/sendio/action_mailbox/message_builder.rb +162 -0
  9. data/lib/sendio/action_mailbox.rb +5 -0
  10. data/lib/sendio/api_keys.rb +32 -0
  11. data/lib/sendio/automations/runs.rb +22 -0
  12. data/lib/sendio/automations/templates.rb +29 -0
  13. data/lib/sendio/automations.rb +64 -0
  14. data/lib/sendio/batch.rb +36 -0
  15. data/lib/sendio/broadcasts.rb +180 -0
  16. data/lib/sendio/client.rb +19 -0
  17. data/lib/sendio/contact_properties.rb +106 -0
  18. data/lib/sendio/contacts/imports.rb +64 -0
  19. data/lib/sendio/contacts/segments.rb +66 -0
  20. data/lib/sendio/contacts/topics.rb +80 -0
  21. data/lib/sendio/contacts.rb +131 -0
  22. data/lib/sendio/domains.rb +60 -0
  23. data/lib/sendio/emails/attachments.rb +67 -0
  24. data/lib/sendio/emails/receiving/attachments.rb +69 -0
  25. data/lib/sendio/emails/receiving.rb +51 -0
  26. data/lib/sendio/emails.rb +124 -0
  27. data/lib/sendio/errors.rb +59 -0
  28. data/lib/sendio/events.rb +46 -0
  29. data/lib/sendio/logs.rb +20 -0
  30. data/lib/sendio/mailboxes.rb +87 -0
  31. data/lib/sendio/mailer.rb +241 -0
  32. data/lib/sendio/multipart_request.rb +67 -0
  33. data/lib/sendio/oauth_grants.rb +20 -0
  34. data/lib/sendio/pagination_helper.rb +30 -0
  35. data/lib/sendio/railtie.rb +14 -0
  36. data/lib/sendio/request.rb +122 -0
  37. data/lib/sendio/response.rb +154 -0
  38. data/lib/sendio/segments.rb +38 -0
  39. data/lib/sendio/suppressions/batch.rb +44 -0
  40. data/lib/sendio/suppressions.rb +64 -0
  41. data/lib/sendio/templates.rb +50 -0
  42. data/lib/sendio/topics.rb +38 -0
  43. data/lib/sendio/usage.rb +14 -0
  44. data/lib/sendio/version.rb +5 -0
  45. data/lib/sendio/webhooks.rb +329 -0
  46. data/lib/sendio.rb +78 -0
  47. metadata +119 -0
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ # Contacts api wrapper
5
+ module Contacts
6
+ class << self
7
+ # https://developer.send.io/docs/api
8
+ def create(params)
9
+ if params[:audience_id]
10
+ path = "audiences/#{params[:audience_id]}/contacts"
11
+ # Audience-scoped contacts don't support properties
12
+ payload = params.reject { |key, _| key == :properties }
13
+ else
14
+ path = "contacts"
15
+ payload = params
16
+ end
17
+ Sendio::Request.new(path, payload, "post").perform
18
+ end
19
+
20
+ #
21
+ # Retrieves a contact
22
+ #
23
+ # @param params [Hash] the parameters
24
+ # @option params [String] :id either the contact id or contact's email (required)
25
+ # @option params [String] :audience_id optional audience id to scope the operation
26
+ #
27
+ # @example Get contact by ID
28
+ # Sendio::Contacts.get(id: "contact_123")
29
+ #
30
+ # @example Get contact scoped to an audience
31
+ # Sendio::Contacts.get(id: "contact_123", audience_id: "aud_456")
32
+ #
33
+ # https://developer.send.io/docs/api
34
+ def get(params = {})
35
+ raise ArgumentError, "Missing `id` or `email` field" if params[:id].nil? && params[:email].nil?
36
+
37
+ audience_id = params[:audience_id]
38
+ contact_id = params[:id] || params[:email]
39
+ path = if audience_id
40
+ "audiences/#{audience_id}/contacts/#{contact_id}"
41
+ else
42
+ "contacts/#{contact_id}"
43
+ end
44
+ Sendio::Request.new(path, {}, "get").perform
45
+ end
46
+
47
+ #
48
+ # List contacts
49
+ #
50
+ # @param params [Hash] optional parameters including pagination
51
+ # @option params [String] :audience_id optional audience id to scope the operation
52
+ # @option params [Integer] :limit number of records to return
53
+ # @option params [String] :cursor pagination cursor
54
+ #
55
+ # @example List all contacts
56
+ # Sendio::Contacts.list
57
+ #
58
+ # @example List contacts with pagination
59
+ # Sendio::Contacts.list(limit: 10)
60
+ #
61
+ # @example List contacts scoped to a segment
62
+ # Sendio::Contacts.list(segment_id: "seg_456", limit: 10)
63
+ #
64
+ # @example List contacts scoped to an audience
65
+ # Sendio::Contacts.list(audience_id: "aud_456", limit: 10)
66
+ #
67
+ # https://developer.send.io/docs/api
68
+ def list(params = {})
69
+ path = if params[:audience_id]
70
+ audience_id = params[:audience_id]
71
+ Sendio::PaginationHelper.build_paginated_path("audiences/#{audience_id}/contacts",
72
+ params.except(:audience_id))
73
+ elsif params[:segment_id]
74
+ segment_id = params[:segment_id]
75
+ Sendio::PaginationHelper.build_paginated_path("segments/#{segment_id}/contacts",
76
+ params.except(:segment_id))
77
+ else
78
+ Sendio::PaginationHelper.build_paginated_path("contacts", params)
79
+ end
80
+ Sendio::Request.new(path, {}, "get").perform
81
+ end
82
+
83
+ #
84
+ # Remove a contact
85
+ #
86
+ # @param params [Hash] the parameters
87
+ # @option params [String] :id either the contact id or contact email (required)
88
+ # @option params [String] :audience_id optional audience id to scope the operation
89
+ #
90
+ # @example Remove contact by ID
91
+ # Sendio::Contacts.remove(id: "contact_123")
92
+ #
93
+ # @example Remove contact scoped to an audience
94
+ # Sendio::Contacts.remove(id: "contact_123", audience_id: "aud_456")
95
+ #
96
+ # https://developer.send.io/docs/api
97
+ def remove(params = {})
98
+ raise ArgumentError, "Missing `id` or `email` field" if params[:id].nil? && params[:email].nil?
99
+
100
+ audience_id = params[:audience_id]
101
+ contact_id = params[:id] || params[:email]
102
+ path = if audience_id
103
+ "audiences/#{audience_id}/contacts/#{contact_id}"
104
+ else
105
+ "contacts/#{contact_id}"
106
+ end
107
+ Sendio::Request.new(path, {}, "delete").perform
108
+ end
109
+
110
+ #
111
+ # Update a contact
112
+ #
113
+ # @param params [Hash] the contact params
114
+ # https://developer.send.io/docs/api
115
+ def update(params)
116
+ raise ArgumentError, "Missing `id` or `email` field" if params[:id].nil? && params[:email].nil?
117
+
118
+ contact_id = params[:id] || params[:email]
119
+ if params[:audience_id]
120
+ path = "audiences/#{params[:audience_id]}/contacts/#{contact_id}"
121
+ # Audience-scoped contacts don't support properties
122
+ payload = params.reject { |key, _| key == :properties }
123
+ else
124
+ path = "contacts/#{contact_id}"
125
+ payload = params
126
+ end
127
+ Sendio::Request.new(path, payload, "patch").perform
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ # domains api wrapper
5
+ module Domains
6
+ class << self
7
+ # https://developer.send.io/docs/api
8
+ #
9
+ # Pass +capabilities: { receiving: "enabled" }+ to also receive email on
10
+ # the domain (send.io then requires its MX record). Sending is always on:
11
+ # +capabilities: { sending: "disabled" }+ is rejected with a 422.
12
+ #
13
+ # @example
14
+ # Sendio::Domains.create({ name: "example.com", capabilities: { receiving: "enabled" } })
15
+ def create(params)
16
+ path = "domains"
17
+ Sendio::Request.new(path, params, "post").perform
18
+ end
19
+
20
+ # https://developer.send.io/docs/api
21
+ #
22
+ # +capabilities: { receiving: "disabled" }+ turns receiving off: send.io
23
+ # stops accepting email for the domain and no longer requires its MX
24
+ # record, so remove that record from your DNS. +capabilities: { receiving:
25
+ # "enabled" }+ turns it back on and asks for the domain's MX record
26
+ # (publish it to start receiving email). Sending can't be disabled.
27
+ #
28
+ # @example
29
+ # Sendio::Domains.update({ id: domain[:id], capabilities: { receiving: "disabled" } })
30
+ def update(params)
31
+ path = "domains/#{params[:id]}"
32
+ Sendio::Request.new(path, params, "patch").perform
33
+ end
34
+
35
+ # https://developer.send.io/docs/api
36
+ def get(domain_id = "")
37
+ path = "domains/#{domain_id}"
38
+ Sendio::Request.new(path, {}, "get").perform
39
+ end
40
+
41
+ # https://developer.send.io/docs/api
42
+ def list(params = {})
43
+ path = Sendio::PaginationHelper.build_paginated_path("domains", params)
44
+ Sendio::Request.new(path, {}, "get").perform
45
+ end
46
+
47
+ # https://developer.send.io/docs/api
48
+ def remove(domain_id = "")
49
+ path = "domains/#{domain_id}"
50
+ Sendio::Request.new(path, {}, "delete").perform
51
+ end
52
+
53
+ # https://developer.send.io/docs/api
54
+ def verify(domain_id = "")
55
+ path = "domains/#{domain_id}/verify"
56
+ Sendio::Request.new(path, {}, "post").perform
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ module Emails
5
+ # Module for sent email attachments API operations
6
+ module Attachments
7
+ class << self
8
+ # Retrieve a single attachment from a sent email
9
+ #
10
+ # @param params [Hash] Parameters for retrieving the attachment
11
+ # @option params [String] :id The attachment ID (required)
12
+ # @option params [String] :email_id The email ID (required)
13
+ # @return [Hash] The attachment object
14
+ #
15
+ # @example
16
+ # Sendio::Emails::Attachments.get(
17
+ # id: "2a0c9ce0-3112-4728-976e-47ddcd16a318",
18
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
19
+ # )
20
+ def get(params = {})
21
+ attachment_id = params[:id]
22
+ email_id = params[:email_id]
23
+
24
+ path = "emails/#{email_id}/attachments/#{attachment_id}"
25
+ Sendio::Request.new(path, {}, "get").perform
26
+ end
27
+
28
+ # List attachments from a sent email with optional pagination
29
+ #
30
+ # @param params [Hash] Parameters for listing attachments
31
+ # @option params [String] :email_id The email ID (required)
32
+ # @option params [Integer] :limit Maximum number of attachments to return (1-100)
33
+ # @option params [String] :after Cursor for pagination (newer attachments)
34
+ # @option params [String] :before Cursor for pagination (older attachments)
35
+ # @return [Hash] List of attachments with pagination info
36
+ #
37
+ # @example List all attachments
38
+ # Sendio::Emails::Attachments.list(
39
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
40
+ # )
41
+ #
42
+ # @example List with custom limit
43
+ # Sendio::Emails::Attachments.list(
44
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
45
+ # limit: 50
46
+ # )
47
+ #
48
+ # @example List with pagination
49
+ # Sendio::Emails::Attachments.list(
50
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
51
+ # limit: 20,
52
+ # after: "attachment_id_123"
53
+ # )
54
+ def list(params = {})
55
+ email_id = params[:email_id]
56
+ base_path = "emails/#{email_id}/attachments"
57
+
58
+ # Extract pagination parameters
59
+ pagination_params = params.slice(:limit, :after, :before)
60
+
61
+ path = Sendio::PaginationHelper.build_paginated_path(base_path, pagination_params)
62
+ Sendio::Request.new(path, {}, "get").perform
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ module Emails
5
+ module Receiving
6
+ # Module for received email attachments API operations
7
+ module Attachments
8
+ class << self
9
+ # Retrieve a single attachment from a received email
10
+ #
11
+ # @param params [Hash] Parameters for retrieving the attachment
12
+ # @option params [String] :id The attachment ID (required)
13
+ # @option params [String] :email_id The email ID (required)
14
+ # @return [Hash] The attachment object
15
+ #
16
+ # @example
17
+ # Sendio::Emails::Receiving::Attachments.get(
18
+ # id: "2a0c9ce0-3112-4728-976e-47ddcd16a318",
19
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
20
+ # )
21
+ def get(params = {})
22
+ attachment_id = params[:id]
23
+ email_id = params[:email_id]
24
+
25
+ path = "emails/receiving/#{email_id}/attachments/#{attachment_id}"
26
+ Sendio::Request.new(path, {}, "get").perform
27
+ end
28
+
29
+ # List attachments from a received email with optional pagination
30
+ #
31
+ # @param params [Hash] Parameters for listing attachments
32
+ # @option params [String] :email_id The email ID (required)
33
+ # @option params [Integer] :limit Maximum number of attachments to return (1-100)
34
+ # @option params [String] :after Cursor for pagination (newer attachments)
35
+ # @option params [String] :before Cursor for pagination (older attachments)
36
+ # @return [Hash] List of attachments with pagination info
37
+ #
38
+ # @example List all attachments
39
+ # Sendio::Emails::Receiving::Attachments.list(
40
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
41
+ # )
42
+ #
43
+ # @example List with custom limit
44
+ # Sendio::Emails::Receiving::Attachments.list(
45
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
46
+ # limit: 50
47
+ # )
48
+ #
49
+ # @example List with pagination
50
+ # Sendio::Emails::Receiving::Attachments.list(
51
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
52
+ # limit: 20,
53
+ # after: "attachment_id_123"
54
+ # )
55
+ def list(params = {})
56
+ email_id = params[:email_id]
57
+ base_path = "emails/receiving/#{email_id}/attachments"
58
+
59
+ # Extract pagination parameters
60
+ pagination_params = params.slice(:limit, :after, :before)
61
+
62
+ path = Sendio::PaginationHelper.build_paginated_path(base_path, pagination_params)
63
+ Sendio::Request.new(path, {}, "get").perform
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ module Emails
5
+ # Module for receiving emails API operations
6
+ module Receiving
7
+ class << self
8
+ # Retrieve a single received email
9
+ #
10
+ # @param email_id [String] The ID of the received email
11
+ # @param params [Hash] Optional query parameters
12
+ # @option params [String] :html_format Format of the HTML content (e.g., "sanitized", "raw")
13
+ # @return [Hash] The received email object
14
+ #
15
+ # @example
16
+ # Sendio::Emails::Receiving.get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c")
17
+ #
18
+ # @example With html_format
19
+ # Sendio::Emails::Receiving.get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c", html_format: "sanitized")
20
+ def get(email_id = "", params = {})
21
+ path = "emails/receiving/#{email_id}"
22
+
23
+ path += "?html_format=#{CGI.escape(params[:html_format].to_s)}" if params[:html_format]
24
+
25
+ Sendio::Request.new(path, {}, "get").perform
26
+ end
27
+
28
+ # List received emails with optional pagination
29
+ #
30
+ # @param params [Hash] Optional parameters for pagination
31
+ # @option params [Integer] :limit Maximum number of emails to return (1-100)
32
+ # @option params [String] :after Cursor for pagination (newer emails)
33
+ # @option params [String] :before Cursor for pagination (older emails)
34
+ # @return [Hash] List of received emails with pagination info
35
+ #
36
+ # @example List all received emails
37
+ # Sendio::Emails::Receiving.list
38
+ #
39
+ # @example List with custom limit
40
+ # Sendio::Emails::Receiving.list(limit: 50)
41
+ #
42
+ # @example List with pagination
43
+ # Sendio::Emails::Receiving.list(limit: 20, after: "email_id_123")
44
+ def list(params = {})
45
+ path = Sendio::PaginationHelper.build_paginated_path("emails/receiving", params)
46
+ Sendio::Request.new(path, {}, "get").perform
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ # Module responsible for wrapping email sending API
5
+ module Emails
6
+ class << self
7
+ # Sends or schedules an email.
8
+ # see more: https://developer.send.io/docs/api
9
+ def send(params, options: {})
10
+ path = "emails"
11
+ Sendio::Request.new(path, params, "post", options: options).perform
12
+ end
13
+
14
+ # Retrieve a single email.
15
+ # see more: https://developer.send.io/docs/api
16
+ def get(email_id = "")
17
+ path = "emails/#{email_id}"
18
+ Sendio::Request.new(path, {}, "get").perform
19
+ end
20
+
21
+ # Update a scheduled email.
22
+ # see more: https://developer.send.io/docs/api
23
+ def update(params)
24
+ path = "emails/#{params[:email_id]}"
25
+ Sendio::Request.new(path, params, "patch").perform
26
+ end
27
+
28
+ # Cancel a scheduled email.
29
+ # see more: https://developer.send.io/docs/api
30
+ def cancel(email_id = "")
31
+ path = "emails/#{email_id}/cancel"
32
+ Sendio::Request.new(path, {}, "post").perform
33
+ end
34
+
35
+ # Create a shareable link for a sent or received email.
36
+ #
37
+ # @param email_id [String] The email id (sent or received).
38
+ # @param params [Hash] Optional parameters
39
+ # @option params [String] :expires_in Human-readable duration (e.g. "10m", "2 hours",
40
+ # "1 day"). Defaults to "48h" and is capped at 48 hours.
41
+ def share(email_id, params = {})
42
+ path = "emails/#{email_id}/share"
43
+ Sendio::Request.new(path, params, "post").perform
44
+ end
45
+
46
+ # List emails with optional pagination.
47
+ # see more: https://developer.send.io/docs/api
48
+ #
49
+ # @param options [Hash] Optional parameters for pagination
50
+ # @option options [Integer] :limit Maximum number of emails to return (1-100, default 20)
51
+ # @option options [String] :after Cursor for pagination (newer emails)
52
+ # @option options [String] :before Cursor for pagination (older emails)
53
+ def list(options = {})
54
+ path = "emails"
55
+
56
+ # Build query parameters, filtering out nil values
57
+ query_params = {}
58
+ query_params[:limit] = options[:limit] if options[:limit]
59
+ query_params[:after] = options[:after] if options[:after]
60
+ query_params[:before] = options[:before] if options[:before]
61
+
62
+ Sendio::Request.new(path, query_params, "get").perform
63
+ end
64
+
65
+ # Retrieve email metrics.
66
+ # see more: https://developer.send.io/docs/api
67
+ #
68
+ # @param options [Hash] Optional parameters for filtering and shaping the metrics response
69
+ # @option options [String] :start_date ISO 8601 date/datetime. Defaults to 6 days before :end_date
70
+ # @option options [String] :end_date ISO 8601 date/datetime. Defaults to now
71
+ # @option options [String] :timezone IANA timezone, e.g. "America/New_York". Defaults to "UTC"
72
+ # @option options [String] :granularity Bucket size used when :period is in :dimensions.
73
+ # One of "hourly", "daily", "weekly", "monthly". Defaults to "daily"
74
+ # @option options [Array<String>] :metrics Metrics to include. Defaults to all metrics.
75
+ # @option options [Array<String>] :dimensions Dimensions to break down by: "period", "domain",
76
+ # "email", "broadcast". Defaults to none, which returns totals only.
77
+ # @option options [Array<String>] :domain_id Restrict to these sending domain IDs (max 100)
78
+ # @option options [Array<String>] :email_id Restrict to these email IDs (max 100)
79
+ # @option options [Array<String>] :broadcast_id Restrict to these broadcast IDs (max 100)
80
+ def metrics(options = {})
81
+ path = "emails/metrics"
82
+ validate_metrics_options(options)
83
+ Sendio::Request.new(path, build_metrics_query(options), "get").perform
84
+ end
85
+
86
+ private
87
+
88
+ # The `email` and `broadcast` dimensions/filters are mutually exclusive.
89
+ def validate_metrics_options(options)
90
+ dimensions = Array(options[:dimensions])
91
+ has_broadcast = dimensions.include?("broadcast") || !Array(options[:broadcast_id]).empty?
92
+ has_email = dimensions.include?("email") || !Array(options[:email_id]).empty?
93
+
94
+ return unless has_broadcast && has_email
95
+
96
+ raise ArgumentError,
97
+ "`broadcast`/`broadcast_id` cannot be combined with `email`/`email_id`"
98
+ end
99
+
100
+ # Builds the metrics query hash, filtering out nil values and joining
101
+ # list-style params (metrics, dimensions, domain_id, email_id, broadcast_id)
102
+ # into comma-separated strings as expected by the API.
103
+ def build_metrics_query(options)
104
+ query_params = {}
105
+
106
+ %i[start_date end_date timezone granularity].each do |key|
107
+ value = options[key]
108
+ query_params[key] = value unless blank?(value)
109
+ end
110
+
111
+ %i[metrics dimensions domain_id email_id broadcast_id].each do |key|
112
+ values = Array(options[key]).reject { |value| blank?(value) }
113
+ query_params[key] = values.join(",") unless values.empty?
114
+ end
115
+
116
+ query_params
117
+ end
118
+
119
+ def blank?(value)
120
+ value.nil? || value.to_s.empty?
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ # Errors wrapper class
5
+ # For more info: https://developer.send.io/docs/api
6
+ class Error < StandardError
7
+ # 4xx HTTP status code
8
+ ClientError = Class.new(self)
9
+
10
+ # 5xx HTTP status code
11
+ ServerError = Class.new(self)
12
+
13
+ # code 500
14
+ InternalServerError = Class.new(ServerError)
15
+
16
+ # code 422
17
+ InvalidRequestError = Class.new(ServerError)
18
+
19
+ # code 429
20
+ class RateLimitExceededError < ServerError
21
+ attr_reader :rate_limit_limit, :rate_limit_remaining, :rate_limit_reset, :retry_after
22
+
23
+ def initialize(msg, code = nil, headers = {})
24
+ super(msg, code, headers)
25
+ @rate_limit_limit = headers["ratelimit-limit"]&.to_i
26
+ @rate_limit_remaining = headers["ratelimit-remaining"]&.to_i
27
+ @rate_limit_reset = headers["ratelimit-reset"]&.to_i
28
+ @retry_after = headers["retry-after"]&.to_i
29
+ end
30
+ end
31
+
32
+ # code 404
33
+ NotFoundError = Class.new(ServerError)
34
+
35
+ # code 402 insufficient_credits: the credit balance does not cover the
36
+ # send, and nothing was sent. 429 also covers the quota names
37
+ # daily_quota_exceeded, monthly_quota_exceeded,
38
+ # subaccount_daily_quota_exceeded and subaccount_monthly_quota_exceeded.
39
+ InsufficientCreditsError = Class.new(ClientError)
40
+
41
+ ERRORS = {
42
+ 401 => Sendio::Error::InvalidRequestError,
43
+ 402 => Sendio::Error::InsufficientCreditsError,
44
+ 404 => Sendio::Error::NotFoundError,
45
+ 422 => Sendio::Error::InvalidRequestError,
46
+ 429 => Sendio::Error::RateLimitExceededError,
47
+ 400 => Sendio::Error::InvalidRequestError,
48
+ 500 => Sendio::Error::InternalServerError
49
+ }.freeze
50
+
51
+ attr_reader :headers
52
+
53
+ def initialize(msg, code = nil, headers = {})
54
+ super(msg)
55
+ @code = code
56
+ @headers = headers
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ # events api wrapper
5
+ module Events
6
+ class << self
7
+ # https://developer.send.io/docs/api
8
+ def create(params = {})
9
+ Sendio::Request.new("events", params, "post").perform
10
+ end
11
+
12
+ # https://developer.send.io/docs/api
13
+ # identifier can be a UUID or an event name (e.g. "user.signed_up")
14
+ def get(identifier = "")
15
+ path = "events/#{CGI.escape(identifier.to_s)}"
16
+ Sendio::Request.new(path, {}, "get").perform
17
+ end
18
+
19
+ # https://developer.send.io/docs/api
20
+ def update(params = {})
21
+ identifier = params[:identifier]
22
+ path = "events/#{CGI.escape(identifier.to_s)}"
23
+ payload = params.reject { |k, _| k == :identifier }
24
+ Sendio::Request.new(path, payload, "patch").perform
25
+ end
26
+
27
+ # https://developer.send.io/docs/api
28
+ # identifier can be a UUID or an event name (e.g. "user.signed_up")
29
+ def remove(identifier = "")
30
+ path = "events/#{CGI.escape(identifier.to_s)}"
31
+ Sendio::Request.new(path, {}, "delete").perform
32
+ end
33
+
34
+ # https://developer.send.io/docs/api
35
+ def send(params = {})
36
+ Sendio::Request.new("events/send", params, "post").perform
37
+ end
38
+
39
+ # https://developer.send.io/docs/api
40
+ def list(params = {})
41
+ path = Sendio::PaginationHelper.build_paginated_path("events", params)
42
+ Sendio::Request.new(path, {}, "get").perform
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendio
4
+ # logs api wrapper
5
+ module Logs
6
+ class << self
7
+ # https://developer.send.io/docs/api
8
+ def get(log_id = "")
9
+ path = "logs/#{log_id}"
10
+ Sendio::Request.new(path, {}, "get").perform
11
+ end
12
+
13
+ # https://developer.send.io/docs/api
14
+ def list(params = {})
15
+ path = Sendio::PaginationHelper.build_paginated_path("logs", params)
16
+ Sendio::Request.new(path, {}, "get").perform
17
+ end
18
+ end
19
+ end
20
+ end