Skip to content

Commit

Permalink
feat(specs): rename composition to composition-full (private) and add…
Browse files Browse the repository at this point in the history
… composition (public) (generated)

algolia/api-clients-automation#4357

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Emmanuel Krebs <e-krebs@users.noreply.github.com>
Co-authored-by: shortcuts <vannicattec@gmail.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
4 people committed Jan 22, 2025
1 parent 4c7995d commit 5f536fb
Show file tree
Hide file tree
Showing 61 changed files with 2,619 additions and 0 deletions.
146 changes: 146 additions & 0 deletions src/main/scala/algoliasearch/api/CompositionClient.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/** Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on
* https://github.com/algolia/api-clients-automation. DO NOT EDIT.
*/
package algoliasearch.api

import algoliasearch.composition.ErrorBase
import algoliasearch.composition.RequestBody
import algoliasearch.composition.SearchForFacetValuesRequest
import algoliasearch.composition.SearchForFacetValuesResponse
import algoliasearch.composition.SearchResponse
import algoliasearch.composition._
import algoliasearch.ApiClient
import algoliasearch.api.CompositionClient.hosts
import algoliasearch.api.CompositionClient.readTimeout
import algoliasearch.api.CompositionClient.writeTimeout
import algoliasearch.api.CompositionClient.connectTimeout
import algoliasearch.config._
import algoliasearch.internal.util._

import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Random

object CompositionClient {

/** Creates a new CompositionClient instance using default hosts.
*
* @param appId
* application ID
* @param apiKey
* api key
*
* @param clientOptions
* client options
*/
def apply(
appId: String,
apiKey: String,
clientOptions: ClientOptions = ClientOptions()
) = new CompositionClient(
appId = appId,
apiKey = apiKey,
clientOptions = clientOptions
)

private def readTimeout(): Duration = {
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(appId: String): Seq[Host] = {
val commonHosts = Random.shuffle(
List(
Host(appId + "-1.algolianet.com", Set(CallType.Read, CallType.Write)),
Host(appId + "-2.algolianet.com", Set(CallType.Read, CallType.Write)),
Host(appId + "-3.algolianet.com", Set(CallType.Read, CallType.Write))
)
)
List(
Host(appId + "-dsn.algolia.net", Set(CallType.Read)),
Host(appId + ".algolia.net", Set(CallType.Write))
) ++ commonHosts
}
}

class CompositionClient(
appId: String,
apiKey: String,
clientOptions: ClientOptions = ClientOptions()
) extends ApiClient(
appId = appId,
apiKey = apiKey,
clientName = "Composition",
defaultHosts = hosts(appId),
defaultReadTimeout = readTimeout(),
defaultWriteTimeout = writeTimeout(),
defaultConnectTimeout = connectTimeout(),
formats = JsonSupport.format,
options = clientOptions
) {

/** Runs a query on a single composition and returns matching results.
*
* Required API Key ACLs:
* - search
*
* @param compositionID
* Unique Composition ObjectID.
*/
def search(compositionID: String, requestBody: RequestBody, requestOptions: Option[RequestOptions] = None)(implicit
ec: ExecutionContext
): Future[SearchResponse] = Future {
requireNotNull(compositionID, "Parameter `compositionID` is required when calling `search`.")
requireNotNull(requestBody, "Parameter `requestBody` is required when calling `search`.")

val request = HttpRequest
.builder()
.withMethod("POST")
.withPath(s"/1/compositions/${escape(compositionID)}/run")
.withBody(requestBody)
.withRead(true)
.build()
execute[SearchResponse](request, requestOptions)
}

/** Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet
* values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for
* facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**.
*
* Required API Key ACLs:
* - search
*
* @param compositionID
* Unique Composition ObjectID.
* @param facetName
* Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting`
* index setting with the `searchable()` modifier.
*/
def searchForFacetValues(
compositionID: String,
facetName: String,
searchForFacetValuesRequest: Option[SearchForFacetValuesRequest] = None,
requestOptions: Option[RequestOptions] = None
)(implicit ec: ExecutionContext): Future[SearchForFacetValuesResponse] = Future {
requireNotNull(compositionID, "Parameter `compositionID` is required when calling `searchForFacetValues`.")
requireNotNull(facetName, "Parameter `facetName` is required when calling `searchForFacetValues`.")

val request = HttpRequest
.builder()
.withMethod("POST")
.withPath(s"/1/compositions/${escape(compositionID)}/facets/${escape(facetName)}/query")
.withBody(searchForFacetValuesRequest)
.withRead(true)
.build()
execute[SearchForFacetValuesResponse](request, requestOptions)
}

}
48 changes: 48 additions & 0 deletions src/main/scala/algoliasearch/composition/AroundPrecision.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

import org.json4s._

/** Precision of a coordinate-based search in meters to group results with similar distances. The Geo ranking criterion
* considers all matches within the same range of distances to be equal.
*/
sealed trait AroundPrecision

object AroundPrecision {

case class IntValue(value: Int) extends AroundPrecision
case class SeqOfRange(value: Seq[Range]) extends AroundPrecision

def apply(value: Int): AroundPrecision = {
AroundPrecision.IntValue(value)
}
def apply(value: Seq[Range]): AroundPrecision = {
AroundPrecision.SeqOfRange(value)
}

}

object AroundPrecisionSerializer extends Serializer[AroundPrecision] {
override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), AroundPrecision] = {

case (TypeInfo(clazz, _), json) if clazz == classOf[AroundPrecision] =>
json match {
case JInt(value) => AroundPrecision.IntValue(value.toInt)
case JArray(value) if value.forall(_.isInstanceOf[JArray]) => AroundPrecision.SeqOfRange(value.map(_.extract))
case _ => throw new MappingException("Can't convert " + json + " to AroundPrecision")
}
}

override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { case value: AroundPrecision =>
value match {
case AroundPrecision.IntValue(value) => JInt(value)
case AroundPrecision.SeqOfRange(value) => JArray(value.map(Extraction.decompose).toList)
}
}
}
50 changes: 50 additions & 0 deletions src/main/scala/algoliasearch/composition/AroundRadius.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

import algoliasearch.composition.AroundRadiusAll._

import org.json4s._

/** Maximum radius for a search around a central location. This parameter works in combination with the `aroundLatLng`
* and `aroundLatLngViaIP` parameters. By default, the search radius is determined automatically from the density of
* hits around the central location. The search radius is small if there are many hits close to the central
* coordinates.
*/
sealed trait AroundRadius

trait AroundRadiusTrait extends AroundRadius

object AroundRadius {

case class IntValue(value: Int) extends AroundRadius

def apply(value: Int): AroundRadius = {
AroundRadius.IntValue(value)
}

}

object AroundRadiusSerializer extends Serializer[AroundRadius] {
override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), AroundRadius] = {

case (TypeInfo(clazz, _), json) if clazz == classOf[AroundRadius] =>
json match {
case JInt(value) => AroundRadius.IntValue(value.toInt)
case value: JString => Extraction.extract[AroundRadiusAll](value)
case _ => throw new MappingException("Can't convert " + json + " to AroundRadius")
}
}

override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { case value: AroundRadius =>
value match {
case AroundRadius.IntValue(value) => JInt(value)
case value: AroundRadiusAll => JString(value.toString)
}
}
}
38 changes: 38 additions & 0 deletions src/main/scala/algoliasearch/composition/AroundRadiusAll.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

import org.json4s._

sealed trait AroundRadiusAll extends AroundRadiusTrait

/** Return all records with a valid `_geoloc` attribute. Don't filter by distance.
*/
object AroundRadiusAll {
case object All extends AroundRadiusAll {
override def toString = "all"
}
val values: Seq[AroundRadiusAll] = Seq(All)

def withName(name: String): AroundRadiusAll = AroundRadiusAll.values
.find(_.toString == name)
.getOrElse(throw new MappingException(s"Unknown AroundRadiusAll value: $name"))
}

class AroundRadiusAllSerializer
extends CustomSerializer[AroundRadiusAll](_ =>
(
{
case JString(value) => AroundRadiusAll.withName(value)
case JNull => null
},
{ case value: AroundRadiusAll =>
JString(value.toString)
}
)
)
15 changes: 15 additions & 0 deletions src/main/scala/algoliasearch/composition/Banner.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

/** Banner with image and link to redirect users.
*/
case class Banner(
image: Option[BannerImage] = scala.None,
link: Option[BannerLink] = scala.None
)
15 changes: 15 additions & 0 deletions src/main/scala/algoliasearch/composition/BannerImage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

/** Image to show inside a banner.
*/
case class BannerImage(
urls: Option[Seq[BannerImageUrl]] = scala.None,
title: Option[String] = scala.None
)
14 changes: 14 additions & 0 deletions src/main/scala/algoliasearch/composition/BannerImageUrl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

/** URL for an image to show inside a banner.
*/
case class BannerImageUrl(
url: Option[String] = scala.None
)
14 changes: 14 additions & 0 deletions src/main/scala/algoliasearch/composition/BannerLink.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** Composition API Composition API.
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.composition

/** Link for a banner defined in the Merchandising Studio.
*/
case class BannerLink(
url: Option[String] = scala.None
)
Loading

0 comments on commit 5f536fb

Please sign in to comment.