Skip to content

Commit 28611ac

Browse files
authored
Merge pull request #106 from algolia/develop
Merge 1.1.0 in master
2 parents 0324378 + ef33663 commit 28611ac

File tree

134 files changed

+4475
-783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+4475
-783
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 1.1.0
2+
3+
- Kotlin version 1.3.41
4+
- Ktor version 1.2.3-rc
5+
- Added `enableABTest` as `Query` parameter
6+
- Added `similarQuery` as `Query` parameter
7+
- Added `advancedSyntaxFeatures` as `Query` parameter
8+
- Added `index.exists()` method
9+
- New `AlgoliaSearchClient` object exposes library version constant
10+
- Added `Compression` feature. `Gzip` compression is enabled by default.
11+
- Default `readTimeout` has been increased to 5 seconds
12+
- It is now possible to configure `HttpClientConfig` in `Configuration`
13+
- Added `ClientPlaces` to access Algolia Places endpoints. See this [file](docs/Places.md) for getting starting with Places.
14+
- `QueryLanguage` is renamed to `Language`
15+
- Fixed a bug in `browseAllABTests` methods

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Algolia
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23
import java.net.URI
34

45

56
plugins {
6-
id("kotlin-multiplatform") version "1.3.31"
7-
id("kotlinx-serialization") version "1.3.31"
7+
id("kotlin-multiplatform") version "1.3.41"
8+
id("kotlinx-serialization") version "1.3.41"
89
id("maven-publish")
910
id("com.jfrog.bintray") version "1.8.4"
1011
id("com.github.kukuhyoniatmoko.buildconfigkotlin") version "1.0.5"
@@ -156,4 +157,7 @@ tasks {
156157
setPublications("jvm", "metadata")
157158
}
158159
}
160+
withType<KotlinCompile> {
161+
dependsOn("generateMetadataBuildConfigKotlin")
162+
}
159163
}

buildSrc/src/main/kotlin/Ktor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ object Ktor : Dependency {
22

33
override val group = "io.ktor"
44
override val artifact = "ktor"
5-
override val version = "1.2.1"
5+
override val version = "1.2.3-rc"
66
}

buildSrc/src/main/kotlin/Library.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ object Library: Dependency {
22

33
override val group = "com.algolia"
44
override val artifact = "algoliasearch-client-kotlin"
5-
override val version = "1.0.0"
5+
override val version = "1.1.0"
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Serialization : Dependency {
22

3-
override val version = "0.11.0"
3+
override val version = "0.11.1"
44
override val group = "org.jetbrains.kotlinx"
55
override val artifact = "kotlinx-serialization"
66
}

docs/Places.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Places client
2+
3+
Algolia Places provides a fast, distributed and easy way to use address search.
4+
5+
## Pricing
6+
7+
#### Rate limit
8+
9+
The Algolia Places API enforces 30 queries per second. [Contact us](https://community.algolia.com/places/contact.html) if you need more.
10+
11+
If you're calling the API from your backend, the rate-limits computation is then based on the source IP.
12+
13+
#### Plans
14+
15+
- Free: 1000 requests / day [Sign Up](https://www.algolia.com/users/sign_up/places)
16+
- Free, with authentication: 100 000 requests / month [Sign Up](https://www.algolia.com/users/sign_up/places)
17+
- Paying: $0.40 per 1000 requests [Sign Up](https://www.algolia.com/users/sign_up/places)
18+
- Up to unlimited: [Contact us](https://community.algolia.com/places/contact.html)
19+
20+
21+
Visit our [website](https://community.algolia.com/places/pricing.html).
22+
23+
## Usage
24+
25+
#### Unauthenticated
26+
27+
You can use Algolia Places without authentication. Limited to 1000 requests per day.
28+
29+
```kotlin
30+
val client = ClientPlaces()
31+
```
32+
33+
#### Authenticated
34+
35+
Pass an `ApplicationID` and an `APIKey` to the `ClientPlaces` for authenticated usage.
36+
37+
```kotlin
38+
val client = ClientPlaces(
39+
ApplicationID("YourApplicationID"),
40+
APIKey("YourPlacesAPIKey")
41+
)
42+
```
43+
44+
#### Search places for multiple languages
45+
46+
By default, the response of `searchPlaces` contains translations in all languages.
47+
48+
```kotlin
49+
val response = client.searchPlaces(PlacesQuery("Paris"))
50+
51+
response.hits.first().city.getValue(Language.English)
52+
```
53+
54+
#### Search places for one language
55+
56+
However, it is possible to restrict the search results to a single language.
57+
58+
```kotlin
59+
val response = client.searchPlaces(
60+
query = PlacesQuery("New-York"),
61+
language = Language.English
62+
)
63+
64+
response.hits.first().city
65+
```
66+
67+
#### Search places in countries
68+
69+
Unless one or multiple countries are specified, it will search on the whole planet.
70+
71+
```kotlin
72+
val query = placesQuery("York") {
73+
countries {
74+
+UnitedKingdom
75+
+UnitedStates
76+
}
77+
}
78+
79+
client.searchPlaces(query)
80+
```
81+
82+
#### Search places around radius
83+
84+
Use latitude and longitude coordinates to find places.
85+
86+
```kotlin
87+
val query = placesQuery {
88+
aroundLatLng = Point(40.7128f, -74.0060f) // New-York
89+
}
90+
91+
client.searchPlaces(query)
92+
```
93+
94+
#### Reverse geocoding
95+
96+
Reverse geocoding means converting a location (latitude and longitude) to a readable address.
97+
98+
```kotlin
99+
client.reverseGeocoding(Point(40.7128f, -74.0060f)) // New-York
100+
```
101+
102+
#### Get By ObjectID
103+
104+
Use a Places `objectID` to get an Algolia Places record.
105+
106+
```kotlin
107+
clientPlaces.getByObjectID(ObjectID("201316654_7340078")) // New-York
108+
```
109+

src/commonMain/kotlin/com/algolia/search/client/ClientAccount.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public object ClientAccount {
1717
* @throws IllegalStateException if [destination] index already exists.
1818
*/
1919
public suspend fun copyIndex(source: Index, destination: Index): List<Task> {
20-
if (source.transport.applicationID == destination.transport.applicationID) {
20+
if (source.transport.credentials.applicationID == destination.transport.credentials.applicationID) {
2121
throw IllegalArgumentException("Source and Destination indices should not be on the same application.")
2222
}
2323
var hasThrown404 = false

src/commonMain/kotlin/com/algolia/search/client/ClientAnalytics.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.algolia.search.client
22

3+
import com.algolia.search.configuration.Credentials
4+
import com.algolia.search.configuration.CredentialsImpl
35
import com.algolia.search.configuration.Configuration
46
import com.algolia.search.configuration.ConfigurationAnalytics
57
import com.algolia.search.endpoint.EndpointAnalytics
@@ -16,20 +18,24 @@ import com.algolia.search.transport.Transport
1618
* Client to manage [ABTest] for analytics purposes.
1719
*/
1820
public class ClientAnalytics private constructor(
19-
private val api: Transport
20-
) : EndpointAnalytics by EndpointAnalyticsImpl(api),
21-
Configuration by api {
21+
private val transport: Transport
22+
) : EndpointAnalytics by EndpointAnalyticsImpl(transport),
23+
Configuration by transport,
24+
Credentials by transport.credentials {
2225

2326
public constructor(
2427
applicationID: ApplicationID,
2528
apiKey: APIKey
2629
) : this(
27-
Transport(ConfigurationAnalytics(applicationID, apiKey))
30+
Transport(
31+
ConfigurationAnalytics(applicationID, apiKey),
32+
CredentialsImpl(applicationID, apiKey)
33+
)
2834
)
2935

3036
public constructor(
3137
configuration: ConfigurationAnalytics
32-
) : this(Transport(configuration))
38+
) : this(Transport(configuration, configuration))
3339

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

4753
while (true) {
48-
val response = listABTests(page++, hitsPerPage, requestOptions)
54+
val response = listABTests(page, hitsPerPage, requestOptions)
4955

50-
if (response.count == 0) break
56+
if (response.count == response.total || response.count == 0) break
57+
page += response.count
5158
responses += response
5259
}
5360
return responses

src/commonMain/kotlin/com/algolia/search/client/ClientInsights.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.algolia.search.client
22

3+
import com.algolia.search.configuration.Credentials
4+
import com.algolia.search.configuration.CredentialsImpl
35
import com.algolia.search.configuration.Configuration
46
import com.algolia.search.configuration.ConfigurationInsights
57
import com.algolia.search.endpoint.EndpointInsights
@@ -17,18 +19,19 @@ import com.algolia.search.transport.Transport
1719
* Client to manage [InsightsEvent].
1820
*/
1921
public class ClientInsights private constructor(
20-
private val api: Transport
21-
) : EndpointInsights by EndpointInsightsImpl(api),
22-
Configuration by api {
22+
private val transport: Transport
23+
) : EndpointInsights by EndpointInsightsImpl(transport),
24+
Configuration by transport,
25+
Credentials by transport.credentials {
2326

2427
public constructor(
2528
applicationID: ApplicationID,
2629
apiKey: APIKey
27-
) : this(Transport(ConfigurationInsights(applicationID, apiKey)))
30+
) : this(Transport(ConfigurationInsights(applicationID, apiKey), CredentialsImpl(applicationID, apiKey)))
2831

2932
public constructor(
3033
configuration: ConfigurationInsights
31-
) : this(Transport(configuration))
34+
) : this(Transport(configuration, configuration))
3235

3336
public inner class User(
3437
val userToken: UserToken
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.algolia.search.client
2+
3+
import com.algolia.search.configuration.CredentialsImpl
4+
import com.algolia.search.configuration.Configuration
5+
import com.algolia.search.configuration.ConfigurationPlaces
6+
import com.algolia.search.endpoint.EndpointPlaces
7+
import com.algolia.search.endpoint.EndpointPlacesImpl
8+
import com.algolia.search.model.APIKey
9+
import com.algolia.search.model.ApplicationID
10+
import com.algolia.search.transport.Transport
11+
12+
13+
public class ClientPlaces private constructor(
14+
private val tranport: Transport
15+
) : EndpointPlaces by EndpointPlacesImpl(tranport),
16+
Configuration by tranport {
17+
18+
public constructor(
19+
applicationID: ApplicationID,
20+
apiKey: APIKey
21+
) : this(
22+
Transport(ConfigurationPlaces(), CredentialsImpl(applicationID, apiKey))
23+
)
24+
25+
public constructor(
26+
configuration: ConfigurationPlaces
27+
) : this(Transport(configuration, null))
28+
29+
public constructor() : this(Transport(ConfigurationPlaces(), null))
30+
}

src/commonMain/kotlin/com/algolia/search/client/ClientSearch.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.algolia.search.client
22

3-
import com.algolia.search.configuration.CallType
4-
import com.algolia.search.configuration.Configuration
5-
import com.algolia.search.configuration.ConfigurationSearch
6-
import com.algolia.search.configuration.defaultLogLevel
3+
import com.algolia.search.configuration.*
74
import com.algolia.search.dsl.requestOptionsBuilder
85
import com.algolia.search.endpoint.*
96
import com.algolia.search.helper.encodeBase64
@@ -38,23 +35,29 @@ import kotlinx.coroutines.*
3835
* Client to perform operations on indices.
3936
*/
4037
public class ClientSearch private constructor(
41-
private val transport: Transport
38+
internal val transport: Transport
4239
) :
4340
EndpointMultipleIndex by EndpointMultipleIndexImpl(transport),
4441
EndpointAPIKey by EndpointAPIKeyImpl(transport),
4542
EndpointMultiCluster by EndpointMulticlusterImpl(transport),
4643
EndpointPersonalization by EndpointPersonalizationImpl(transport),
47-
Configuration by transport {
44+
Configuration by transport,
45+
Credentials by transport.credentials {
4846

4947
public constructor(
5048
applicationID: ApplicationID,
5149
apiKey: APIKey,
5250
logLevel: LogLevel = defaultLogLevel
53-
) : this(Transport(ConfigurationSearch(applicationID, apiKey, logLevel = logLevel)))
51+
) : this(
52+
Transport(
53+
ConfigurationSearch(applicationID, apiKey, logLevel = logLevel),
54+
CredentialsImpl(applicationID, apiKey)
55+
)
56+
)
5457

5558
public constructor(
5659
configuration: ConfigurationSearch
57-
) : this(Transport(configuration))
60+
) : this(Transport(configuration, configuration))
5861

5962
/**
6063
* Initialize an [Index] configured with [ConfigurationSearch].
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.algolia.search.configuration
2+
3+
4+
/**
5+
* Singleton exposing information on the library.
6+
*/
7+
public object AlgoliaSearchClient {
8+
9+
/**
10+
* Current version of the library.
11+
*/
12+
const val version = BuildConfig.version
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.algolia.search.configuration
2+
3+
4+
/**
5+
* The different methods of request payload compression.
6+
*/
7+
public enum class Compression {
8+
None,
9+
Gzip
10+
}

0 commit comments

Comments
 (0)