Skip to content

Commit 5b10f4e

Browse files
authored
Merge pull request #24 from ContentChef/release/v1.3.0
Release/v1.3.0
2 parents 9836495 + dec5a34 commit 5b10f4e

File tree

11 files changed

+154
-27
lines changed

11 files changed

+154
-27
lines changed

.github/workflows/deploy.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ jobs:
3434
base64 -d -i secretKeyRing.gpg.b64 > "$CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE"
3535
env:
3636
CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE }}
37-
CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE_CONTENT: ${{ secret.CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE_CONTENT }}
37+
CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE_CONTENT: ${{ secrets.CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE_CONTENT }}
3838
- name: Build with Gradle
3939
run: ./gradlew clean build
4040
- name: Publish to MavenCentral
41-
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
41+
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1
4242
env:
43-
CONTENT_CHEF_SIGNING_KEY_ID: ${{ secret.CONTENT_CHEF_SIGNING_KEY_ID }}
44-
CONTENT_CHEF_SIGNING_PASSWORD: ${{ secret.CONTENT_CHEF_SIGNING_PASSWORD }}
45-
CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE: ${{ secret.CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE }}
46-
CONTENT_CHEF_OSSRH_USERNAME: ${{ secret.CONTENT_CHEF_OSSRH_USERNAME }}
47-
CONTENT_CHEF_OSSRH_PASSWORD: ${{ secret.CONTENT_CHEF_OSSRH_PASSWORD }}
48-
CONTENT_CHEF_SONATYPE_STAGING_PROFILE_ID: ${{ secret.CONTENT_CHEF_SONATYPE_STAGING_PROFILE_ID }}
43+
CONTENT_CHEF_SIGNING_KEY_ID: ${{ secrets.CONTENT_CHEF_SIGNING_KEY_ID }}
44+
CONTENT_CHEF_SIGNING_PASSWORD: ${{ secrets.CONTENT_CHEF_SIGNING_PASSWORD }}
45+
CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.CONTENT_CHEF_SIGNING_SECRET_KEY_RING_FILE }}
46+
CONTENT_CHEF_OSSRH_USERNAME: ${{ secrets.CONTENT_CHEF_OSSRH_USERNAME }}
47+
CONTENT_CHEF_OSSRH_PASSWORD: ${{ secrets.CONTENT_CHEF_OSSRH_PASSWORD }}
48+
CONTENT_CHEF_SONATYPE_STAGING_PROFILE_ID: ${{ secrets.CONTENT_CHEF_SONATYPE_STAGING_PROFILE_ID }}
49+
- name: Remember to release to MavenCentral
50+
run: echo "Remember to release on MavenCentral from https://s01.oss.sonatype.org"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
## [1.3.0] - 2021-05-14
6+
### Added
7+
- A `Locale` can now be provided to `getPreviewChannel` and `getOnlineChannel` to retrieve localized content
8+
### Fixed
9+
- Fix `NullPointerException` when a 404 response happens. Now `ContentNotFoundException` it's correctly used
510

611
## [1.2.2] - 2021-04-30
712
### Added

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,30 @@ Preview all the contents with definition as *default-header* in a given future d
9999
println("onError $it")
100100
})
101101

102-
Look at *sampleapp* and *sampleapp-android* in the source code for more examples.
102+
Retrieve localized content as *localized-header* from the _live_ environment:
103+
104+
```kotlin
105+
val enOnlineChannel = contentChef.getOnlineChannel(ONLINE_API_KEY, PUBLISHING_CHANNEL, locale = Locale.ENGLISH)
106+
val itOnlineChannel = contentChef.getOnlineChannel(ONLINE_API_KEY, PUBLISHING_CHANNEL, locale = Locale.ITALY)
107+
108+
val localizedHeaderOnlineContentRequestData = OnlineContentRequestData(
109+
"localized-header"
110+
)
111+
112+
enOnlineChannel.getContent(localizedHeaderOnlineContentRequestData, {
113+
println("onSuccess $it")
114+
}, {
115+
println("onError $it")
116+
})
117+
118+
itOnlineChannel.getContent(localizedHeaderOnlineContentRequestData, {
119+
println("onSuccess $it")
120+
}, {
121+
println("onError $it")
122+
})
123+
```
124+
125+
Look at *sample-java*, *sample-kt* and *sample-android* in the source code for more examples.
103126

104127
## Installation
105128

contentchef-jvm-callback-common/src/main/java/io/contentchef/callback/common/CallbackContentChef.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.contentchef.callback.common
33
import io.contentchef.common.configuration.ContentChefEnvironment
44
import io.contentchef.common.configuration.ContentChefEnvironmentConfiguration
55
import io.contentchef.common.network.RequestFactory
6+
import java.util.Locale
67

78
/**
89
* Exposes methods used to retrieve contents from ContentChef's backend
@@ -15,35 +16,40 @@ internal class CallbackContentChef constructor(
1516

1617
override fun getPreviewChannel(
1718
previewApiKey: String,
18-
publishingChannel: String
19+
publishingChannel: String,
20+
locale: Locale?
1921
): PreviewChannel {
2022
return AbstractChannel(
2123
contentChefEnvironmentConfiguration.generateWebserviceURL(
2224
ContentChefEnvironmentConfiguration.Companion.WebService.PREVIEW_CONTENT,
23-
publishingChannel
25+
publishingChannel,
26+
locale
2427
),
2528
contentChefEnvironmentConfiguration.generateWebserviceURL(
2629
ContentChefEnvironmentConfiguration.Companion.WebService.PREVIEW_SEARCH,
27-
publishingChannel
30+
publishingChannel,
31+
locale
2832
),
2933
previewApiKey,
3034
requestFactory,
3135
requestExecutor
3236
)
3337
}
3438

35-
override fun getOnlineChannel(onlineApiKey: String, publishingChannel: String): OnlineChannel {
39+
override fun getOnlineChannel(onlineApiKey: String, publishingChannel: String, locale: Locale?): OnlineChannel {
3640
require(contentChefEnvironmentConfiguration.contentChefEnvironment == ContentChefEnvironment.LIVE) {
3741
"Online channel can only be used with LIVE environment setup"
3842
}
3943
return AbstractChannel(
4044
contentChefEnvironmentConfiguration.generateWebserviceURL(
4145
ContentChefEnvironmentConfiguration.Companion.WebService.ONLINE_CONTENT,
42-
publishingChannel
46+
publishingChannel,
47+
locale
4348
),
4449
contentChefEnvironmentConfiguration.generateWebserviceURL(
4550
ContentChefEnvironmentConfiguration.Companion.WebService.ONLINE_SEARCH,
46-
publishingChannel
51+
publishingChannel,
52+
locale
4753
),
4854
onlineApiKey,
4955
requestFactory,

contentchef-jvm-callback-common/src/main/java/io/contentchef/callback/common/ContentChef.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.contentchef.common.request.OnlineContentRequestData
44
import io.contentchef.common.request.PreviewContentRequestData
55
import io.contentchef.common.request.SearchOnlineRequestData
66
import io.contentchef.common.request.SearchPreviewRequestData
7+
import java.util.Locale
78

89
/**
910
* Exposes methods used to retrieve contents from ContentChef's backend
@@ -14,15 +15,17 @@ interface ContentChef {
1415
* Using the [PreviewChannel] you can retrieve contents which are in in both stage and live state and even contents that are not visible in the current date
1516
* [previewApiKey] is the api key required for the [PreviewChannel]
1617
* [publishingChannel] chosen publishingChannel
18+
* [locale] used to retrieve localized content
1719
*/
18-
fun getPreviewChannel(previewApiKey: String, publishingChannel: String): PreviewChannel
20+
fun getPreviewChannel(previewApiKey: String, publishingChannel: String, locale: Locale? = null): PreviewChannel
1921

2022
/**
2123
* Using the [OnlineChannel] you can retrieve contents which are in live state and which are actually visible
2224
* [onlineApiKey] is the api key required for the [OnlineChannel]
2325
* [publishingChannel] chosen publishingChannel
26+
* [locale] used to retrieve localized content
2427
*/
25-
fun getOnlineChannel(onlineApiKey: String, publishingChannel: String): OnlineChannel
28+
fun getOnlineChannel(onlineApiKey: String, publishingChannel: String, locale: Locale? = null): OnlineChannel
2629

2730
}
2831

contentchef-jvm-common/src/main/java/io/contentchef/common/configuration/ContentChefEnvironmentConfiguration.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.contentchef.common.configuration
22

3+
import java.util.Locale
4+
35
/**
46
* Used to configure a [ContentChef] instance using a [ContentChefProvider]
57
* [contentChefEnvironment] chosen ContentChef environment
@@ -28,10 +30,18 @@ constructor(
2830
}
2931
}
3032

31-
fun generateWebserviceURL(webService: WebService, publishingChannel: String): String {
33+
fun generateWebserviceURL(webService: WebService, publishingChannel: String, locale: Locale? = null): String {
3234
val finalUrl = contentChefBaseUrl.plus(webService.urlTemplate)
33-
return finalUrl.replace(ENVIRONMENT_PLACEHOLDER, contentChefEnvironment.urlPathValue)
35+
finalUrl.replace(ENVIRONMENT_PLACEHOLDER, contentChefEnvironment.urlPathValue)
3436
.replace(SPACE_ID_PLACEHOLDER, spaceId)
3537
.replace(PUBLISHING_CHANNEL_PLACEHOLDER, publishingChannel)
38+
.run {
39+
return if (locale != null) {
40+
val localeString = locale.toString()
41+
plus("/$localeString")
42+
} else {
43+
this
44+
}
45+
}
3646
}
3747
}

contentchef-jvm-common/src/main/java/io/contentchef/common/network/ConnectionStreamReader.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.contentchef.common.network
22

33
import java.io.BufferedReader
4+
import java.io.InputStream
45
import java.io.InputStreamReader
56
import java.net.HttpURLConnection
67

@@ -13,12 +14,21 @@ object ConnectionStreamReader {
1314
* Returns the content read from [httpURLConnection] as [String]
1415
*/
1516
fun getContentAsString(httpURLConnection: HttpURLConnection): String {
16-
val br = if (httpURLConnection.responseCode in 200..299) {
17-
BufferedReader(InputStreamReader(httpURLConnection.inputStream))
18-
} else {
19-
BufferedReader(InputStreamReader(httpURLConnection.errorStream))
17+
return when (httpURLConnection.responseCode) {
18+
in 200..299 -> {
19+
readStreamAsString(httpURLConnection.inputStream)
20+
}
21+
404 -> {
22+
""
23+
}
24+
else -> {
25+
readStreamAsString(httpURLConnection.errorStream);
26+
}
2027
}
21-
return br.useLines {
28+
}
29+
30+
private fun readStreamAsString(inputStream: InputStream): String {
31+
return BufferedReader(InputStreamReader(inputStream)).useLines {
2232
it.joinToString(separator = "")
2333
}
2434
}

publish_scripts/publish-module.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ artifacts {
2727
}
2828

2929
def PUBLISH_GROUP_ID = 'io.contentchef'
30-
def PUBLISH_VERSION = '1.2.2'
30+
def PUBLISH_VERSION = '1.3.0'
3131
group = PUBLISH_GROUP_ID
3232
version = PUBLISH_VERSION
3333

sample-android/src/main/java/io/contentchef/android/sample/MainActivity.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class MainActivity : AppCompatActivity() {
2525
private lateinit var onlineChannel: OnlineChannel
2626
private lateinit var previewChannel: PreviewChannel
2727

28+
//LOCALIZED CHANNELS
29+
private lateinit var enOnlineChannel: OnlineChannel
30+
private lateinit var itOnlineChannel: OnlineChannel
31+
2832
override fun onCreate(savedInstanceState: Bundle?) {
2933
super.onCreate(savedInstanceState)
3034
setContentView(R.layout.activity_main)
@@ -143,6 +147,26 @@ class MainActivity : AppCompatActivity() {
143147
SampleHeader(it.getString("header"))
144148
})
145149

150+
//LOCALIZED CONTENT EXAMPLE
151+
enOnlineChannel = contentChef.getOnlineChannel(ONLINE_API_KEY, PUBLISHING_CHANNEL, locale = Locale.ENGLISH)
152+
itOnlineChannel = contentChef.getOnlineChannel(ONLINE_API_KEY, PUBLISHING_CHANNEL, locale = Locale.ITALY)
153+
154+
val localizedHeaderOnlineContentRequestData = OnlineContentRequestData(
155+
"test-localized-header"
156+
)
157+
158+
enOnlineChannel.getContent(localizedHeaderOnlineContentRequestData, {
159+
println("onSuccess $it")
160+
}, {
161+
println("onError $it")
162+
})
163+
164+
itOnlineChannel.getContent(localizedHeaderOnlineContentRequestData, {
165+
println("onSuccess $it")
166+
}, {
167+
println("onError $it")
168+
})
169+
146170
}
147171
}
148172

sample-java/src/main/java/io/contentchef/sample/Main.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Collections;
44
import java.util.Date;
5+
import java.util.Locale;
56

67
import io.contentchef.callback.CallbackContentChefProvider;
78
import io.contentchef.callback.common.Channel;
@@ -42,8 +43,8 @@ public static void main(String[] args) {
4243
), true
4344
);
4445

45-
Channel<OnlineContentRequestData, SearchOnlineRequestData> onlineChannel = contentChef.getOnlineChannel(ContentChefConfiguration.ONLINE_API_KEY, ContentChefConfiguration.PUBLISHING_CHANNEL);
46-
Channel<PreviewContentRequestData, SearchPreviewRequestData> previewChannel = contentChef.getPreviewChannel(ContentChefConfiguration.PREVIEW_API_KEY, ContentChefConfiguration.PUBLISHING_CHANNEL);
46+
Channel<OnlineContentRequestData, SearchOnlineRequestData> onlineChannel = contentChef.getOnlineChannel(ContentChefConfiguration.ONLINE_API_KEY, ContentChefConfiguration.PUBLISHING_CHANNEL, null);
47+
Channel<PreviewContentRequestData, SearchPreviewRequestData> previewChannel = contentChef.getPreviewChannel(ContentChefConfiguration.PREVIEW_API_KEY, ContentChefConfiguration.PUBLISHING_CHANNEL, null);
4748

4849
PreviewContentRequestData previewContentRequestData = new PreviewContentRequestData(
4950
"new-header", new Date()
@@ -151,6 +152,26 @@ public static void main(String[] args) {
151152
jsonObject -> new SampleHeader(jsonObject.getString("header"))
152153
);
153154

155+
//LOCALIZED CONTENT EXAMPLE
156+
Channel<OnlineContentRequestData, SearchOnlineRequestData> enOnlineChannel = contentChef.getOnlineChannel(ContentChefConfiguration.ONLINE_API_KEY, ContentChefConfiguration.PUBLISHING_CHANNEL, Locale.ENGLISH);
157+
Channel<OnlineContentRequestData, SearchOnlineRequestData> itOnlineChannel = contentChef.getOnlineChannel(ContentChefConfiguration.ONLINE_API_KEY, ContentChefConfiguration.PUBLISHING_CHANNEL, Locale.ITALY);
158+
159+
OnlineContentRequestData localizedHeaderOnlineContentRequestData = new OnlineContentRequestData(
160+
"test-localized-header"
161+
);
162+
163+
enOnlineChannel.getContent(
164+
localizedHeaderOnlineContentRequestData,
165+
jsonObjectContentChefItemResponse -> printSuccess(jsonObjectContentChefItemResponse),
166+
throwable -> printError(throwable)
167+
);
168+
169+
itOnlineChannel.getContent(
170+
localizedHeaderOnlineContentRequestData,
171+
jsonObjectContentChefItemResponse -> printSuccess(jsonObjectContentChefItemResponse),
172+
throwable -> printError(throwable)
173+
);
174+
154175
}
155176

156177
}

0 commit comments

Comments
 (0)