eternaltwin

Haxe client for the Eternaltwin API
https://github.com/cmnemoi/eternaltwin-client-haxe

To install, run:

haxelib install eternaltwin 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Eternaltwin

Eternaltwin API client for Haxe.

Supports all Haxe server targets: JavaScript (Node.js), Neko, HashLink, C++, Python.

Installation

Install using haxelib:

haxelib install eternaltwin

Then add the dependency in your .hxml build file:

-lib eternaltwin
-lib tink_core

Getting started

import eternaltwin.client.Auth;
import eternaltwin.client.HttpEtwinClient;
import eternaltwin.user.UserId;
import tink.core.Outcome;

class Main {
    static function main() {
        var client = new HttpEtwinClient("https://eternaltwin.org");
        var userId = new UserId("9f310484-963b-446b-af69-797feec6813f");
        client.getUser(Auth.guest(), userId).handle(function(outcome) {
            switch (outcome) {
                case Success(user): trace(user);
                case Failure(error): trace("Error: " + error.message);
            }
        });
    }
}

Using an access token

var auth = Auth.fromToken("my-oauth-access-token");
client.getSelf(auth).handle(function(outcome) {
    switch (outcome) {
        case Success(ctx):
            switch (ctx) {
                case UserAuth(u): trace("Logged in as: " + u.user.displayName);
                default: trace(ctx);
            }
        case Failure(error): trace("Error: " + error.message);
    }
});

API

EtwinClient interface

MethodSignatureDescription
getSelf(auth: Auth) -> Promise<AuthContext>Get the auth context for the current session
getUser(auth: Auth, userId: UserId) -> Promise<User>Get a user by ID

Auth helper

MethodDescription
Auth.guest()Unauthenticated (no Authorization header)
Auth.fromToken(key)Bearer token authentication

Multi-target compilation

haxe build.hxml                         # JS (primary)
haxe build.hxml -neko build/etwin.n     # Neko
haxe build.hxml -hl build/etwin.hl      # HashLink
haxe build.hxml -cpp build/cpp          # C++

Tasks

  • haxe test.hxml: Run the test suite
  • haxe build.hxml: Build the library (JS target)

License

AGPL-3.0-or-later

Contributors
cmnemoi
Version
1.0.0
Published
9 months ago
Dependencies
License
GPL

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂