All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.francwhite.raros.client.connector.MagnetApiService Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package io.github.francwhite.raros.client.connector;

import io.github.francwhite.raros.client.util.HttpRequestBuilder;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpResponse;
import java.util.concurrent.CompletableFuture;

class MagnetApiService implements MagnetService {
  private record MagnetState(Boolean active) {
  }

  private final URI apiUri;

  public MagnetApiService(URI apiBaseUri) {
    this.apiUri = apiBaseUri.resolve("/api/magnet");
  }

  @Override
  public CompletableFuture setMagnetState(Boolean active) {
    var magnetState = new MagnetState(active);

    var request = HttpRequestBuilder.buildJsonPOST(apiUri, magnetState);

    return HttpClient.newHttpClient()
      .sendAsync(request, HttpResponse.BodyHandlers.discarding())
      .thenApply(HttpResponse::body);

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy