Skip to content

Commit

Permalink
Merge pull request #106 from algolia/develop
Browse files Browse the repository at this point in the history
Merge 1.1.0 in master
  • Loading branch information
q-litzler authored Jul 29, 2019
2 parents 0324378 + ef33663 commit 28611ac
Show file tree
Hide file tree
Showing 134 changed files with 4,475 additions and 783 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 1.1.0

- Kotlin version 1.3.41
- Ktor version 1.2.3-rc
- Added `enableABTest` as `Query` parameter
- Added `similarQuery` as `Query` parameter
- Added `advancedSyntaxFeatures` as `Query` parameter
- Added `index.exists()` method
- New `AlgoliaSearchClient` object exposes library version constant
- Added `Compression` feature. `Gzip` compression is enabled by default.
- Default `readTimeout` has been increased to 5 seconds
- It is now possible to configure `HttpClientConfig` in `Configuration`
- Added `ClientPlaces` to access Algolia Places endpoints. See this [file](docs/Places.md) for getting starting with Places.
- `QueryLanguage` is renamed to `Language`
- Fixed a bug in `browseAllABTests` methods
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Algolia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI


plugins {
id("kotlin-multiplatform") version "1.3.31"
id("kotlinx-serialization") version "1.3.31"
id("kotlin-multiplatform") version "1.3.41"
id("kotlinx-serialization") version "1.3.41"
id("maven-publish")
id("com.jfrog.bintray") version "1.8.4"
id("com.github.kukuhyoniatmoko.buildconfigkotlin") version "1.0.5"
Expand Down Expand Up @@ -156,4 +157,7 @@ tasks {
setPublications("jvm", "metadata")
}
}
withType<KotlinCompile> {
dependsOn("generateMetadataBuildConfigKotlin")
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Ktor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ object Ktor : Dependency {

override val group = "io.ktor"
override val artifact = "ktor"
override val version = "1.2.1"
override val version = "1.2.3-rc"
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Library.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ object Library: Dependency {

override val group = "com.algolia"
override val artifact = "algoliasearch-client-kotlin"
override val version = "1.0.0"
override val version = "1.1.0"
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Serialization.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Serialization : Dependency {

override val version = "0.11.0"
override val version = "0.11.1"
override val group = "org.jetbrains.kotlinx"
override val artifact = "kotlinx-serialization"
}
109 changes: 109 additions & 0 deletions docs/Places.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Places client

Algolia Places provides a fast, distributed and easy way to use address search.

## Pricing

#### Rate limit

The Algolia Places API enforces 30 queries per second. [Contact us](https://community.algolia.com/places/contact.html) if you need more.

If you're calling the API from your backend, the rate-limits computation is then based on the source IP.

#### Plans

- Free: 1000 requests / day [Sign Up](https://www.algolia.com/users/sign_up/places)
- Free, with authentication: 100 000 requests / month [Sign Up](https://www.algolia.com/users/sign_up/places)
- Paying: $0.40 per 1000 requests [Sign Up](https://www.algolia.com/users/sign_up/places)
- Up to unlimited: [Contact us](https://community.algolia.com/places/contact.html)


Visit our [website](https://community.algolia.com/places/pricing.html).

## Usage

#### Unauthenticated

You can use Algolia Places without authentication. Limited to 1000 requests per day.

```kotlin
val client = ClientPlaces()
```

#### Authenticated

Pass an `ApplicationID` and an `APIKey` to the `ClientPlaces` for authenticated usage.

```kotlin
val client = ClientPlaces(
ApplicationID("YourApplicationID"),
APIKey("YourPlacesAPIKey")
)
```

#### Search places for multiple languages

By default, the response of `searchPlaces` contains translations in all languages.

```kotlin
val response = client.searchPlaces(PlacesQuery("Paris"))

response.hits.first().city.getValue(Language.English)
```

#### Search places for one language

However, it is possible to restrict the search results to a single language.

```kotlin
val response = client.searchPlaces(
query = PlacesQuery("New-York"),
language = Language.English
)

response.hits.first().city
```

#### Search places in countries

Unless one or multiple countries are specified, it will search on the whole planet.

```kotlin
val query = placesQuery("York") {
countries {
+UnitedKingdom
+UnitedStates
}
}

client.searchPlaces(query)
```

#### Search places around radius

Use latitude and longitude coordinates to find places.

```kotlin
val query = placesQuery {
aroundLatLng = Point(40.7128f, -74.0060f) // New-York
}

client.searchPlaces(query)
```

#### Reverse geocoding

Reverse geocoding means converting a location (latitude and longitude) to a readable address.

```kotlin
client.reverseGeocoding(Point(40.7128f, -74.0060f)) // New-York
```

#### Get By ObjectID

Use a Places `objectID` to get an Algolia Places record.

```kotlin
clientPlaces.getByObjectID(ObjectID("201316654_7340078")) // New-York
```

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public object ClientAccount {
* @throws IllegalStateException if [destination] index already exists.
*/
public suspend fun copyIndex(source: Index, destination: Index): List<Task> {
if (source.transport.applicationID == destination.transport.applicationID) {
if (source.transport.credentials.applicationID == destination.transport.credentials.applicationID) {
throw IllegalArgumentException("Source and Destination indices should not be on the same application.")
}
var hasThrown404 = false
Expand Down
21 changes: 14 additions & 7 deletions src/commonMain/kotlin/com/algolia/search/client/ClientAnalytics.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.algolia.search.client

import com.algolia.search.configuration.Credentials
import com.algolia.search.configuration.CredentialsImpl
import com.algolia.search.configuration.Configuration
import com.algolia.search.configuration.ConfigurationAnalytics
import com.algolia.search.endpoint.EndpointAnalytics
Expand All @@ -16,20 +18,24 @@ import com.algolia.search.transport.Transport
* Client to manage [ABTest] for analytics purposes.
*/
public class ClientAnalytics private constructor(
private val api: Transport
) : EndpointAnalytics by EndpointAnalyticsImpl(api),
Configuration by api {
private val transport: Transport
) : EndpointAnalytics by EndpointAnalyticsImpl(transport),
Configuration by transport,
Credentials by transport.credentials {

public constructor(
applicationID: ApplicationID,
apiKey: APIKey
) : this(
Transport(ConfigurationAnalytics(applicationID, apiKey))
Transport(
ConfigurationAnalytics(applicationID, apiKey),
CredentialsImpl(applicationID, apiKey)
)
)

public constructor(
configuration: ConfigurationAnalytics
) : this(Transport(configuration))
) : this(Transport(configuration, configuration))

/**
* Browse every [ABTest] on the index and return them as a list.
Expand All @@ -45,9 +51,10 @@ public class ClientAnalytics private constructor(
var page = 0

while (true) {
val response = listABTests(page++, hitsPerPage, requestOptions)
val response = listABTests(page, hitsPerPage, requestOptions)

if (response.count == 0) break
if (response.count == response.total || response.count == 0) break
page += response.count
responses += response
}
return responses
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.algolia.search.client

import com.algolia.search.configuration.Credentials
import com.algolia.search.configuration.CredentialsImpl
import com.algolia.search.configuration.Configuration
import com.algolia.search.configuration.ConfigurationInsights
import com.algolia.search.endpoint.EndpointInsights
Expand All @@ -17,18 +19,19 @@ import com.algolia.search.transport.Transport
* Client to manage [InsightsEvent].
*/
public class ClientInsights private constructor(
private val api: Transport
) : EndpointInsights by EndpointInsightsImpl(api),
Configuration by api {
private val transport: Transport
) : EndpointInsights by EndpointInsightsImpl(transport),
Configuration by transport,
Credentials by transport.credentials {

public constructor(
applicationID: ApplicationID,
apiKey: APIKey
) : this(Transport(ConfigurationInsights(applicationID, apiKey)))
) : this(Transport(ConfigurationInsights(applicationID, apiKey), CredentialsImpl(applicationID, apiKey)))

public constructor(
configuration: ConfigurationInsights
) : this(Transport(configuration))
) : this(Transport(configuration, configuration))

public inner class User(
val userToken: UserToken
Expand Down
30 changes: 30 additions & 0 deletions src/commonMain/kotlin/com/algolia/search/client/ClientPlaces.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.algolia.search.client

import com.algolia.search.configuration.CredentialsImpl
import com.algolia.search.configuration.Configuration
import com.algolia.search.configuration.ConfigurationPlaces
import com.algolia.search.endpoint.EndpointPlaces
import com.algolia.search.endpoint.EndpointPlacesImpl
import com.algolia.search.model.APIKey
import com.algolia.search.model.ApplicationID
import com.algolia.search.transport.Transport


public class ClientPlaces private constructor(
private val tranport: Transport
) : EndpointPlaces by EndpointPlacesImpl(tranport),
Configuration by tranport {

public constructor(
applicationID: ApplicationID,
apiKey: APIKey
) : this(
Transport(ConfigurationPlaces(), CredentialsImpl(applicationID, apiKey))
)

public constructor(
configuration: ConfigurationPlaces
) : this(Transport(configuration, null))

public constructor() : this(Transport(ConfigurationPlaces(), null))
}
19 changes: 11 additions & 8 deletions src/commonMain/kotlin/com/algolia/search/client/ClientSearch.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.algolia.search.client

import com.algolia.search.configuration.CallType
import com.algolia.search.configuration.Configuration
import com.algolia.search.configuration.ConfigurationSearch
import com.algolia.search.configuration.defaultLogLevel
import com.algolia.search.configuration.*
import com.algolia.search.dsl.requestOptionsBuilder
import com.algolia.search.endpoint.*
import com.algolia.search.helper.encodeBase64
Expand Down Expand Up @@ -38,23 +35,29 @@ import kotlinx.coroutines.*
* Client to perform operations on indices.
*/
public class ClientSearch private constructor(
private val transport: Transport
internal val transport: Transport
) :
EndpointMultipleIndex by EndpointMultipleIndexImpl(transport),
EndpointAPIKey by EndpointAPIKeyImpl(transport),
EndpointMultiCluster by EndpointMulticlusterImpl(transport),
EndpointPersonalization by EndpointPersonalizationImpl(transport),
Configuration by transport {
Configuration by transport,
Credentials by transport.credentials {

public constructor(
applicationID: ApplicationID,
apiKey: APIKey,
logLevel: LogLevel = defaultLogLevel
) : this(Transport(ConfigurationSearch(applicationID, apiKey, logLevel = logLevel)))
) : this(
Transport(
ConfigurationSearch(applicationID, apiKey, logLevel = logLevel),
CredentialsImpl(applicationID, apiKey)
)
)

public constructor(
configuration: ConfigurationSearch
) : this(Transport(configuration))
) : this(Transport(configuration, configuration))

/**
* Initialize an [Index] configured with [ConfigurationSearch].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.algolia.search.configuration


/**
* Singleton exposing information on the library.
*/
public object AlgoliaSearchClient {

/**
* Current version of the library.
*/
const val version = BuildConfig.version
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.algolia.search.configuration


/**
* The different methods of request payload compression.
*/
public enum class Compression {
None,
Gzip
}
Loading

0 comments on commit 28611ac

Please sign in to comment.