Skip to content

ariels2/public-api-sdk-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java API client for Segment Public API

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

Segment Public API

  • API version: 32.0.2

The Segment Public API helps you manage your Segment Workspaces and its resources. You can use the API to perform CRUD (create, read, update, delete) operations at no extra charge. This includes working with resources such as Sources, Destinations, Warehouses, Tracking Plans, and the Segment Destinations and Sources Catalogs.

All CRUD endpoints in the API follow REST conventions and use standard HTTP methods. Different URL endpoints represent different resources in a Workspace.

See the next sections for more information on how to use the Segment Public API.

For more information, please visit https://docs.segmentapis.com

Automatically generated by the OpenAPI Generator

Requirements

Building the API client library requires:

  1. Java 1.8+
  2. Maven (3.8.3+)/Gradle (7.2+)

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.segment.publicapi</groupId>
  <artifactId>segment-publicapi</artifactId>
  <version>32.0.2</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

  repositories {
    mavenCentral()     // Needed if the 'segment-publicapi' jar has been published to maven central.
    mavenLocal()       // Needed if the 'segment-publicapi' jar has been published to the local maven repo.
  }

  dependencies {
     implementation "com.segment.publicapi:segment-publicapi:32.0.2"
  }

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/segment-publicapi-32.0.2.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction and execute the following Java code:

// Import classes:
import com.segment.publicapi.ApiClient;
import com.segment.publicapi.ApiException;
import com.segment.publicapi.Configuration;
import com.segment.publicapi.auth.*;
import com.segment.publicapi.models.*;
import com.segment.publicapi.api.SourcesApi;
import com.segment.publicapi.api.WorkspacesApi;
import java.math.BigDecimal;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://api.segmentapis.com");
    
    // Configure HTTP bearer authorization: token
    HttpBearerAuth token = (HttpBearerAuth) defaultClient.getAuthentication("token");
    token.setBearerToken("BEARER TOKEN");

    ApiCallsApi apiInstance = new ApiCallsApi(defaultClient);
    String period = "period_example"; // String | The start of the usage month in the ISO-8601 format.  This parameter exists in alpha.
    PaginationInput pagination = new HashMap(); // PaginationInput | Pagination input for per Source API calls counts.  This parameter exists in alpha.
    
    // Make an API call without Pagination
    try {
        WorkspacesApi apiInstance = new WorkspacesApi(defaultClient);
        GetWorkspace200Response workspaceResponse = apiInstance.getWorkspace();
    } catch (ApiException e) {
        System.err.println("Exception when calling WorkspacesApi#getWorkspace");
        System.err.println("Status code: " + e.getCode());
        System.err.println("Reason: " + e.getResponseBody());
        System.err.println("Response headers: " + e.getResponseHeaders());
        e.printStackTrace();
    }

    // Make an API call with Pagination
    try {
        SourcesApi sourceApiInstance = new SourcesApi(defaultClient);
        PaginationInput paginationInput = new PaginationInput();
        paginationInput.count(BigDecimal.valueOf(20));
        String current = null;
        do {
            paginationInput.setCursor(current);
            ListSources200Response sourcesResponse = sourceApiInstance.listSources(paginationInput);
            current = sourcesResponse.getData().getPagination().getNext();
        } while(current != null);
    } catch (ApiException e) {
        System.err.println("Exception when calling SourcesApi#sourceApiInstance");
        System.err.println("Status code: " + e.getCode());
        System.err.println("Reason: " + e.getResponseBody());
        System.err.println("Response headers: " + e.getResponseHeaders());
        e.printStackTrace();
    }
  }
}

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.

Author

[email protected]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%