private ApiClient createApiClient() { ApiClient apiClient = new ApiClient(); apiClient.setBasePath(finapiConnectionUrl); apiClient.setAccessToken(clientToken != null ? clientToken.getAccessToken() : null); return apiClient; }
/** * Set the User-Agent header's value (by adding to the default header map). * * @param userAgent HTTP request's user agent * @return ApiClient */ public ApiClient setUserAgent(String userAgent) { addDefaultHeader("User-Agent", userAgent); return this; }
queryParams.addAll(apiClient.parameterToPairs("", "id", id)); final String accept = apiClient.selectHeaderAccept(accepts); final String contentType = apiClient.selectHeaderContentType(contentTypes); String response = apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames); if(response != null){ return (String) apiClient.deserialize(response, "", String.class);
private ApiClient createUserApiClient() { ApiClient apiClient = new ApiClient(); apiClient.setBasePath(finapiConnectionUrl); return apiClient; }
.replaceAll("\\{" + "userId" + "\\}", apiClient.escapeString(userId.toString())); final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); localVarHeaderParams.put("Content-Type", localVarContentType); apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { @Override public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
updateParamsForAuth(authNames, queryParams, headerParams); final String url = buildUrl(path, queryParams, collectionQueryParams); final Request.Builder reqBuilder = new Request.Builder().url(url); processHeaderParams(headerParams, reqBuilder); reqBody = null; } else if ("application/x-www-form-urlencoded".equals(contentType)) { reqBody = buildRequestBodyFormEncoding(formParams); } else if ("multipart/form-data".equals(contentType)) { reqBody = buildRequestBodyMultipart(formParams); } else if (body == null) { if ("DELETE".equals(method)) { reqBody = serialize(body, contentType);
updateParamsForAuth(authNames, queryParams, headerParams); Client client = getClient(); for (Pair queryParam : queryParams){ if (!queryParam.getName().isEmpty()) { b.append(escapeString(queryParam.getName())); b.append("="); b.append(escapeString(queryParam.getValue())); b.append("&"); if (contentType.startsWith("application/x-www-form-urlencoded")) { String encodedFormParams = this .getXWWWFormUrlencodedParams(formParams); response = builder.type(contentType).post(ClientResponse.class, encodedFormParams); response = builder.type(contentType).post(ClientResponse.class, serialize(body)); .getXWWWFormUrlencodedParams(formParams); response = builder.type(contentType).put(ClientResponse.class, encodedFormParams); } else if(body == null) { response = builder.put(ClientResponse.class, serialize(body)); } else { response = builder.type(contentType).put(ClientResponse.class, serialize(body)); if ("application/x-www-form-urlencoded".equals(contentType)) { String encodedFormParams = this
params.add(new Pair(name, escapeString(parameterToString(item)))); delimiter = escapeString(" "); } else if ("tsv".equals(collectionFormat)) { delimiter = escapeString("\t"); } else if ("pipes".equals(collectionFormat)) { delimiter = escapeString("|"); for (Object item : value) { sb.append(delimiter); sb.append(escapeString(parameterToString(item)));
@Test(expected = ApiException.class) public void refreshTokenTestFailsIfRefreshTokenIsInvalid() throws ApiException { DefaultApi api = new DefaultApi(new ApiClient(), clientId, clientSecret); String refreshToken = "1232131"; api.refreshAccessToken(refreshToken); }
/** * Formats the specified query parameter to a list containing a single {@code Pair} object. * * Note that {@code value} must not be a collection. * * @param name The name of the parameter. * @param value The value of the parameter. * @return A list containing a single {@code Pair} object. */ public List<Pair> parameterToPair(String name, Object value) { List<Pair> params = new ArrayList<Pair>(); // preconditions if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params; params.add(new Pair(name, parameterToString(value))); return params; }
/** * Build a multipart (file uploading) request body with the given form parameters, * which could contain text fields and file fields. * * @param formParams Form parameters in the form of Map * @return RequestBody */ public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) { MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM); for (Entry<String, Object> param : formParams.entrySet()) { if (param.getValue() instanceof File) { File file = (File) param.getValue(); Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\""); MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file)); mpBuilder.addPart(partHeaders, RequestBody.create(mediaType, file)); } else { Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\""); mpBuilder.addPart(partHeaders, RequestBody.create(null, parameterToString(param.getValue()))); } } return mpBuilder.build(); }
public ApiClient() { // Use ISO 8601 format for date and datetime. // See https://en.wikipedia.org/wiki/ISO_8601 this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); // Use UTC as the default time zone. this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // Set default User-Agent. setUserAgent("Java-Swagger"); // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap<String, Authentication>(); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); }
return deserialize(response, returnType);
.replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); localVarHeaderParams.put("Content-Type", localVarContentType); apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { @Override public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
url.append("&"); String value = parameterToString(param.getValue()); url.append(escapeString(param.getName())).append("=").append(escapeString(value)); url.append("&"); String value = parameterToString(param.getValue()); url.append(escapeString(param.getName())).append("=").append(value);
@Test(expected = ApiException.class) public void authorizeTestFailsIfCodeIsNull() throws ApiException { DefaultApi api = new DefaultApi(new ApiClient(), clientId, clientSecret); String code = null; api.authorize(code, redirectUri); }
/** * Set header parameters to the request builder, including default headers. * * @param headerParams Header parameters in the ofrm of Map * @param reqBuilder Reqeust.Builder */ public void processHeaderParams(Map<String, String> headerParams, Request.Builder reqBuilder) { for (Entry<String, String> param : headerParams.entrySet()) { reqBuilder.header(param.getKey(), parameterToString(param.getValue())); } for (Entry<String, String> header : defaultHeaderMap.entrySet()) { if (!headerParams.containsKey(header.getKey())) { reqBuilder.header(header.getKey(), parameterToString(header.getValue())); } } }
public ApiClient() { httpClient = new OkHttpClient(); verifyingSsl = true; json = new JSON(); // Set default User-Agent. setUserAgent("Swagger-Codegen/1.0.0/java"); // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap<String, Authentication>(); authentications.put("finapi_auth", new OAuth()); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); }
.replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString())); final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); localVarHeaderParams.put("Content-Type", localVarContentType); apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { @Override public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException { return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
"application/json" }; final String accept = apiClient.selectHeaderAccept(accepts); final String contentType = apiClient.selectHeaderContentType(contentTypes); String response = apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames); if(response != null){ return (List<Todo>) apiClient.deserialize(response, "array", Todo.class);