Java Code Examples for com.google.api.client.http.HttpRequestFactory#buildDeleteRequest()
The following examples show how to use
com.google.api.client.http.HttpRequestFactory#buildDeleteRequest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MendeleyClient.java From slr-toolkit with Eclipse Public License 1.0 | 6 votes |
/** * This methods is used to delete a Mendeley documents via the DELETE https://api.mendeley.com/documents/{id} endpoint. * @param document Pass the document that needs to be deleted from Mendeley */ public void deleteDocument(MendeleyDocument document ){ refreshTokenIfNecessary(); HttpRequestFactory requestFactory = new ApacheHttpTransport().createRequestFactory(); HttpRequest request; HttpRequest delete_request; Gson gson = new GsonBuilder().create(); String json_body = gson.toJson(document); String document_id = document.getId(); String resource_url = "https://api.mendeley.com/documents/" + document_id; GenericUrl gen_url = new GenericUrl(resource_url); try { final HttpContent content = new ByteArrayContent("application/json", json_body.getBytes("UTF8") ); delete_request = requestFactory.buildDeleteRequest(gen_url); delete_request.getHeaders().setAuthorization("Bearer " + access_token); delete_request.getHeaders().setContentType("application/vnd.mendeley-document.1+json"); String rawResponse = delete_request.execute().parseAsString(); } catch (IOException e) { e.printStackTrace(); } }
Example 2
Source File: CredentialTest.java From google-oauth-java-client with Apache License 2.0 | 6 votes |
private void subtestRefreshToken_request(AccessTokenTransport transport, int expectedCalls) throws Exception { Credential credential = new Credential.Builder(BearerToken.queryParameterAccessMethod()).setTransport(transport) .setJsonFactory(JSON_FACTORY) .setTokenServerUrl(TOKEN_SERVER_URL) .setClientAuthentication(new BasicAuthentication(CLIENT_ID, CLIENT_SECRET)) .build() .setRefreshToken(REFRESH_TOKEN) .setAccessToken(ACCESS_TOKEN); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); HttpRequest request = requestFactory.buildDeleteRequest(HttpTesting.SIMPLE_GENERIC_URL); request.setThrowExceptionOnExecuteError(false); request.execute(); assertEquals(expectedCalls, transport.calls); }
Example 3
Source File: CredentialTest.java From google-oauth-java-client with Apache License 2.0 | 5 votes |
private HttpRequest subtestConstructor(Credential credential) throws Exception { MockHttpTransport transport = new MockHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); HttpRequest request = requestFactory.buildDeleteRequest(HttpTesting.SIMPLE_GENERIC_URL); request.execute(); return request; }