Skip to content

Commit cbb2802

Browse files
PubNub SDK v5.1.0 release.
1 parent 94c3234 commit cbb2802

File tree

103 files changed

+4418
-598
lines changed

Some content is hidden

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

103 files changed

+4418
-598
lines changed

.github/CODEOWNERS

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
* @kleewho @bartk @qsoftdevelopment @Chesteer89
1+
* @kleewho @bartk @Chesteer89
2+
.travis/* @parfeon @kleewho @bartk @Chesteer89
3+
README.md @polarweasel @samiahmedsiddiqui @techwritermat

.pubnub.yml

+50-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
name: kotlin
2-
version: 5.0.2
2+
version: 5.1.0
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-5.0.2-all.jar
6+
- build/libs/pubnub-kotlin-5.1.0-all.jar
77
changelog:
8+
-
9+
version: v5.1.0
10+
date: 2020-12-16
11+
changes:
12+
-
13+
type: feature
14+
text: "Files support includes sending, downloading, listing, deleting together with notifications about file events."
15+
-
16+
type: feature
17+
text: "New methods can set and remove memberships/channelMembers in one call."
18+
-
19+
type: feature
20+
text: "New field `page` can be returned from the backend in case there's more data to fetch for the original query. This new field can be used directly in new `fetchMessages` and `getMessagesActions` method versions. The old versions in which paging information was in separate arguments has been deprecated."
21+
-
22+
type: feature
23+
text: "FetchMessages has a default limit of 100 for single-channel call."
24+
-
25+
type: bug
26+
text: "Make PNMessageActionResultevent accessible (no longer internal)."
27+
-
28+
type: bug
29+
text: "Method `addMemberships` has been deprecated and shouldn't be used in the future."
830
-
931
version: v5.0.2
1032
date: 2020-10-20
@@ -13,7 +35,7 @@ changelog:
1335
type: bug
1436
text: "Remove Instant to improve Android version compatibility."
1537
-
16-
version: 5.0.2
38+
version: 5.1.0
1739
date: 2020-09-28
1840
changes:
1941
-
@@ -104,6 +126,31 @@ features:
104126
- SUBSCRIBE-MESSAGE-ACTIONS-LISTENER
105127
signal:
106128
- SIGNAL-SEND
129+
objects:
130+
- OBJECTS-FILTERING
131+
- OBJECTS-SORTING
132+
- OBJECTS-GET-ALL-UUID-METADATA
133+
- OBJECTS-GET-UUID-METADATA
134+
- OBJECTS-SET-UUID-METADATA
135+
- OBJECTS-REMOVE-UUID-METADATA
136+
- OBJECTS-GET-ALL-CHANNEL-METADATA
137+
- OBJECTS-GET-CHANNEL-METADATA
138+
- OBJECTS-SET-CHANNEL-METADATA
139+
- OBJECTS-REMOVE-CHANNEL-METADATA
140+
- OBJECTS-GET-MEMBERSHIPS-V2
141+
- OBJECTS-SET-MEMBERSHIPS-V2
142+
- OBJECTS-REMOVE-MEMBERSHIPS-V2
143+
- OBJECTS-GET-CHANNEL-MEMBERS-V2
144+
- OBJECTS-SET-CHANNEL-MEMBERS-V2
145+
- OBJECTS-REMOVE-CHANNEL-MEMBERS-V2
146+
- OBJECTS-MANAGE-MEMBERSHIPS-V2
147+
- OBJECTS-MANAGE-CHANNEL-MEMBERS-V2
148+
files:
149+
- FILES-DELETE-FILE
150+
- FILES-DOWNLOAD-FILE
151+
- FILES-GET-FILE-URL
152+
- FILES-LIST-FILES
153+
- FILES-SEND-FILE
107154
unsubscribe:
108155
- UNSUBSCRIBE-ALL
109156
- UNSUBSCRIBE-SUPPRESS-LEAVE-EVENTS

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## [v5.1.0](https://github.com/pubnub/kotlin/releases/tag/v5.1.0)
2+
December 16 2020
3+
4+
[Full Changelog](https://github.com/pubnub/kotlin/compare/v5.0.2...v5.1.0)
5+
6+
- Files support includes sending, downloading, listing, deleting together with notifications about file events.
7+
- New methods can set and remove memberships/channelMembers in one call.
8+
- New field `page` can be returned from the backend in case there's more data to fetch for the original query. This new field can be used directly in new `fetchMessages` and `getMessagesActions` method versions. The old versions in which paging information was in separate arguments has been deprecated.
9+
- FetchMessages has a default limit of 100 for single-channel call.
10+
- Make PNMessageActionResultevent accessible (no longer internal).
11+
- Method `addMemberships` has been deprecated and shouldn't be used in the future.
12+
13+

build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group = 'com.pubnub'
15-
version = '5.0.2'
15+
version = '5.1.0'
1616

1717
repositories {
1818
mavenCentral()
@@ -52,7 +52,8 @@ dependencies {
5252

5353
api 'com.google.code.gson:gson:2.8.6'
5454
implementation "com.squareup.retrofit2:converter-gson:2.6.2"
55-
55+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
56+
compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.9'
5657
implementation "org.slf4j:slf4j-api:1.7.28"
5758

5859
implementation "org.json:json:20190722"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.pubnub.api.integration
2+
3+
import com.pubnub.api.CommonUtils.randomChannel
4+
import com.pubnub.api.PubNub
5+
import com.pubnub.api.callbacks.SubscribeCallback
6+
import com.pubnub.api.enums.PNStatusCategory
7+
import com.pubnub.api.models.consumer.PNStatus
8+
import com.pubnub.api.models.consumer.files.PNFileUploadResult
9+
import com.pubnub.api.models.consumer.pubsub.PNMessageResult
10+
import com.pubnub.api.models.consumer.pubsub.PNPresenceEventResult
11+
import com.pubnub.api.models.consumer.pubsub.PNSignalResult
12+
import com.pubnub.api.models.consumer.pubsub.files.PNFileEventResult
13+
import com.pubnub.api.models.consumer.pubsub.message_actions.PNMessageActionResult
14+
import com.pubnub.api.models.consumer.pubsub.objects.PNObjectEventResult
15+
import org.junit.Assert
16+
import org.junit.Test
17+
import java.io.ByteArrayInputStream
18+
import java.io.InputStream
19+
import java.nio.charset.StandardCharsets
20+
import java.util.Scanner
21+
import java.util.concurrent.CountDownLatch
22+
import java.util.concurrent.TimeUnit
23+
24+
class FilesIntegrationTest : BaseIntegrationTest() {
25+
@Test
26+
fun uploadListDownloadDeleteWithCipher() {
27+
uploadListDownloadDelete(true)
28+
}
29+
30+
@Test
31+
fun uploadListDownloadDeleteWithoutCipher() {
32+
uploadListDownloadDelete(false)
33+
}
34+
35+
private fun uploadListDownloadDelete(withCipher: Boolean) {
36+
if (withCipher) {
37+
pubnub.configuration.cipherKey = "enigma"
38+
}
39+
val channel: String = randomChannel()
40+
val content = "This is content"
41+
val message = "This is message"
42+
val meta = "This is meta"
43+
val fileName = "fileName$channel.txt"
44+
val connectedLatch = CountDownLatch(1)
45+
val fileEventReceived = CountDownLatch(1)
46+
pubnub.addListener(object : LimitedListener() {
47+
override fun status(pubnub: PubNub, pnStatus: PNStatus) {
48+
if (pnStatus.category === PNStatusCategory.PNConnectedCategory) {
49+
connectedLatch.countDown()
50+
}
51+
}
52+
53+
override fun file(pubnub: PubNub, pnFileEventResult: PNFileEventResult) {
54+
if (pnFileEventResult.file.name == fileName) {
55+
fileEventReceived.countDown()
56+
}
57+
}
58+
})
59+
pubnub.subscribe(channels = listOf(channel))
60+
connectedLatch.await(10, TimeUnit.SECONDS)
61+
val sendResult: PNFileUploadResult? = ByteArrayInputStream(content.toByteArray(StandardCharsets.UTF_8)).use {
62+
pubnub.sendFile(
63+
channel = channel,
64+
fileName = fileName,
65+
inputStream = it,
66+
message = message,
67+
meta = meta
68+
).sync()
69+
}
70+
71+
if (sendResult == null) {
72+
Assert.fail()
73+
return
74+
}
75+
fileEventReceived.await(10, TimeUnit.SECONDS)
76+
val (_, _, _, data) = pubnub.listFiles(channel = channel).sync()!!
77+
val fileFoundOnList = data.find { it.id == sendResult.file.id } != null
78+
79+
Assert.assertTrue(fileFoundOnList)
80+
val (_, byteStream) = pubnub.downloadFile(
81+
channel = channel,
82+
fileName = fileName,
83+
fileId = sendResult.file.id
84+
)
85+
.sync()!!
86+
byteStream?.use {
87+
Assert.assertEquals(content, readToString(it))
88+
}
89+
pubnub.deleteFile(channel = channel,
90+
fileName = fileName,
91+
fileId = sendResult.file.id)
92+
.sync()
93+
}
94+
95+
private fun readToString(inputStream: InputStream): String {
96+
Scanner(inputStream).useDelimiter("\\A").use { s -> return if (s.hasNext()) s.next() else "" }
97+
}
98+
99+
private abstract class LimitedListener : SubscribeCallback() {
100+
override fun presence(pubnub: PubNub, pnPresenceEventResult: PNPresenceEventResult) {}
101+
override fun message(pubnub: PubNub, pnMessageResult: PNMessageResult) {}
102+
override fun signal(pubnub: PubNub, pnSignalResult: PNSignalResult) {}
103+
override fun objects(pubnub: PubNub, objectEvent: PNObjectEventResult) {}
104+
override fun messageAction(pubnub: PubNub, pnMessageActionResult: PNMessageActionResult) {}
105+
}
106+
}

src/integrationTest/kotlin/com/pubnub/api/integration/HistoryIntegrationTest.kt

+38-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.pubnub.api.CommonUtils.randomValue
88
import com.pubnub.api.CommonUtils.retry
99
import com.pubnub.api.PubNubError
1010
import com.pubnub.api.await
11+
import com.pubnub.api.models.consumer.PNBoundedPage
1112
import com.pubnub.api.models.consumer.message_actions.PNMessageAction
1213
import com.pubnub.api.param
1314
import org.junit.Assert.assertEquals
@@ -124,7 +125,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
124125
retry {
125126
pubnub.fetchMessages(
126127
channels = listOf(expectedChannelName),
127-
maximumPerChannel = 25
128+
page = PNBoundedPage(
129+
limit = 25
130+
)
128131
).sync()!!.run {
129132
channels[expectedChannelName]!!.forEach {
130133
assertNotNull(it.message)
@@ -144,7 +147,7 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
144147
retry {
145148
pubnub.fetchMessages(
146149
channels = listOf(expectedChannelName),
147-
maximumPerChannel = 25,
150+
page = PNBoundedPage(limit = 25),
148151
includeMeta = true
149152
).sync()!!.run {
150153
channels[expectedChannelName]!!.forEach {
@@ -176,9 +179,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
176179
retry {
177180
pubnub.fetchMessages(
178181
channels = listOf(expectedChannelName),
179-
maximumPerChannel = 25,
180-
includeMessageActions = true,
181-
includeMeta = false
182+
page = PNBoundedPage(limit = 25),
183+
includeMeta = false,
184+
includeMessageActions = true
182185
).sync()!!.run {
183186
channels[expectedChannelName]!!.forEach {
184187
assertNotNull(it.message)
@@ -211,9 +214,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
211214
retry {
212215
pubnub.fetchMessages(
213216
channels = listOf(expectedChannelName),
214-
maximumPerChannel = 25,
215-
includeMessageActions = true,
216-
includeMeta = true
217+
page = PNBoundedPage(limit = 25),
218+
includeMeta = true,
219+
includeMessageActions = true
217220
).sync()!!.run {
218221
channels[expectedChannelName]!!.forEach {
219222
assertNotNull(it.message)
@@ -242,7 +245,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
242245
retry {
243246
pubnub.fetchMessages(
244247
channels = expectedChannelNames,
245-
maximumPerChannel = 25
248+
page = PNBoundedPage(
249+
limit = 25
250+
)
246251
).sync()!!.run {
247252
expectedChannelNames.forEach { expectedChannel ->
248253
channels[expectedChannel]!!.forEach {
@@ -285,7 +290,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
285290
retry {
286291
pubnub.fetchMessages(
287292
channels = listOf(expectedChannelName),
288-
maximumPerChannel = 100
293+
page = PNBoundedPage(
294+
limit = 100
295+
)
289296
).sync()!!.apply {
290297
assertEquals(10, channels[expectedChannelName]!!.size)
291298
channels[expectedChannelName]!!.forEach {
@@ -447,7 +454,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
447454
fun testFetchSingleChannel_NoActions_Limit_Low() {
448455
pubnub.fetchMessages(
449456
channels = listOf(randomValue()),
450-
maximumPerChannel = -1
457+
page = PNBoundedPage(
458+
limit = -1
459+
)
451460
).await { _, status ->
452461
assertEquals("1", status.param("max"))
453462
}
@@ -457,7 +466,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
457466
fun testFetchSingleChannel_NoActions_Limit_Valid() {
458467
pubnub.fetchMessages(
459468
channels = listOf(randomValue()),
460-
maximumPerChannel = 15
469+
page = PNBoundedPage(
470+
limit = 15
471+
)
461472
).await { _, status ->
462473
assertEquals("15", status.param("max"))
463474
}
@@ -467,7 +478,9 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
467478
fun testFetchSingleChannel_NoActions_Limit_High() {
468479
pubnub.fetchMessages(
469480
channels = listOf(randomValue()),
470-
maximumPerChannel = 100
481+
page = PNBoundedPage(
482+
limit = 100
483+
)
471484
).await { _, status ->
472485
assertEquals("25", status.param("max"))
473486
}
@@ -487,8 +500,10 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
487500
fun testFetchSingleChannel_WithActions_Limit_Low() {
488501
pubnub.fetchMessages(
489502
channels = listOf(randomValue()),
490-
includeMessageActions = true,
491-
maximumPerChannel = -1
503+
page = PNBoundedPage(
504+
limit = -1
505+
),
506+
includeMessageActions = true
492507
).await { _, status ->
493508
assertEquals("25", status.param("max"))
494509
}
@@ -498,8 +513,10 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
498513
fun testFetchSingleChannel_WithActions_Limit_High() {
499514
pubnub.fetchMessages(
500515
channels = listOf(randomValue()),
501-
includeMessageActions = true,
502-
maximumPerChannel = 200
516+
page = PNBoundedPage(
517+
limit = 200
518+
),
519+
includeMessageActions = true
503520
).await { _, status ->
504521
assertEquals("25", status.param("max"))
505522
}
@@ -509,8 +526,10 @@ class HistoryIntegrationTest : BaseIntegrationTest() {
509526
fun testFetchSingleChannel_WithActions_Limit_Valid() {
510527
pubnub.fetchMessages(
511528
channels = listOf(randomValue()),
512-
includeMessageActions = true,
513-
maximumPerChannel = 15
529+
page = PNBoundedPage(
530+
limit = 15
531+
),
532+
includeMessageActions = true
514533
).await { _, status ->
515534
assertEquals("15", status.param("max"))
516535
}

0 commit comments

Comments
 (0)