Skip to content

Commit 309ecde

Browse files
hdhayneCoveoy-lakhdar
authored andcommitted
docs: create Sample Code classes to create push and Catalog Source in Coveo and instance Java classes in different ways (#39)
1 parent 37dd38c commit 309ecde

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

samples/CreateCoveoSource.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import com.coveo.pushapiclient.CatalogSource;
2+
import com.coveo.pushapiclient.PlatformClient;
3+
import com.coveo.pushapiclient.PushSource;
4+
import com.coveo.pushapiclient.SourceVisibility;
5+
6+
import java.io.IOException;
7+
import java.net.http.HttpResponse;
8+
9+
10+
11+
public class CreateCoveoSource {
12+
public static void main(String[] args) {
13+
PlatformClient platformClient = new PlatformClient("my_api_key", "my_org_id");
14+
try {
15+
HttpResponse<String> pushResponse = PushSource.create(platformClient, "the_name_of_my_source", SourceVisibility.SHARED);
16+
System.out.println(String.format("Push Source creation status: %s", pushResponse.statusCode()));
17+
System.out.println(String.format("Push Source creation response: %s", pushResponse.body()));
18+
19+
HttpResponse<String> response = CatalogSource.create(platformClient, "the_name_of_my_source", SourceVisibility.SHARED);
20+
System.out.println(String.format("Catalog Source creation status: %s", response.statusCode()));
21+
System.out.println(String.format("Catalog Source creation response: %s", response.body()));
22+
23+
} catch (IOException | InterruptedException e) {
24+
e.printStackTrace();
25+
}
26+
}
27+
}

samples/CreateSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.net.http.HttpResponse;
99

10+
// TODO: LENS-844 - Deprecate class
1011
public class CreateSource {
1112
public static void main(String[] args) {
1213
PlatformUrl platformUrl = new PlatformUrlBuilder()

samples/InstantiateSource.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import com.coveo.pushapiclient.*;
2+
3+
import java.net.MalformedURLException;
4+
import java.net.URL;
5+
6+
public class InstantiateSource {
7+
public static void main(String[] args) throws MalformedURLException {
8+
//create source from url
9+
URL url = new URL("https://api-eu.cloud.coveo.com/push/v1/organizations/my-org-id/sources/my-source-id/documents");
10+
PushSource pushSource1 = new PushSource("my_api_key", url);
11+
CatalogSource catalogSource1 = new CatalogSource("my_api_key", url);
12+
13+
14+
//create source from platform config
15+
PlatformUrl platformUrl = new PlatformUrlBuilder().withEnvironment(Environment.PRODUCTION).withRegion(Region.EU).build();
16+
PushSource pushSource2 = PushSource.fromPlatformUrl("my_api_key","my_organization_id","my_source_id", platformUrl);
17+
CatalogSource catalogSource2 = CatalogSource.fromPlatformUrl("my_api_key","my_organization_id","my_source_id", platformUrl);
18+
19+
}
20+
}

0 commit comments

Comments
 (0)