Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor LiveStripeResponseGetter #1722

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/main/java/com/stripe/net/LiveStripeResponseGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ public LiveStripeResponseGetter(StripeResponseGetterOptions options, HttpClient
this.httpClient = (httpClient != null) ? httpClient : buildDefaultHttpClient();
}

private StripeRequest toStripeRequest(ApiRequest apiRequest) throws StripeException {
String fullUrl = fullUrl(apiRequest);

return new StripeRequest(
apiRequest.getMethod(),
fullUrl,
apiRequest.getParams(),
RequestOptions.merge(this.options, apiRequest.getOptions()));
}

@Override
@SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"})
public <T extends StripeObjectInterface> T request(ApiRequest apiRequest, Type typeToken)
throws StripeException {
String fullUrl = fullUrl(apiRequest);
StripeRequest request =
new StripeRequest(
apiRequest.getMethod(),
fullUrl,
apiRequest.getParams(),
RequestOptions.merge(this.options, apiRequest.getOptions()));

StripeRequest request = toStripeRequest(apiRequest);
StripeResponse response = httpClient.requestWithRetries(request);

int responseCode = response.code();
Expand Down Expand Up @@ -83,14 +88,7 @@ public <T extends StripeObjectInterface> T request(ApiRequest apiRequest, Type t

@Override
public InputStream requestStream(ApiRequest apiRequest) throws StripeException {
String fullUrl = fullUrl(apiRequest);

StripeRequest request =
new StripeRequest(
apiRequest.getMethod(),
fullUrl,
apiRequest.getParams(),
RequestOptions.merge(this.options, apiRequest.getOptions()));
StripeRequest request = toStripeRequest(apiRequest);
StripeResponseStream responseStream = httpClient.requestStreamWithRetries(request);

int responseCode = responseStream.code();
Expand Down Expand Up @@ -318,7 +316,7 @@ public void validateRequestOptions(RequestOptions options) {
}
}

private String fullUrl(ApiRequest apiRequest) {
private String fullUrl(BaseApiRequest apiRequest) {
BaseAddress baseAddress = apiRequest.getBaseAddress();
RequestOptions options = apiRequest.getOptions();
String relativeUrl = apiRequest.getPath();
Expand Down