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

smartsheet / smartsheet-java-sdk / #55

02 Oct 2024 07:40PM UTC coverage: 60.548% (+0.7%) from 59.836%
#55

push

github

web-flow
Release prep for 3.2.1 (#103)

4156 of 6864 relevant lines covered (60.55%)

0.61 hits per line

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

62.86
/src/main/java/com/smartsheet/api/SmartsheetBuilder.java
1
/*
2
 * Copyright (C) 2024 Smartsheet
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.smartsheet.api;
18

19
import com.smartsheet.api.internal.SmartsheetImpl;
20
import com.smartsheet.api.internal.http.HttpClient;
21
import com.smartsheet.api.internal.json.JsonSerializer;
22

23
/**
24
 * <p>A convenience class to help create a {@link Smartsheet} instance with the appropriate fields.</p>
25
 *
26
 * <p>Thread Safety: This class is not thread safe since it's mutable, one builder instance is NOT expected to be used in
27
 * multiple threads.</p>
28
 */
29
public class SmartsheetBuilder {
30
    /**
31
     * <p>Represents the HttpClient.</p>
32
     *
33
     * <p>It can be set using corresponding setter.</p>
34
     */
35
    private HttpClient httpClient;
36

37
    /**
38
     * <p>Represents the JsonSerializer.</p>
39
     *
40
     * <p>It can be set using corresponding setter.</p>
41
     */
42
    private JsonSerializer jsonSerializer;
43

44
    /**
45
     * <p>Represents the base URI.</p>
46
     *
47
     * <p>It can be set using corresponding setter.</p>
48
     */
49
    private String baseURI;
50

51
    /**
52
     * <p>Represents the access token.</p>
53
     *
54
     * <p>It can be set using corresponding setter.</p>
55
     */
56
    private String accessToken;
57

58
    /**
59
     * <p>Represents the maximum retry time allowed for failed API calls.</p>
60
     *
61
     * <p>It can be set using corresponding setter.</p>
62
     */
63
    private Long maxRetryTimeMillis;
64

65
    /**
66
     * <p>Represents the assumed user.</p>
67
     *
68
     * <p>It can be set using corresponding setter.</p>
69
     */
70
    private String assumedUser;
71

72
    /**
73
     * <p>Represents the change agent.</p>
74
     *
75
     * <p>It can be set using corresponding setter.</p>
76
     */
77
    private String changeAgent;
78

79
    /** URI to prod-us API endpoints */
80
    public static final String US_BASE_URI = "https://api.smartsheet.com/2.0/";
81
    /** URI to prod-eu API endpoints */
82
    public static final String EU_BASE_URI = "https://api.smartsheet.eu/2.0/";
83

84
    /**
85
     * <p>Represents the default base URI of the Smartsheet REST API.</p>
86
     *
87
     * <p>It is a constant with value "https://api.smartsheet.com/2.0".</p>
88
     */
89
    public static final String DEFAULT_BASE_URI = US_BASE_URI;
90

91
    /**
92
     * <p>Represents the default base URI of the Smartsheetgov REST API.</p>
93
     *
94
     * <p>It is a constant with value "https://api.smartsheetgov.com/2.0".</p>
95
     */
96
    public static final String GOV_BASE_URI = "https://api.smartsheetgov.com/2.0/";
97

98
    /**
99
     * Constructor.
100
     */
101
    public SmartsheetBuilder() {
1✔
102
    }
1✔
103

104
    /**
105
     * <p>Set the HttpClient.</p>
106
     *
107
     * @param httpClient the http client
108
     * @return the smartsheet builder
109
     */
110
    public SmartsheetBuilder setHttpClient(HttpClient httpClient) {
111
        this.httpClient = httpClient;
1✔
112
        return this;
1✔
113
    }
114

115
    /**
116
     * <p>Set the JsonSerializer.</p>
117
     *
118
     * @param jsonSerializer the JsonSerializer
119
     * @return the SmartsheetBuilder
120
     */
121
    public SmartsheetBuilder setJsonSerializer(JsonSerializer jsonSerializer) {
122
        this.jsonSerializer = jsonSerializer;
1✔
123
        return this;
1✔
124
    }
125

126
    /**
127
     * <p>Set the base URI.</p>
128
     *
129
     * @param baseURI the base uri
130
     * @return the smartsheet builder
131
     */
132
    public SmartsheetBuilder setBaseURI(String baseURI) {
133
        this.baseURI = baseURI;
1✔
134
        return this;
1✔
135
    }
136

137
    /**
138
     * <p>Set the access token.</p>
139
     *
140
     * @param accessToken the access token
141
     * @return the smartsheet builder
142
     */
143
    public SmartsheetBuilder setAccessToken(String accessToken) {
144
        this.accessToken = accessToken;
1✔
145
        return this;
1✔
146
    }
147

148
    /**
149
     * <p>Store a user provided userCalcBackoff.</p>
150
     *
151
     * <p>This interface is only valid when the DefaultHttpClient is used.</p>
152
     *
153
     * @return the smartsheet builder
154
     */
155
    public SmartsheetBuilder setMaxRetryTimeMillis(long maxRetryTimeMillis) {
156
        this.maxRetryTimeMillis = maxRetryTimeMillis;
×
157
        return this;
×
158
    }
159

160
    /**
161
     * <p>Set the assumed user.</p>
162
     *
163
     * @param assumedUser the assumed user
164
     * @return the smartsheet builder
165
     */
166
    public SmartsheetBuilder setAssumedUser(String assumedUser) {
167
        this.assumedUser = assumedUser;
1✔
168
        return this;
1✔
169
    }
170

171
    /**
172
     * <p>Set the assumed user.</p>
173
     *
174
     * @param changeAgent the identifier to include in the webhooks that result from the changes
175
     *                    made using the API
176
     * @return the smartsheet builder
177
     */
178
    public SmartsheetBuilder setChangeAgent(String changeAgent) {
179
        this.changeAgent = changeAgent;
×
180
        return this;
×
181
    }
182

183
    /**
184
     * <p>Gets the http client.</p>
185
     *
186
     * @return the http client
187
     */
188
    public HttpClient getHttpClient() {
189
        return httpClient;
×
190
    }
191

192
    /**
193
     * <p>Gets the json serializer.</p>
194
     *
195
     * @return the json serializer
196
     */
197
    public JsonSerializer getJsonSerializer() {
198
        return jsonSerializer;
×
199
    }
200

201
    /**
202
     * <p>Gets the base uri.</p>
203
     *
204
     * @return the base uri
205
     */
206
    public String getBaseURI() {
207
        return baseURI;
×
208
    }
209

210
    /**
211
     * <p>Gets the access token.</p>
212
     *
213
     * @return the access token
214
     */
215
    public String getAccessToken() {
216
        return accessToken;
×
217
    }
218

219
    /**
220
     * <p>Gets the assumed user.</p>
221
     *
222
     * @return the assumed user
223
     */
224
    public String getAssumedUser() {
225
        return assumedUser;
×
226
    }
227

228
    /**
229
     * <p>Gets the default base uri.</p>
230
     *
231
     * @return the default base uri
232
     */
233
    public static String getDefaultBaseUri() {
234
        return DEFAULT_BASE_URI;
×
235
    }
236

237
    /**
238
     * <p>Gets the Smartsheet Change-Agent</p>
239
     *
240
     * @return the change agent
241
     */
242
    public String getChangeAgent() {
243
        return changeAgent;
×
244
    }
245

246
    /**
247
     * <p>Build the Smartsheet instance.</p>
248
     *
249
     * @return the Smartsheet instance
250
     * @throws IllegalStateException if accessToken isn't set yet.
251
     */
252
    public Smartsheet build() {
253
        if (baseURI == null) {
1✔
254
            baseURI = DEFAULT_BASE_URI;
1✔
255
        }
256

257
        if (accessToken == null) {
1✔
258
            accessToken = System.getenv("SMARTSHEET_ACCESS_TOKEN");
1✔
259
        }
260

261
        SmartsheetImpl smartsheet = new SmartsheetImpl(baseURI, accessToken, httpClient, jsonSerializer);
1✔
262

263
        if (changeAgent != null) {
1✔
264
            smartsheet.setChangeAgent(changeAgent);
×
265
        }
266
        if (assumedUser != null) {
1✔
267
            smartsheet.setAssumedUser(assumedUser);
1✔
268
        }
269
        if (maxRetryTimeMillis != null) {
1✔
270
            smartsheet.setMaxRetryTimeMillis(maxRetryTimeMillis);
×
271
        }
272

273
        return smartsheet;
1✔
274
    }
275
}
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

© 2025 Coveralls, Inc