Skip to content

Commit 2267a1a

Browse files
committed
Webhook class was actualized. WebhookCreateResponse simplifies retrieving of created record id.
1 parent 7cd1ad9 commit 2267a1a

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.sparkpost.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import com.yepher.jsondoc.annotations.Description;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
7+
8+
@Data
9+
@EqualsAndHashCode(callSuper = true)
10+
public class AuthCredentials extends Base {
11+
12+
@Description(value = "Basic Auth Username. Used for 'basic' authorization flow.")
13+
private String username;
14+
15+
@Description(value = "Basic Auth Password. Used for 'basic' authorization flow.")
16+
private String password;
17+
18+
@Description(value = "OAuth2 access token generated by SparkPost. Returned in case of 'oauth2' authorization flow.")
19+
@SerializedName("access_token")
20+
private String accessToken;
21+
22+
@Description(value = "The lifetime of the access_token in seconds. Returned in case of 'oauth2' authorization flow.")
23+
@SerializedName("expires_in")
24+
private Integer expiresIn;
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.sparkpost.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import com.yepher.jsondoc.annotations.Description;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
7+
8+
@Data
9+
@EqualsAndHashCode(callSuper = true)
10+
public class AuthRequestDetails extends Base {
11+
12+
@Description(value = "This is the URL SparkPost will request tokens from.", sample = {"https://oauth.myurl.com/tokens"})
13+
private String url;
14+
15+
@Description(value = "OAuth 2.0 parameters that your target URL uses")
16+
private AuthRequestClientDetails body;
17+
18+
19+
@Data
20+
@EqualsAndHashCode(callSuper = true)
21+
public class AuthRequestClientDetails extends Base {
22+
23+
@Description(value = "OAuth 2.0 Client ID")
24+
@SerializedName("client_id")
25+
private String clientId;
26+
27+
@Description(value = "OAuth 2.0 Client Secret")
28+
@SerializedName("client_secret")
29+
private String clientSecret;
30+
}
31+
}

libs/sparkpost-lib/src/main/java/com/sparkpost/model/Webhook.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
package com.sparkpost.model;
33

4+
import java.util.Arrays;
45
import java.util.List;
56

67
import com.google.gson.annotations.SerializedName;
@@ -24,6 +25,20 @@ public class Webhook extends Base {
2425
@Description(value = "URL of the target to which to POST relay batches", sample = {"https://webhooks.customer.example/replies"})
2526
private String target;
2627

28+
@Description(value = "Type of authentication to be used during POST requests to target.", sample = {"none", "basic", "oauth2"})
29+
@SerializedName("auth_type")
30+
private String authType;
31+
32+
@Description(value = "When using auth_type == 'oauth2', auth_request_details must be set by the user. "
33+
+ "Additionally, auth_credentials is set by the system and cannot be configured by the user")
34+
@SerializedName("auth_request_details")
35+
private AuthRequestDetails authRequestDetails;
36+
37+
@Description(value = "When using auth_type == 'basic', auth_credentials must be set by the user")
38+
@SerializedName("auth_credentials")
39+
private AuthCredentials authCredentials;
40+
41+
@Deprecated
2742
@Description(
2843
value = "Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target",
2944
sample = {"5ebe2294ecd0e0f08eab7690d2a6ee69"})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.sparkpost.model;
2+
3+
import com.yepher.jsondoc.annotations.Description;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
@Data
8+
@EqualsAndHashCode(callSuper = true)
9+
public class WebhookCreateResponseEntry extends Base {
10+
11+
@Description(value = "Created webhook id.")
12+
private String id;
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.sparkpost.model.responses;
2+
3+
import com.sparkpost.model.WebhookCreateResponseEntry;
4+
import com.yepher.jsondoc.annotations.Description;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
7+
8+
@Data
9+
@EqualsAndHashCode(callSuper = true)
10+
public class WebhookCreateResponse extends Response {
11+
12+
13+
@Description(value = "Created webhook description")
14+
WebhookCreateResponseEntry results;
15+
}

libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceWebhooks.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.sparkpost.exception.SparkPostException;
55
import com.sparkpost.model.Webhook;
66
import com.sparkpost.model.responses.Response;
7+
import com.sparkpost.model.responses.WebhookCreateResponse;
78
import com.sparkpost.model.responses.WebhookListAllResponse;
89
import com.sparkpost.transport.RestConnection;
910

@@ -39,11 +40,12 @@ public static WebhookListAllResponse listAll(RestConnection conn, String timezon
3940
return allWebhooks;
4041
}
4142

42-
public static Response create(RestConnection conn, Webhook webhook) throws SparkPostException {
43+
public static WebhookCreateResponse create(RestConnection conn, Webhook webhook) throws SparkPostException {
4344

4445
String json = webhook.toJson();
4546
Response response = conn.post("webhooks", json);
46-
return response;
47+
WebhookCreateResponse webhookCreateResponse = WebhookCreateResponse.decode(response, WebhookCreateResponse.class);
48+
return webhookCreateResponse;
4749
}
4850

4951
public static Response describe(RestConnection conn, String id, String timezone) throws SparkPostException {

0 commit comments

Comments
 (0)