• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smartsheet / smartsheet-java-sdk / #41

24 Aug 2023 04:59PM UTC coverage: 50.458% (+0.01%) from 50.444%
#41

push

github-actions

web-flow
Fix Checkstyle Violations in "Impl" Classes (#53)

241 of 241 new or added lines in 32 files covered. (100.0%)

3417 of 6772 relevant lines covered (50.46%)

0.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/smartsheet/api/internal/WebhookResourcesImpl.java
1
package com.smartsheet.api.internal;
2

3
/*
4
 * #[license]
5
 * Smartsheet SDK for Java
6
 * %%
7
 * Copyright (C) 2023 Smartsheet
8
 * %%
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *      http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 * %[license]
21
 */
22

23
import com.fasterxml.jackson.core.JsonParseException;
24
import com.fasterxml.jackson.databind.JsonMappingException;
25
import com.smartsheet.api.AuthorizationException;
26
import com.smartsheet.api.InvalidRequestException;
27
import com.smartsheet.api.ResourceNotFoundException;
28
import com.smartsheet.api.ServiceUnavailableException;
29
import com.smartsheet.api.SmartsheetException;
30
import com.smartsheet.api.WebhookResources;
31
import com.smartsheet.api.internal.http.HttpMethod;
32
import com.smartsheet.api.internal.http.HttpRequest;
33
import com.smartsheet.api.internal.http.HttpResponse;
34
import com.smartsheet.api.internal.util.QueryUtil;
35
import com.smartsheet.api.models.PagedResult;
36
import com.smartsheet.api.models.PaginationParameters;
37
import com.smartsheet.api.models.Webhook;
38
import com.smartsheet.api.models.WebhookSharedSecret;
39

40
import java.io.IOException;
41
import java.util.HashMap;
42
import java.util.Map;
43

44
public class WebhookResourcesImpl extends AbstractResources implements WebhookResources {
45
    private static final String WEBHOOKS_PATH = "webhooks/";
46

47
    public WebhookResourcesImpl(SmartsheetImpl smartsheet) {
48
        super(smartsheet);
×
49
    }
×
50

51
    /**
52
     * Gets the list of all Webhooks that the user owns (if a user generated token was used to make the request)
53
     * or the list of all Webhooks associated with the third-party app (if a third-party app made the request). Items
54
     * in the response are ordered by API Client name, then Webhook name, then creation date.
55
     * <p>
56
     * It mirrors to the following Smartsheet REST API method: GET /webhooks
57
     *
58
     * @param paging the object containing the pagination parameters
59
     * @return IndexResult object containing an array of Webhook objects.
60
     * @throws IllegalArgumentException if any argument is null or empty string
61
     * @throws InvalidRequestException if there is any problem with the REST API request
62
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
63
     * @throws ResourceNotFoundException if the resource cannot be found
64
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
65
     * @throws SmartsheetException if there is any other error during the operation
66
     */
67
    public PagedResult<Webhook> listWebhooks(PaginationParameters paging) throws SmartsheetException {
68
        String path = "webhooks";
×
69

70
        Map<String, Object> parameters = new HashMap<>();
×
71
        if (paging != null) {
×
72
            parameters = paging.toHashMap();
×
73
        }
74

75
        path += QueryUtil.generateUrl(null, parameters);
×
76
        return this.listResourcesWithWrapper(path, Webhook.class);
×
77
    }
78

79
    /**
80
     * Gets the Webhook specified in the URL.
81
     * <p>
82
     * It mirrors to the following Smartsheet REST API method: GET /webhooks/{webhookId}
83
     *
84
     * @param webhookId the Id of the webhook
85
     * @return the webhook resource.
86
     * @throws IllegalArgumentException if any argument is null or empty string
87
     * @throws InvalidRequestException if there is any problem with the REST API request
88
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
89
     * @throws ResourceNotFoundException if the resource cannot be found
90
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
91
     * @throws SmartsheetException if there is any other error during the operation
92
     */
93
    public Webhook getWebhook(long webhookId) throws SmartsheetException {
94
        return this.getResource(WEBHOOKS_PATH + webhookId, Webhook.class);
×
95
    }
96

97
    /**
98
     * Creates a new Webhook.
99
     * <p>
100
     * It mirrors to the following Smartsheet REST API method: POST /webhooks
101
     *
102
     * @param webhook the webhook to be created
103
     * @return the webhook resource.
104
     * @throws IllegalArgumentException if any argument is null or empty string
105
     * @throws InvalidRequestException if there is any problem with the REST API request
106
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
107
     * @throws ResourceNotFoundException if the resource cannot be found
108
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
109
     * @throws SmartsheetException if there is any other error during the operation
110
     */
111
    public Webhook createWebhook(Webhook webhook) throws SmartsheetException {
112
        return this.createResource("webhooks", Webhook.class, webhook);
×
113
    }
114

115
    /**
116
     * Updates the webhooks specified in the URL.
117
     * <p>
118
     * It mirrors to the following Smartsheet REST API method: PUT /webhooks/{webhookId}
119
     *
120
     * @param webhook the webhook to update
121
     * @return the updated webhook resource.
122
     * @throws IllegalArgumentException if any argument is null or empty string
123
     * @throws InvalidRequestException if there is any problem with the REST API request
124
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
125
     * @throws ResourceNotFoundException if the resource cannot be found
126
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
127
     */
128
    public Webhook updateWebhook(Webhook webhook) throws SmartsheetException {
129
        return this.updateResource(WEBHOOKS_PATH + webhook.getId(), Webhook.class, webhook);
×
130
    }
131

132
    /**
133
     * Delete a webhook.
134
     * <p>
135
     * It mirrors to the following Smartsheet REST API method: DELETE /webhooks/{webhookId}
136
     *
137
     * @param webhookId the webhook Id
138
     * @throws IllegalArgumentException if any argument is null or empty string
139
     * @throws InvalidRequestException if there is any problem with the REST API request
140
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
141
     * @throws ResourceNotFoundException if the resource cannot be found
142
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
143
     * @throws SmartsheetException if there is any other error during the operation
144
     */
145
    public void deleteWebhook(long webhookId) throws SmartsheetException {
146
        this.deleteResource(WEBHOOKS_PATH + webhookId, Webhook.class);
×
147
    }
×
148

149
    /**
150
     * Resets the shared secret for the specified Webhook. For more information about how a shared secret is used,
151
     *  see Authenticating Callbacks.
152
     * <p>
153
     * It mirrors to the following Smartsheet REST API method: POST /webhooks/{webhookId}/resetsharedsecret
154
     *
155
     * @param webhookId the webhook Id
156
     * @return the Webhook shared secret
157
     * @throws IllegalArgumentException if any argument is null or empty string
158
     * @throws InvalidRequestException if there is any problem with the REST API request
159
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
160
     * @throws ResourceNotFoundException if the resource cannot be found
161
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
162
     * @throws SmartsheetException if there is any other error during the operation
163
     */
164
    public WebhookSharedSecret resetSharedSecret(long webhookId) throws SmartsheetException {
165
        HttpRequest request = createHttpRequest(this.getSmartsheet().getBaseURI().resolve(WEBHOOKS_PATH +
×
166
                webhookId + "/resetsharedsecret"), HttpMethod.POST);
167

168
        HttpResponse response = getSmartsheet().getHttpClient().request(request);
×
169

170
        WebhookSharedSecret secret = null;
×
171
        switch (response.getStatusCode()) {
×
172
            case 200:
173
                try {
174
                    secret = this.smartsheet.getJsonSerializer().deserialize(WebhookSharedSecret.class,
×
175
                        response.getEntity().getContent());
×
176
                } catch (JsonParseException e) {
×
177
                    throw new SmartsheetException(e);
×
178
                } catch (JsonMappingException e) {
×
179
                    throw new SmartsheetException(e);
×
180
                } catch (IOException e) {
×
181
                    throw new SmartsheetException(e);
×
182
                }
×
183
                break;
184
            default:
185
                handleError(response);
×
186
        }
187

188
        getSmartsheet().getHttpClient().releaseConnection();
×
189
        return secret;
×
190
    }
191
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc