SDK

how to initialize GS2-SDK

To initialize the SDK, you need to create the Credential and Session objects.

Credential

An object representing a GS2 API key. The class BasicGs2Credential is defined and used when using the API with clientId / clientSecret.

BasicGs2Credential Request

Argument NameDescription
clientIdCredential Information
clientSecretCredential Information

Session

There are two types of sessions: Gs2RestSession, which uses HTTP communication, and Gs2WebSocketSession, which uses WebSocket communication. Some programming languages do not support Gs2WebSocketSession, and Gs2WebSocketSession cannot be used for requests with large payloads, so if you do not need push notifications from the server, use Gs2 RestSession if you do not need push notification from the server.

Gs2RestSession Request

Argument NameDescription
credentialCredential object
regionGS2 Region to connect to

Gs2WebSocketSession Request

Argument NameDescription
credentialCredential object
regionGS2 Region to connect to

Initialization

The created Session object must be connected before it can be used.

The Session object has a connection API that can be called to establish a connection.

    session := core.Gs2RestSession{
        Credential: &core.BasicGs2Credential{
            ClientId: "your client id",
            ClientSecret: "your client secret",
        },
        Region: core.ApNortheast1,
    }

    if err := session.Connect(); err != nil {
        panic("error occurred")
    }
    $session = new Gs2RestSession(
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        Region::AP_NORTHEAST_1
    );

    $session->open();
    Gs2RestSession session = new Gs2RestSession(
        Region.AP_NORTHEAST_1,
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        )
    );
    session.connect();
    var session = new Gs2RestSession(
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        Region.ApNortheast1
    );
    yield return session.Open();
    const session = new Gs2Core.Gs2RestSession(
        "ap-northeast-1",
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        )
    );
    await session.connect();
    session = core.Gs2RestSession(
        core.BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        "ap-northeast-1",
    )
    session.connect()

Chaos mode

By calling the SDK initialization process with chaos mode applied, API requests can be made to fail with a certain probability. Development can proceed using clients with chaos mode enabled to ensure robust error handling.

    var session = new ChaosGs2RestSession(
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        0.1f, // 10% chance of error requiring a retry when making an API request
        Region.ApNortheast1
    );
    yield return session.Open();

Clients for microservices

A client is provided for each of the various microservices offered by GS2. There are also clients for each communication protocol, such as Gs2AccountRestClient and Gs2AccountWebSocketClient, which require Gs2RestSession and Gs2 WebSocketSession respectively.

Gs2AccountRestClient Request

Argument NameDescription
sessionGs2RestSession

Gs2AccountWebSocketClient Request

Argument NameDescription
sessionGs2WebSocketSession

Implementation Example

client := account.Gs2AccountRestClient{
    Session: &session,
}
$client = new Gs2AccountRestClient($session);
Gs2AccountRestClient client = new Gs2AccountRestClient(session);
var client = new Gs2AccountRestClient(session);
const client = new Gs2Account.Gs2AccountRestClient(session);
client = account.Gs2AccountRestClient(session)