Skip to content

Commit 4587908

Browse files
committed
Remove ApiResource.RequestType (#899)
1 parent 35be63b commit 4587908

File tree

9 files changed

+24
-83
lines changed

9 files changed

+24
-83
lines changed

src/main/java/com/stripe/model/File.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static File create(FileCreateParams params, RequestOptions options)
9999
*/
100100
public static File create(Map<String, Object> params, RequestOptions options)
101101
throws StripeException {
102-
return multipartRequest(
102+
return request(
103103
RequestMethod.POST,
104104
classUrl(File.class, Stripe.getUploadBase()),
105105
params,

src/main/java/com/stripe/net/ApiResource.java

+1-18
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ public enum RequestMethod {
123123
DELETE
124124
}
125125

126-
public enum RequestType {
127-
NORMAL,
128-
MULTIPART
129-
}
130-
131126
/** URL-encodes a string. */
132127
public static String urlEncode(String str) {
133128
// Preserve original behavior that passing null for an object id will lead
@@ -165,17 +160,6 @@ public static String urlEncodeId(String id) throws InvalidRequestException {
165160
return urlEncode(id);
166161
}
167162

168-
public static <T> T multipartRequest(
169-
ApiResource.RequestMethod method,
170-
String url,
171-
Map<String, Object> params,
172-
Class<T> clazz,
173-
RequestOptions options)
174-
throws StripeException {
175-
return ApiResource.stripeResponseGetter.request(
176-
method, url, params, clazz, ApiResource.RequestType.MULTIPART, options);
177-
}
178-
179163
public static <T> T request(
180164
ApiResource.RequestMethod method,
181165
String url,
@@ -194,8 +178,7 @@ public static <T> T request(
194178
Class<T> clazz,
195179
RequestOptions options)
196180
throws StripeException {
197-
return ApiResource.stripeResponseGetter.request(
198-
method, url, params, clazz, ApiResource.RequestType.NORMAL, options);
181+
return ApiResource.stripeResponseGetter.request(method, url, params, clazz, options);
199182
}
200183

201184
public static <T extends StripeCollectionInterface<?>> T requestCollection(

src/main/java/com/stripe/net/LiveStripeResponseGetter.java

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public <T> T request(
3030
String url,
3131
Map<String, Object> params,
3232
Class<T> clazz,
33-
ApiResource.RequestType type,
3433
RequestOptions options)
3534
throws StripeException {
3635
StripeRequest request = new StripeRequest(method, url, params, options);
@@ -65,7 +64,6 @@ public <T> T oauthRequest(
6564
String url,
6665
Map<String, Object> params,
6766
Class<T> clazz,
68-
ApiResource.RequestType type,
6967
RequestOptions options)
7068
throws StripeException {
7169
StripeRequest request = new StripeRequest(method, url, params, options);

src/main/java/com/stripe/net/OAuth.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ public static TokenResponse token(Map<String, Object> params, RequestOptions opt
4747
throws StripeException {
4848
String url = Stripe.getConnectBase() + "/oauth/token";
4949
return OAuth.stripeResponseGetter.oauthRequest(
50-
ApiResource.RequestMethod.POST,
51-
url,
52-
params,
53-
TokenResponse.class,
54-
ApiResource.RequestType.NORMAL,
55-
options);
50+
ApiResource.RequestMethod.POST, url, params, TokenResponse.class, options);
5651
}
5752

5853
/**
@@ -67,12 +62,7 @@ public static DeauthorizedAccount deauthorize(Map<String, Object> params, Reques
6762
String url = Stripe.getConnectBase() + "/oauth/deauthorize";
6863
params.put("client_id", getClientId(params, options));
6964
return OAuth.stripeResponseGetter.oauthRequest(
70-
ApiResource.RequestMethod.POST,
71-
url,
72-
params,
73-
DeauthorizedAccount.class,
74-
ApiResource.RequestType.NORMAL,
75-
options);
65+
ApiResource.RequestMethod.POST, url, params, DeauthorizedAccount.class, options);
7666
}
7767

7868
/**

src/main/java/com/stripe/net/StripeResponseGetter.java

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ <T> T request(
99
String url,
1010
Map<String, Object> params,
1111
Class<T> clazz,
12-
ApiResource.RequestType type,
1312
RequestOptions options)
1413
throws StripeException;
1514

@@ -18,7 +17,6 @@ <T> T oauthRequest(
1817
String url,
1918
Map<String, Object> params,
2019
Class<T> clazz,
21-
ApiResource.RequestType type,
2220
RequestOptions options)
2321
throws StripeException;
2422
}

src/test/java/com/stripe/BaseStripeTest.java

+14-29
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,24 @@ public void tearDownStripeMockUsage() {
137137
}
138138

139139
/**
140-
* {@code params}, {@code requestType} and {@code options} defaults to {@code null}.
140+
* {@code params} and {@code options} defaults to {@code null}.
141141
*
142-
* @see BaseStripeTest#verifyRequest(ApiResource.RequestMethod, String, Map,
143-
* ApiResource.RequestType, RequestOptions)
142+
* @see BaseStripeTest#verifyRequest(ApiResource.RequestMethod, String, Map, RequestOptions)
144143
*/
145144
public static <T> void verifyRequest(ApiResource.RequestMethod method, String path)
146145
throws StripeException {
147-
verifyRequest(method, path, null, null, null);
146+
verifyRequest(method, path, null, null);
148147
}
149148

150149
/**
151-
* {@code requestType} and {@code options} defaults to {@code null}.
150+
* {@code options} defaults to {@code null}.
152151
*
153-
* @see BaseStripeTest#verifyRequest(ApiResource.RequestMethod, String, Map,
154-
* ApiResource.RequestType, RequestOptions)
152+
* @see BaseStripeTest#verifyRequest(ApiResource.RequestMethod, String, Map, RequestOptions)
155153
*/
156154
public static <T> void verifyRequest(
157155
ApiResource.RequestMethod method, String path, Map<String, Object> params)
158156
throws StripeException {
159-
verifyRequest(method, path, params, null, null);
157+
verifyRequest(method, path, params, null);
160158
}
161159

162160
/**
@@ -165,15 +163,12 @@ public static <T> void verifyRequest(
165163
* @param method HTTP method (GET, POST or DELETE)
166164
* @param path request path (e.g. "/v1/charges"). Can also be an abolute URL.
167165
* @param params map containing the parameters. If null, the parameters are not checked.
168-
* @param requestType request type (NORMAL or MULTIPART). If null, the request type is not
169-
* checked.
170166
* @param options request options. If null, the options are not checked.
171167
*/
172168
public static <T> void verifyRequest(
173169
ApiResource.RequestMethod method,
174170
String path,
175171
Map<String, Object> params,
176-
ApiResource.RequestType requestType,
177172
RequestOptions options)
178173
throws StripeException {
179174
String url;
@@ -191,9 +186,6 @@ public static <T> void verifyRequest(
191186
? Mockito.argThat(new ParamMapMatcher(params))
192187
: Mockito.<Map<String, Object>>any(),
193188
Mockito.<Class<T>>any(),
194-
(requestType != null)
195-
? Mockito.eq(requestType)
196-
: Mockito.any(ApiResource.RequestType.class),
197189
(options != null)
198190
? Mockito.argThat(new RequestOptionsMatcher(options))
199191
: Mockito.<RequestOptions>any());
@@ -210,22 +202,22 @@ public static <T> void verifyNoMoreRequests() {
210202
}
211203

212204
/**
213-
* {@code params}, {@code requestType} and {@code options} defaults to {@code null}.
205+
* {@code params} and {@code options} defaults to {@code null}.
214206
*
215-
* @see BaseStripeTest#stubRequest(ApiResource.RequestMethod, String, Map,
216-
* ApiResource.RequestType, RequestOptions, Class, String)
207+
* @see BaseStripeTest#stubRequest(ApiResource.RequestMethod, String, Map, RequestOptions, Class,
208+
* String)
217209
*/
218210
public static <T> void stubRequest(
219211
ApiResource.RequestMethod method, String path, Class<T> clazz, String response)
220212
throws StripeException {
221-
stubRequest(method, path, null, null, null, clazz, response);
213+
stubRequest(method, path, null, null, clazz, response);
222214
}
223215

224216
/**
225-
* {@code requestType} and {@code options} defaults to {@code null}.
217+
* {@code options} defaults to {@code null}.
226218
*
227-
* @see BaseStripeTest#stubRequest(ApiResource.RequestMethod, String, Map,
228-
* ApiResource.RequestType, RequestOptions, Class, String)
219+
* @see BaseStripeTest#stubRequest(ApiResource.RequestMethod, String, Map, RequestOptions, Class,
220+
* String)
229221
*/
230222
public static <T> void stubRequest(
231223
ApiResource.RequestMethod method,
@@ -234,7 +226,7 @@ public static <T> void stubRequest(
234226
Class<T> clazz,
235227
String response)
236228
throws StripeException {
237-
stubRequest(method, path, params, null, null, clazz, response);
229+
stubRequest(method, path, params, null, clazz, response);
238230
}
239231

240232
/**
@@ -244,8 +236,6 @@ public static <T> void stubRequest(
244236
* @param method HTTP method (GET, POST or DELETE)
245237
* @param path request path (e.g. "/v1/charges"). Can also be an abolute URL.
246238
* @param params map containing the parameters. If null, the parameters are not checked.
247-
* @param requestType request type (NORMAL or MULTIPART). If null, the request type is not
248-
* checked.
249239
* @param options request options. If null, the options are not checked.
250240
* @param clazz Class of the API resource that will be returned for the stubbed request.
251241
* @param response JSON payload of the API resource that will be returned for the stubbed request.
@@ -254,7 +244,6 @@ public static <T> void stubRequest(
254244
ApiResource.RequestMethod method,
255245
String path,
256246
Map<String, Object> params,
257-
ApiResource.RequestType requestType,
258247
RequestOptions options,
259248
Class<T> clazz,
260249
String response)
@@ -275,9 +264,6 @@ public static <T> void stubRequest(
275264
? Mockito.argThat(new ParamMapMatcher(params))
276265
: Mockito.<Map<String, Object>>any(),
277266
Mockito.<Class<T>>any(),
278-
(requestType != null)
279-
? Mockito.eq(requestType)
280-
: Mockito.any(ApiResource.RequestType.class),
281267
(options != null)
282268
? Mockito.argThat(new RequestOptionsMatcher(options))
283269
: Mockito.<RequestOptions>any());
@@ -292,7 +278,6 @@ public static <T> void stubOAuthRequest(Class<T> clazz, String response) throws
292278
Mockito.anyString(),
293279
Mockito.<Map<String, Object>>any(),
294280
Mockito.<Class<T>>any(),
295-
Mockito.any(ApiResource.RequestType.class),
296281
Mockito.<RequestOptions>any());
297282
}
298283

src/test/java/com/stripe/functional/EphemeralKeyTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void testCreate() throws StripeException {
3333
final EphemeralKey key = EphemeralKey.create(params, options);
3434

3535
assertNotNull(key);
36-
verifyRequest(ApiResource.RequestMethod.POST, "/v1/ephemeral_keys", params, null, options);
36+
verifyRequest(ApiResource.RequestMethod.POST, "/v1/ephemeral_keys", params, options);
3737
}
3838

3939
@Test
@@ -67,7 +67,6 @@ public void testCreateWithTypedParams() throws StripeException {
6767
ImmutableMap.of(
6868
"customer", "cust_123",
6969
"issuing_card", "card_123"),
70-
null,
7170
options);
7271
}
7372

src/test/java/com/stripe/functional/FileTest.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ public void testCreateWithFile() throws StripeException {
3131
final com.stripe.model.File file = com.stripe.model.File.create(params);
3232

3333
assertNotNull(file);
34-
verifyRequest(
35-
ApiResource.RequestMethod.POST,
36-
"/v1/files",
37-
params,
38-
ApiResource.RequestType.MULTIPART,
39-
null);
34+
verifyRequest(ApiResource.RequestMethod.POST, "/v1/files", params, null);
4035
}
4136

4237
@Test
@@ -63,7 +58,6 @@ public void testCreateWithFileWithTypedParams() throws StripeException {
6358
fileObject,
6459
"file_link_data",
6560
ImmutableMap.of("create", true, "expires_at", 123)),
66-
ApiResource.RequestType.MULTIPART,
6761
null);
6862
}
6963

@@ -88,12 +82,7 @@ public void testCreateWithStream() throws IOException, StripeException {
8882
final com.stripe.model.File file = com.stripe.model.File.create(params);
8983

9084
assertNotNull(file);
91-
verifyRequest(
92-
ApiResource.RequestMethod.POST,
93-
"/v1/files",
94-
params,
95-
ApiResource.RequestType.MULTIPART,
96-
null);
85+
verifyRequest(ApiResource.RequestMethod.POST, "/v1/files", params, null);
9786
}
9887

9988
@Test

src/test/java/com/stripe/model/PagingIteratorTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public PageableModelCollection answer(InvocationOnMock invocation) {
7171
Mockito.anyString(),
7272
Mockito.<Map<String, Object>>any(),
7373
Mockito.<Class<PageableModelCollection>>any(),
74-
Mockito.any(ApiResource.RequestType.class),
7574
Mockito.<RequestOptions>any());
7675
}
7776

@@ -144,9 +143,9 @@ public void testAutoPaginationWithParams() throws StripeException {
144143
assertEquals("pm_126", models.get(3).getId());
145144
assertEquals("pm_127", models.get(4).getId());
146145

147-
verifyRequest(ApiResource.RequestMethod.GET, "/v1/pageable_models", page0Params, null, options);
148-
verifyRequest(ApiResource.RequestMethod.GET, "/v1/pageable_models", page1Params, null, options);
149-
verifyRequest(ApiResource.RequestMethod.GET, "/v1/pageable_models", page2Params, null, options);
146+
verifyRequest(ApiResource.RequestMethod.GET, "/v1/pageable_models", page0Params, options);
147+
verifyRequest(ApiResource.RequestMethod.GET, "/v1/pageable_models", page1Params, options);
148+
verifyRequest(ApiResource.RequestMethod.GET, "/v1/pageable_models", page2Params, options);
150149
verifyNoMoreInteractions(networkSpy);
151150
}
152151
}

0 commit comments

Comments
 (0)