Skip to content

Commit 79ff05d

Browse files
committed
v2.searchSpaces
1 parent f8e950f commit 79ff05d

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

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

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,5 +590,20 @@ interface TwitterV2 {
590590
userFields: String? = null,
591591
): SpacesResponse
592592

593+
/**
594+
* The recent search endpoint returns Tweets from the last seven days that match a search query.
595+
*
596+
* @throws TwitterException when Twitter service or network is unavailable
597+
* @see "https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent"
598+
*/
599+
@Throws(TwitterException::class)
600+
fun searchSpaces(
601+
query: String,
602+
state: Space.State,
603+
expansions: String? = null,
604+
maxResults: Int? = null,
605+
spaceFields: String? = null,
606+
userFields: String? = null,
607+
): SpacesResponse
593608

594609
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,32 @@ class TwitterV2Impl(private val twitter: Twitter) : TwitterV2 {
10571057
)
10581058
}
10591059

1060+
@Throws(TwitterException::class)
1061+
override fun searchSpaces(
1062+
query: String,
1063+
state: Space.State,
1064+
expansions: String?,
1065+
maxResults: Int?,
1066+
spaceFields: String?,
1067+
userFields: String?,
1068+
): SpacesResponse {
1069+
1070+
val params = arrayListOf(
1071+
HttpParameter("query", query),
1072+
HttpParameter("state", state.rawValue),
1073+
)
1074+
1075+
V2Util.addHttpParamIfNotNull(params, "expansions", expansions)
1076+
V2Util.addHttpParamIfNotNull(params, "max_results", maxResults)
1077+
V2Util.addHttpParamIfNotNull(params, "space.fields", spaceFields)
1078+
V2Util.addHttpParamIfNotNull(params, "user.fields", userFields)
1079+
1080+
return V2ResponseFactory().createSpacesResponse(
1081+
get(conf.v2Configuration.baseURL + "spaces/search", params.toTypedArray()),
1082+
conf
1083+
)
1084+
}
1085+
10601086
//--------------------------------------------------
10611087
// get/post/delete
10621088
//--------------------------------------------------

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import org.junit.Test
77
class SearchSpacesTest {
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")
1414
fun searchSpaces_minimum() {
1515

1616
// Scheduled
17-
twitter.searchSpaces("a", Space.State.Scheduled).let { res ->
17+
twitter.v2.searchSpaces("a", Space.State.Scheduled).let { res ->
1818
println(res)
1919

2020
val json = JSONObject(TwitterObjectFactory.getRawJSON(res))
@@ -33,7 +33,7 @@ class SearchSpacesTest {
3333
}
3434

3535
// Live
36-
twitter.searchSpaces("a", Space.State.Live).let { res ->
36+
twitter.v2.searchSpaces("a", Space.State.Live).let { res ->
3737
println(res)
3838

3939
val json = JSONObject(TwitterObjectFactory.getRawJSON(res))
@@ -56,7 +56,7 @@ class SearchSpacesTest {
5656
@Ignore("expiration time of oauth2.accessToken is too short")
5757
fun searchSpaces_full_result() {
5858

59-
val res = twitter.searchSpaces(
59+
val res = twitter.v2.searchSpaces(
6060
"a",
6161
Space.State.Live,
6262
maxResults = 10,

0 commit comments

Comments
 (0)