-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathWebhookService.java
More file actions
115 lines (98 loc) · 3.38 KB
/
WebhookService.java
File metadata and controls
115 lines (98 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.easypost.service;
import com.easypost.exception.EasyPostException;
import com.easypost.http.Requestor;
import com.easypost.http.Requestor.RequestMethod;
import com.easypost.model.Webhook;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
public class WebhookService {
private final EasyPostClient client;
/**
* WebhookService constructor.
*
* @param client The client object.
*/
WebhookService(EasyPostClient client) {
this.client = client;
}
/**
* Create a Webhook object from a map of parameters.
*
* @param params the map of parameters
* @return Webhook object
* @throws EasyPostException when the request fails.
*/
public Webhook create(final Map<String, Object> params) throws EasyPostException {
Map<String, Object> wrappedParams = new HashMap<String, Object>();
wrappedParams.put("webhook", params);
String endpoint = "webhooks";
return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, Webhook.class, client);
}
/**
* Retrieve a Webhook object from the API.
*
* @param id the ID of the Webhook to retrieve
* @return Webhook object
* @throws EasyPostException when the request fails.
*/
public Webhook retrieve(final String id) throws EasyPostException {
String endpoint = "webhooks/" + id;
return Requestor.request(RequestMethod.GET, endpoint, null, Webhook.class, client);
}
/**
* Get a list of all Webhook objects.
*
* @return List of Webhook objects.
* @throws EasyPostException when the request fails.
*/
public List<Webhook> all() throws EasyPostException {
return all(null);
}
/**
* Get a list of all Webhook objects.
*
* @param params params for request
* @return List of Webhook objects.
* @throws EasyPostException when the request fails.
*/
public List<Webhook> all(final Map<String, Object> params) throws EasyPostException {
String endpoint = "webhooks";
Webhook[] response = Requestor.request(RequestMethod.GET, endpoint, params, Webhook[].class, client);
return Arrays.asList(response);
}
/**
* Delete this Webhook.
*
* @param id The ID of webhook.
* @throws EasyPostException when the request fails.
*/
public void delete(final String id) throws EasyPostException {
String endpoint = "webhooks/" + id;
Requestor.request(RequestMethod.DELETE, endpoint, null, Webhook.class, client);
}
/**
* Update this webhook.
*
* @param id The ID of webhook.
* @return Webhook object
* @throws EasyPostException when the request fails.
*/
public Webhook update(final String id) throws EasyPostException {
Map<String, Object> params = new HashMap<String, Object>();
return this.update(id, params);
}
/**
* Update this webhook.
*
* @param id The ID of webhook.
* @param params Map of parameters
* @return Webhook object
* @throws EasyPostException when the request fails.
*/
public Webhook update(final String id, final Map<String, Object> params) throws EasyPostException {
String endpoint = "webhooks/" + id;
return Requestor.request(RequestMethod.PUT, endpoint, params, Webhook.class, client);
}
}