Skip to content

Commit 63eb95b

Browse files
committed
Adds samples for the Metrics API. Also adds concrete metrics responses to each Metrics resource call.
1 parent 240a5e9 commit 63eb95b

12 files changed

+1163
-36
lines changed

apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/DeliverabilityMetricsSample.java

+714
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
package com.sparkpost.model;
3+
4+
public class MetricsBounceFields {
5+
6+
/**
7+
* These are all the fields that can be used in a request
8+
*/
9+
public static final String ALL_FIELDS = "count_bounce,count_inband_bounce,count_outofband_bounce";
10+
11+
/**
12+
* This is all the fields available in a response
13+
*/
14+
public static final String[] ALL_FIELDS_ARRAY = new String[] {
15+
"bounce_class_name",
16+
"bounce_class_description",
17+
"bounce_category_name",
18+
"classification_id",
19+
"count_bounce",
20+
"count_inband_bounce",
21+
"count_outofband_bounce",
22+
"domain",
23+
"reason"};
24+
25+
public static final String BOUNCE_CLASS_NAME = "bounce_class_name";
26+
public static final String BOUNCE_CLASS_DESCRIPTION = "bounce_class_description";
27+
public static final String BOUNCE_CATEGORY_NAME = "bounce_category_name";
28+
public static final String CLASSIFICATION_ID = "classification_id";
29+
public static final String COUNT_BOUNCE = "count_bounce";
30+
public static final String COUNT_INBAND_BOUNCE = "count_inband_bounce";
31+
public static final String COUNT_OUTOFBAND_BOUNCE = "count_outofband_bounce";
32+
33+
public static final String REASON = "reason";
34+
35+
public static final String DOMAIN = "domain";
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
package com.sparkpost.model;
3+
4+
public class MetricsDelayReasonFields {
5+
6+
public static final String[] ALL_FIELDS_ARRAY = new String[] {"count_delayed", "count_delayed_first", "reason"};
7+
8+
public static final String COUNT_DELAYED = "count_delayed";
9+
public static final String COUNT_DELAYED_FIRST = "count_delayed_first";
10+
public static final String REASON = "reason";
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
package com.sparkpost.model;
3+
4+
public class MetricsDeliveriesFields {
5+
6+
public static final String[] ALL_FIELDS_ARRAY = new String[] {"attempt", "count_delivered"};
7+
8+
public static final String ATTEMPT = "attempt";
9+
public static final String COUNT_DELIVERED = "count_delivered";
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
package com.sparkpost.model;
3+
4+
public class MetricsEngagementFields {
5+
6+
public static final String ALL_FIELDS = "count_clicked,count_raw_clicked";
7+
8+
public static final String[] ALL_FIELDS_ARRAY = new String[] {"link_name", "count_clicked", "count_raw_clicked"};
9+
10+
public static final String LINK_NAME = "link_name";
11+
public static final String COUNT_CLICKED = "count_clicked";
12+
public static final String COUNT_ROW_CLICKED = "count_raw_clicked";
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
2+
package com.sparkpost.model;
3+
4+
/**
5+
* Deliverability Metrics Fields
6+
* See: https://developers.sparkpost.com/api/#/reference/metrics
7+
*/
8+
public class MetricsFields {
9+
10+
public static final String DOMAIN = "domain";
11+
12+
public static final String CAMPAIGN_ID = "campaign_id";
13+
14+
public static final String TEMPLATE_ID = "template_id";
15+
16+
public static final String WATCHED_DOMAIN = "watched_domain";
17+
18+
public static final String TIMESTAMP = "ts";
19+
20+
/**
21+
* All Deliverability Fields
22+
*/
23+
public static final String ALL_FIELDS = "count_targeted,count_injected,count_sent,count_accepted,count_delivered_first,count_delivered_subsequent,count_rendered,count_unique_rendered,count_unique_confirmed_opened,count_clicked,count_unique_clicked,count_bounce,count_hard_bounce,count_soft_bounce,count_block_bounce,count_admin_bounce,count_undetermined_bounce,count_rejected,count_policy_rejection,count_generation_failed,count_generation_rejection,count_inband_bounce,count_outofband_bounce,count_delayed,count_delayed_first,total_msg_volume,count_spam_complaint,total_delivery_time_first,total_delivery_time_subsequent,total_msg_volume";
24+
25+
public static final String[] ALL_FIELDS_ARRAY = new String[] {
26+
"count_targeted",
27+
"count_injected",
28+
"count_sent",
29+
"count_accepted",
30+
"count_delivered_first",
31+
"count_delivered_subsequent",
32+
"count_rendered",
33+
"count_unique_rendered",
34+
"count_unique_confirmed_opened",
35+
"count_clicked",
36+
"count_unique_clicked",
37+
"count_bounce",
38+
"count_hard_bounce",
39+
"count_soft_bounce",
40+
"count_block_bounce",
41+
"count_admin_bounce",
42+
"count_undetermined_bounce",
43+
"count_rejected",
44+
"count_policy_rejection",
45+
"count_generation_failed",
46+
"count_generation_rejection",
47+
"count_inband_bounce",
48+
"count_outofband_bounce",
49+
"count_delayed",
50+
"count_delayed_first",
51+
"total_msg_volume",
52+
"count_spam_complaint",
53+
"total_delivery_time_first",
54+
"total_delivery_time_subsequent",
55+
"total_msg_volume"
56+
57+
};
58+
59+
/**
60+
* Messages successfully injected into SparkPost and SparkPost Elite as well as rejected by it
61+
*/
62+
public static final String COUNT_TARGETED = "count_targeted";
63+
64+
/**
65+
* Messages injected to or received by SparkPost and SparkPost Elite
66+
*/
67+
public static final String COUNT_INJECTED = "count_injected";
68+
69+
/**
70+
* Messages that SparkPost and SparkPost Elite attempted to deliver, which includes both Deliveries and In-Band Bounces
71+
*/
72+
public static final String COUNT_SENT = "count_sent";
73+
74+
/**
75+
* Messages an ISP or other remote domain accepted (less Out-of-Band Bounces)
76+
*/
77+
public static final String COUNT_ACCEPTED = "count_accepted";
78+
79+
/**
80+
* Messages delivered on the first attempt
81+
*/
82+
public static final String COUNT_DELIVERED_FIRST = "count_delivered_first";
83+
84+
/**
85+
* Messages delivered that required more than one delivery attempt
86+
*/
87+
public static final String COUNT_DELIVERED_SUBSEQUENT = "count_delivered_subsequent";
88+
89+
/**
90+
* Total renderings of a message
91+
*/
92+
public static final String COUNT_RENDERED = "count_rendered";
93+
94+
/**
95+
* Total number of messages that were rendered at least once
96+
*/
97+
public static final String COUNT_UNIQUE_RENDERED = "count_unique_rendered";
98+
99+
/**
100+
* Total number of messages that were rendered or had at least one link selected
101+
*/
102+
public static final String COUNT_UNIQUE_CONFIRMED_OPENED = "count_unique_confirmed_opened";
103+
104+
/**
105+
* Total number of times that links were selected across all messages
106+
*/
107+
public static final String COUNT_CLICKED = "count_clicked";
108+
109+
/**
110+
* Total number of messages which had at least one link selected one or more times
111+
*/
112+
public static final String COUNT_UNIQUE_CLICKED = "count_unique_clicked";
113+
114+
/**
115+
* Total number of bounced messages, which includes both In-Band and Out-of-Band bounces
116+
*/
117+
public static final String COUNT_BOUNCE = "count_bounce";
118+
119+
/**
120+
* Total number of Bounced messages due to hard bounce classification reasons
121+
*/
122+
public static final String COUNT_HARD_BOUNCE = "count_hard_bounce";
123+
124+
/**
125+
* Total number of Bounced messages due to soft bounce classification reasons
126+
*/
127+
public static final String COUNT_SOFT_BOUNCE = "count_soft_bounce";
128+
129+
/**
130+
* Total number of Bounced messages due to an IP block
131+
*/
132+
public static final String COUNT_BLOCK_BOUNCE = "count_block_bounce";
133+
134+
/**
135+
* Total number of Bounced messages due to admin bounce classification reasons, also includes Rejected
136+
*/
137+
public static final String COUNT_ADMIN_BOUNCE = "count_admin_bounce";
138+
139+
/**
140+
* Total number of Bounced messages due to undetermined bounce reasons
141+
*/
142+
public static final String COUNT_UNDERTERMINED_BOUNCE = "count_undetermined_bounce";
143+
144+
/**
145+
* Messages rejected due to policy or that failed to generate
146+
*/
147+
public static final String COUNT_REJECTED = "count_rejected";
148+
149+
/**
150+
* Messages rejected by SparkPost and SparkPost Elite due to policy
151+
*/
152+
public static final String COUNT_POLICY_REJECTED = "count_policy_rejection";
153+
154+
/**
155+
* Message generation failed for an intended recipient
156+
*/
157+
public static final String COUNT_GENERATION_FAILED = "count_generation_failed";
158+
159+
/**
160+
* Messages rejected by SparkPost and SparkPost Elite due to policy
161+
*/
162+
public static final String COUNT_GENERATION_REJECTION = "count_generation_rejection";
163+
164+
/**
165+
* Messages that bounced on delivery attempt during the SMTP session
166+
*/
167+
public static final String COUNT_INBAND_BOUNCE = "count_inband_bounce";
168+
169+
/**
170+
* Messages that the ISP bounced subsequent to a successful delivery
171+
*/
172+
public static final String COUNT_OUTOFBAND_BOUNCE = "count_outofband_bounce";
173+
174+
/**
175+
* Total number of delays due to any temporary failure
176+
*/
177+
public static final String COUNT_DELAYED = "count_delayed";
178+
179+
/**
180+
* Messages delayed on the first delivery attempt
181+
*/
182+
public static final String COUNT_DELAYED_FIRST = "count_delayed_first";
183+
184+
/**
185+
* Number of spam complaints received from an ISP
186+
*/
187+
public static final String COUNT_SPAM_COMPLAINT = "count_spam_complaint";
188+
189+
public static final String TOTAL_DELIVERY_TIME_FIRST = "total_delivery_time_first";
190+
191+
public static final String TOTAL_DELIVERY_TIME_SUBSEQUENT = "total_delivery_time_subsequent";
192+
193+
/**
194+
* Total size of delivered messages, in bytes (including attachments)
195+
*/
196+
public static final String TOTAL_MSG_VOLUME = "total_msg_volume";
197+
198+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
package com.sparkpost.model;
3+
4+
public class MetricsRejectFields {
5+
6+
public static final String[] ALL_FIELDS_ARRAY = new String[] {"count_rejected", "rejection_category_name", "rejection_category_id", "reason"};
7+
8+
public static final String COUNT_REJECTED = "count_rejected";
9+
public static final String REJECTION_CATEGORY_NAME = "rejection_category_name";
10+
public static final String REJECTION_CATEGORY_ID = "rejection_category_id";
11+
public static final String REASON = "reason";
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
package com.sparkpost.model.responses;
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import lombok.Data;
9+
import lombok.EqualsAndHashCode;
10+
11+
@Data
12+
@EqualsAndHashCode(callSuper = true)
13+
public class CampaignListResponse extends Response {
14+
15+
Map<String, List<String>> results;
16+
17+
public List<String> getCampaignList() {
18+
if (this.results == null) {
19+
return new ArrayList<String>();
20+
}
21+
return this.results.get("campaigns");
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
package com.sparkpost.model.responses;
3+
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import com.google.gson.annotations.SerializedName;
8+
import com.yepher.jsondoc.annotations.Description;
9+
10+
import lombok.Data;
11+
import lombok.EqualsAndHashCode;
12+
13+
@Data
14+
@EqualsAndHashCode(callSuper = true)
15+
public class DeliverabiltyMetricsResponse extends Response {
16+
17+
@Description(value = "results", sample = {"\"results\": [ {\"count_injected\": 633,...}]"})
18+
@SerializedName("results")
19+
private List<Map<String, Object>> results;
20+
21+
@Description(value = "links", sample = {"{ \"href\": \"/api/v1/metrics/deliverability\", \"rel\": \"deliverability\", \"method\": \"GET\" }"})
22+
@SerializedName("links")
23+
private List<MetricLinkResponse> links;
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
package com.sparkpost.model.responses;
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import lombok.Data;
9+
import lombok.EqualsAndHashCode;
10+
11+
@Data
12+
@EqualsAndHashCode(callSuper = true)
13+
public class DomainListResponse extends Response {
14+
15+
Map<String, List<String>> results;
16+
17+
public List<String> getDomainList() {
18+
if (this.results == null) {
19+
return new ArrayList<String>();
20+
}
21+
return this.results.get("domains");
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
package com.sparkpost.model.responses;
3+
4+
import com.yepher.jsondoc.annotations.Description;
5+
6+
import lombok.Data;
7+
import lombok.EqualsAndHashCode;
8+
9+
/**
10+
* child endpoints that contain aggregate data, which can be used as "group by" qualifiers.
11+
*/
12+
@Data
13+
@EqualsAndHashCode
14+
public class MetricLinkResponse {
15+
16+
@Description(value = "endpoint reference", sample = {"/api/v1/metrics/deliverability"})
17+
private String href;
18+
19+
@Description(value = "", sample = {"deliverability"})
20+
private String rel;
21+
22+
@Description(value = "", sample = {"GET, POST, PUT, DELETE"})
23+
private String method;
24+
25+
}

0 commit comments

Comments
 (0)