Skip to content

Commit f8e950f

Browse files
committed
v2.getSpaces, v2.getSpacesByCreatorIds
1 parent 9b4f1d0 commit f8e950f

File tree

4 files changed

+75
-79
lines changed

4 files changed

+75
-79
lines changed

twitter4j-v2-support/src/main/kotlin/twitter4j/SpacesLookupEx.kt

Lines changed: 0 additions & 76 deletions
This file was deleted.

twitter4j-v2-support/src/main/kotlin/twitter4j/TwitterV2.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,5 +562,33 @@ interface TwitterV2 {
562562
targetUserId: Long
563563
): BooleanResponse
564564

565+
/**
566+
* Returns details about multiple Spaces. Up to 100 comma-separated Spaces IDs can be looked up using this endpoint.
567+
*
568+
* @throws TwitterException when Twitter service or network is unavailable
569+
* @see "https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces"
570+
*/
571+
@Throws(TwitterException::class)
572+
fun getSpaces(
573+
vararg spaceIds: String,
574+
expansions: String? = null,
575+
spaceFields: String? = null,
576+
userFields: String? = null,
577+
): SpacesResponse
578+
579+
/**
580+
* Returns live or scheduled Spaces created by the specified user IDs. Up to 100 comma-separated IDs can be looked up using this endpoint.
581+
*
582+
* @throws TwitterException when Twitter service or network is unavailable
583+
* @see "https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids"
584+
*/
585+
@Throws(TwitterException::class)
586+
fun getSpacesByCreatorIds(
587+
vararg userIds: Long,
588+
expansions: String? = null,
589+
spaceFields: String? = null,
590+
userFields: String? = null,
591+
): SpacesResponse
592+
565593

566594
}

twitter4j-v2-support/src/main/kotlin/twitter4j/TwitterV2Impl.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,50 @@ class TwitterV2Impl(private val twitter: Twitter) : TwitterV2 {
10131013
)
10141014
}
10151015

1016+
@Throws(TwitterException::class)
1017+
override fun getSpaces(
1018+
vararg spaceIds: String,
1019+
expansions: String?,
1020+
spaceFields: String?,
1021+
userFields: String?,
1022+
): SpacesResponse {
1023+
1024+
val params = arrayListOf(
1025+
HttpParameter("ids", spaceIds.joinToString(",")),
1026+
)
1027+
1028+
V2Util.addHttpParamIfNotNull(params, "expansions", expansions)
1029+
V2Util.addHttpParamIfNotNull(params, "space.fields", spaceFields)
1030+
V2Util.addHttpParamIfNotNull(params, "user.fields", userFields)
1031+
1032+
return V2ResponseFactory().createSpacesResponse(
1033+
get(conf.v2Configuration.baseURL + "spaces", params.toTypedArray()),
1034+
conf
1035+
)
1036+
}
1037+
1038+
@Throws(TwitterException::class)
1039+
override fun getSpacesByCreatorIds(
1040+
vararg userIds: Long,
1041+
expansions: String?,
1042+
spaceFields: String?,
1043+
userFields: String?,
1044+
): SpacesResponse {
1045+
1046+
val params = arrayListOf(
1047+
HttpParameter("user_ids", userIds.joinToString(",")),
1048+
)
1049+
1050+
V2Util.addHttpParamIfNotNull(params, "expansions", expansions)
1051+
V2Util.addHttpParamIfNotNull(params, "space.fields", spaceFields)
1052+
V2Util.addHttpParamIfNotNull(params, "user.fields", userFields)
1053+
1054+
return V2ResponseFactory().createSpacesResponse(
1055+
get(conf.v2Configuration.baseURL + "spaces/by/creator_ids", params.toTypedArray()),
1056+
conf
1057+
)
1058+
}
1059+
10161060
//--------------------------------------------------
10171061
// get/post/delete
10181062
//--------------------------------------------------

twitter4j-v2-support/src/test/kotlin/twitter4j/SpacesLookupTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.junit.Test
77
class SpacesLookupTest {
88

99
private val twitter by lazy { V2TestUtil.createOAuth2TwitterInstance() }
10-
private val myId by lazy { twitter.verifyCredentials().id }
10+
// private val myId by lazy { twitter.verifyCredentials().id }
1111

1212
@Test
1313
@Ignore("expiration time of oauth2.accessToken is too short")
@@ -33,7 +33,7 @@ class SpacesLookupTest {
3333
//--------------------------------------------------
3434
println("getSpaces")
3535
println("=====================")
36-
val res = twitter.getSpaces(*spaceIds)
36+
val res = twitter.v2.getSpaces(*spaceIds)
3737
println(res)
3838

3939
val json = JSONObject(TwitterObjectFactory.getRawJSON(res))
@@ -75,7 +75,7 @@ class SpacesLookupTest {
7575
//--------------------------------------------------
7676
println("getSpacesByCreatorIds")
7777
println("=====================")
78-
val res = twitter.getSpacesByCreatorIds(*creatorIds)
78+
val res = twitter.v2.getSpacesByCreatorIds(*creatorIds)
7979
println(res)
8080

8181
val json = JSONObject(TwitterObjectFactory.getRawJSON(res))

0 commit comments

Comments
 (0)