diff --git a/java-webrisk/README.md b/java-webrisk/README.md index 6b3daa8c6443..2264c05190ab 100644 --- a/java-webrisk/README.md +++ b/java-webrisk/README.md @@ -107,16 +107,6 @@ use this Web Risk Client Library. -## Samples - -Samples are in the [`samples/`](https://github.com/googleapis/java-webrisk/tree/main/samples) directory. - -| Sample | Source Code | Try it | -| --------------------------- | --------------------------------- | ------ | -| Search Uri Example | [source code](https://github.com/googleapis/java-webrisk/blob/main/samples/snippets/src/main/java/webrisk/SearchUriExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-webrisk&page=editor&open_in_editor=samples/snippets/src/main/java/webrisk/SearchUriExample.java) | -| Submit Uri Example | [source code](https://github.com/googleapis/java-webrisk/blob/main/samples/snippets/src/main/java/webrisk/SubmitUriExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-webrisk&page=editor&open_in_editor=samples/snippets/src/main/java/webrisk/SubmitUriExample.java) | - - ## Troubleshooting diff --git a/java-webrisk/samples/snippets/src/main/java/webrisk/SearchUriExample.java b/java-webrisk/samples/snippets/src/main/java/webrisk/SearchUriExample.java deleted file mode 100644 index 3791a305fbbb..000000000000 --- a/java-webrisk/samples/snippets/src/main/java/webrisk/SearchUriExample.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package webrisk; - -import com.google.cloud.webrisk.v1.WebRiskServiceClient; -import com.google.webrisk.v1.SearchUrisRequest; -import com.google.webrisk.v1.SearchUrisResponse; -import com.google.webrisk.v1.ThreatType; -import java.io.IOException; - -public class SearchUriExample { - - public static void searchUriExample() throws IOException { - // The URL to be searched - String uri = "http://testsafebrowsing.appspot.com/s/malware.html"; - SearchUrisResponse response = searchUriExample(uri); - } - - // [START webrisk_search_uri] - public static SearchUrisResponse searchUriExample(String uri) throws IOException { - // create-webrisk-client - try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) { - // Query the url for a specific threat type - SearchUrisRequest searchUrisRequest = - SearchUrisRequest.newBuilder().addThreatTypes(ThreatType.MALWARE).setUri(uri).build(); - SearchUrisResponse searchUrisResponse = webRiskServiceClient.searchUris(searchUrisRequest); - webRiskServiceClient.shutdownNow(); - if (!searchUrisResponse.getThreat().getThreatTypesList().isEmpty()) { - System.out.println("The URL has the following threat : "); - System.out.println(searchUrisResponse); - } else { - System.out.println("The URL is safe!"); - } - - return searchUrisResponse; - } - } - // [END webrisk_search_uri] -} diff --git a/java-webrisk/samples/snippets/src/main/java/webrisk/SubmitUriExample.java b/java-webrisk/samples/snippets/src/main/java/webrisk/SubmitUriExample.java deleted file mode 100644 index 93fb56049950..000000000000 --- a/java-webrisk/samples/snippets/src/main/java/webrisk/SubmitUriExample.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package webrisk; - -import com.google.cloud.webrisk.v1.WebRiskServiceClient; -import com.google.webrisk.v1.CreateSubmissionRequest; -import com.google.webrisk.v1.Submission; -import java.io.IOException; - -public class SubmitUriExample { - - public static void submitUriExample() throws IOException { - // The URL to be submitted - String uri = "http://testsafebrowsing.appspot.com/s/malware.html"; - Submission response = submitUriExample(uri); - } - - // [START webrisk_submit_uri] - public static Submission submitUriExample(String uri) throws IOException { - // create-webrisk-client - try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) { - Submission submission = Submission.newBuilder().setUri(uri).build(); - CreateSubmissionRequest submissionRequest = - CreateSubmissionRequest.newBuilder() - .setParent("projects/your-project-id") - .setSubmission(submission) - .build(); - Submission submissionResponse = webRiskServiceClient.createSubmission(submissionRequest); - webRiskServiceClient.shutdownNow(); - System.out.println("The submitted " + submissionResponse); - return submissionResponse; - } - } - // [END webrisk_submit_uri] -} diff --git a/java-webrisk/samples/snippets/src/test/java/webrisk/SearchUriExampleTest.java b/java-webrisk/samples/snippets/src/test/java/webrisk/SearchUriExampleTest.java deleted file mode 100644 index 0483a1d024d5..000000000000 --- a/java-webrisk/samples/snippets/src/test/java/webrisk/SearchUriExampleTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package webrisk; - -import com.google.common.truth.Truth; -import com.google.webrisk.v1.SearchUrisResponse; -import com.google.webrisk.v1.ThreatType; -import java.io.IOException; -import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class SearchUriExampleTest { - @Test - public void testSearchWithThreat() throws IOException { - // The URL to be searched - String uri = "http://testsafebrowsing.appspot.com/s/malware.html"; - SearchUrisResponse actualResponse = SearchUriExample.searchUriExample(uri); - List type = actualResponse.getThreat().getThreatTypesList(); - Truth.assertThat(type).contains(ThreatType.MALWARE); - } - - @Test - public void testSearchWithoutThreat() throws IOException { - // The URL to be searched - String uri = "http://testsafebrowsing.appspot.com/malware.html"; - SearchUrisResponse actualResponse = SearchUriExample.searchUriExample(uri); - List type = actualResponse.getThreat().getThreatTypesList(); - Truth.assertThat(type).isEmpty(); - } -} diff --git a/java-webrisk/samples/snippets/src/test/java/webrisk/SubmitUriExampleTest.java b/java-webrisk/samples/snippets/src/test/java/webrisk/SubmitUriExampleTest.java deleted file mode 100644 index 6d7c2fba3741..000000000000 --- a/java-webrisk/samples/snippets/src/test/java/webrisk/SubmitUriExampleTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package webrisk; - -import com.google.common.truth.Truth; -import com.google.webrisk.v1.Submission; -import java.io.IOException; -import org.junit.Test; - -public class SubmitUriExampleTest { - @Test - public void testSumbitUriExample() throws IOException { - String testUri = "http://testsafebrowsing.appspot.com/s/malware.html"; - Submission actualSubmission = SubmitUriExample.submitUriExample(testUri); - Truth.assertThat(actualSubmission.getUri()).isEqualTo(testUri); - } -}