mirror of
https://github.com/tribufu/tribufu-java
synced 2026-05-06 14:57:27 +00:00
Add oauth2 client
This commit is contained in:
parent
61c562b63d
commit
92ea35896f
12 changed files with 124 additions and 56 deletions
26
lib/build.gradle
Normal file
26
lib/build.gradle
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
plugins {
|
||||
id "java-library"
|
||||
}
|
||||
|
||||
version = "0.0.4"
|
||||
archivesBaseName = "tribufu"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api "org.apache.commons:commons-math3:3.6.1"
|
||||
implementation "com.google.guava:guava:31.1-jre"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter:5.9.1"
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(11)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("test") {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
39
lib/src/main/java/com/tribufu/sdk/TribufuClient.java
Normal file
39
lib/src/main/java/com/tribufu/sdk/TribufuClient.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
package com.tribufu.sdk;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TribufuClient {
|
||||
public static final String VERSION = "0.0.0";
|
||||
|
||||
private final long id;
|
||||
private final String secret;
|
||||
private final HttpClient http;
|
||||
private Map<String, String> defaultHeaders;
|
||||
|
||||
public TribufuClient(long id, String secret) {
|
||||
this.id = id;
|
||||
this.secret = secret;
|
||||
|
||||
String targetTriple = "Java";
|
||||
String userAgent = String.format("Tribufu/%s (+https://api.tribufu.com; %s)", VERSION, targetTriple);
|
||||
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", userAgent);
|
||||
headers.put("X-Tribufu-Language", "java");
|
||||
headers.put("X-Tribufu-Version", VERSION);
|
||||
|
||||
this.defaultHeaders = headers;
|
||||
|
||||
this.http = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_2)
|
||||
.build();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
14
lib/src/test/java/com/tribufu/sdk/TribufuClientTest.java
Normal file
14
lib/src/test/java/com/tribufu/sdk/TribufuClientTest.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) TribuFu. All Rights Reserved
|
||||
|
||||
package com.tribufu.sdk;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TribufuClientTest {
|
||||
@Test
|
||||
void clientGetId() {
|
||||
TribufuClient client = new TribufuClient(0, "client_secret");
|
||||
assertEquals(0, client.getId());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue