resend 1.10.0 → 1.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f371f1dad3f54dd4be3d53a1a242749f451a2052b87faf8c062a29b001fa9d40
4
- data.tar.gz: 5acf401dbb4d342126629e4e7f13744cd9569ec4cb872a1e14822f5c1d207ab7
3
+ metadata.gz: 64e11672300db0ff3bdc430fada0fbd8ca115a07d2bfbbd761ea95dacf1e5c80
4
+ data.tar.gz: 02d393546fb4316ae1f9a6da5682e7d7b71aaad6b36a1bf29a84e4ef1996336e
5
5
  SHA512:
6
- metadata.gz: 65c023232e15a0a64fe731ab6a5691d29972bc3b2e57a2f25b5ccdfe94d7c92ef80da1d8acb06a1cd9ddb23338767b07c960cb099d74990f46a9f0c8a3e8314d
7
- data.tar.gz: 88301451135d13c9944062cb08e5b2a59e76e933cdc01cdcabbfc8c944f9cce70fa88eb7fd238cd59f799fd4f22d0b0cfd1bf9e0bc785d5cd03b363dff6177fe
6
+ metadata.gz: 714868b613882c10b8990bef7a06dcd132e5d29dbda076f84d13f5c69ffe60fed0518d694e67e5a7ce46bc9a4fe84352a418dfc8711020d04a307764bd3130de
7
+ data.tar.gz: 9465a51da2439c78eedaad4bf9ad5e411e6a1068fb5c28d8829c9f8a4fadeab23c7c4da5f3fc40af48b58c457eefe403cb57533ad79c0dbe2f3b0bf4f2837a60
@@ -41,6 +41,12 @@ module Resend
41
41
  Resend::Request.new(path, {}, "get").perform
42
42
  end
43
43
 
44
+ # https://resend.com/docs/api-reference/broadcasts/list-broadcast-clicked-links
45
+ def clicked_links(broadcast_id = "", params = {})
46
+ path = Resend::PaginationHelper.build_paginated_path("broadcasts/#{broadcast_id}/clicked-links", params)
47
+ Resend::Request.new(path, {}, "get").perform
48
+ end
49
+
44
50
  def cancel(broadcast_id = "")
45
51
  path = "broadcasts/#{broadcast_id}/cancel"
46
52
  Resend::Request.new(path, {}, "post").perform
@@ -57,6 +63,25 @@ module Resend
57
63
  path = "broadcasts/#{broadcast_id}"
58
64
  Resend::Request.new(path, {}, "get").perform
59
65
  end
66
+
67
+ # https://resend.com/docs/api-reference/broadcasts/list-broadcast-recipients
68
+ # @param broadcast_id [String] the broadcast id
69
+ # @param params [Hash] the parameters
70
+ # @option params [String] :type the recipient event type to filter by (required):
71
+ # sent, delivered, opened, clicked, bounced, complained, unsubscribed, suppressed
72
+ # @option params [String] :email filter recipients by email address (optional)
73
+ # @option params [String] :bounce_type filter bounced recipients by bounce type (optional,
74
+ # only valid when type is bounced): permanent, transient, undetermined
75
+ # @option params [Integer] :limit the maximum number of results to return (optional)
76
+ # @option params [String] :after the cursor for pagination (optional)
77
+ # @option params [String] :before the cursor for pagination (optional)
78
+ def recipients(broadcast_id = "", params = {})
79
+ raise ArgumentError, "type is required" if params[:type].nil?
80
+
81
+ base_path = "broadcasts/#{broadcast_id}/recipients"
82
+ path = Resend::PaginationHelper.build_paginated_path(base_path, params)
83
+ Resend::Request.new(path, {}, "get").perform
84
+ end
60
85
  end
61
86
  end
62
87
  end
data/lib/resend/emails.rb CHANGED
@@ -61,6 +61,64 @@ module Resend
61
61
 
62
62
  Resend::Request.new(path, query_params, "get").perform
63
63
  end
64
+
65
+ # Retrieve email metrics.
66
+ # see more: https://resend.com/docs/api-reference/emails/metrics
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
+ Resend::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
64
122
  end
65
123
  end
66
124
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resend
4
- VERSION = "1.10.0"
4
+ VERSION = "1.11.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derich Pacheco