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

com.ngrok.services.EndpointCompressionModule.scala Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
package com.ngrok.services

import com.ngrok.NgrokApiClient
import com.ngrok.definitions._
import io.circe.Encoder
import io.circe.syntax._
import scala.concurrent.{ExecutionContext, Future}

object EndpointCompressionModule {
  private case class EndpointCompressionModuleReplace(
    module: Option[EndpointCompression]
  )

  private object EndpointCompressionModuleReplace {
    implicit val encodeEndpointCompressionModuleReplace: Encoder[EndpointCompressionModuleReplace] =
      Encoder.encodeJsonObject.contramap(value =>
        List(
          value.module.map(_.asJson).map(("module", _))
        ).flatten.toMap.asJsonObject
      )
  }

}

/** An API client for [[EndpointCompressionModule]].
  *
  * See also https://ngrok.com/docs/api#api-endpoint-compression-module.
  */
class EndpointCompressionModule private[ngrok] (apiClient: NgrokApiClient)(implicit ec: ExecutionContext) {
  import EndpointCompressionModule._

  /** Sends an API request for the Replace operation.
    *
    * See also https://ngrok.com/docs/api#api-endpoint-compression-module-replace.
    *
    * @param id the value of the id parameter as a [[scala.Predef.String]]
    * @param module the value of the module parameter as a [[EndpointCompression]]
    * @return a [[scala.concurrent.Future]] encapsulating the API call's result
    */
  def replace(
    id: String,
    module: Option[EndpointCompression] = None
  ): Future[EndpointCompression] =
    apiClient.sendRequest[EndpointCompression](
      NgrokApiClient.HttpMethod.Put,
      s"/endpoint_configurations/$id/compression",
      List.empty,
      Option(
        EndpointCompressionModuleReplace(
          module
        ).asJson
      )
    )

  /** Sends an API request for the Get operation.
    *
    * See also https://ngrok.com/docs/api#api-endpoint-compression-module-get.
    *
    * @param id a resource identifier
    * @return a [[scala.concurrent.Future]] encapsulating the API call's result
    */
  def get(
    id: String
  ): Future[EndpointCompression] =
    apiClient.sendRequest[EndpointCompression](
      NgrokApiClient.HttpMethod.Get,
      s"/endpoint_configurations/$id/compression",
      List.empty,
      Option.empty
    )

  /** Sends an API request for the Delete operation.
    *
    * See also https://ngrok.com/docs/api#api-endpoint-compression-module-delete.
    *
    * @param id a resource identifier
    * @return a [[scala.concurrent.Future]] encapsulating the API call's result
    */
  def delete(
    id: String
  ): Future[Unit] =
    apiClient.sendRequest[Unit](
      NgrokApiClient.HttpMethod.Delete,
      s"/endpoint_configurations/$id/compression",
      List.empty,
      Option.empty
    )

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy