Skip to content

Commit

Permalink
v2.searchSpaces
Browse files Browse the repository at this point in the history
  • Loading branch information
takke committed Oct 17, 2022
1 parent f8e950f commit 79ff05d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 47 deletions.
43 changes: 0 additions & 43 deletions twitter4j-v2-support/src/main/kotlin/twitter4j/SearchSpacesEx.kt

This file was deleted.

15 changes: 15 additions & 0 deletions twitter4j-v2-support/src/main/kotlin/twitter4j/TwitterV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -590,5 +590,20 @@ interface TwitterV2 {
userFields: String? = null,
): SpacesResponse

/**
* The recent search endpoint returns Tweets from the last seven days that match a search query.
*
* @throws TwitterException when Twitter service or network is unavailable
* @see "https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent"
*/
@Throws(TwitterException::class)
fun searchSpaces(
query: String,
state: Space.State,
expansions: String? = null,
maxResults: Int? = null,
spaceFields: String? = null,
userFields: String? = null,
): SpacesResponse

}
26 changes: 26 additions & 0 deletions twitter4j-v2-support/src/main/kotlin/twitter4j/TwitterV2Impl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,32 @@ class TwitterV2Impl(private val twitter: Twitter) : TwitterV2 {
)
}

@Throws(TwitterException::class)
override fun searchSpaces(
query: String,
state: Space.State,
expansions: String?,
maxResults: Int?,
spaceFields: String?,
userFields: String?,
): SpacesResponse {

val params = arrayListOf(
HttpParameter("query", query),
HttpParameter("state", state.rawValue),
)

V2Util.addHttpParamIfNotNull(params, "expansions", expansions)
V2Util.addHttpParamIfNotNull(params, "max_results", maxResults)
V2Util.addHttpParamIfNotNull(params, "space.fields", spaceFields)
V2Util.addHttpParamIfNotNull(params, "user.fields", userFields)

return V2ResponseFactory().createSpacesResponse(
get(conf.v2Configuration.baseURL + "spaces/search", params.toTypedArray()),
conf
)
}

//--------------------------------------------------
// get/post/delete
//--------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import org.junit.Test
class SearchSpacesTest {

private val twitter by lazy { V2TestUtil.createOAuth2TwitterInstance() }
private val myId by lazy { twitter.verifyCredentials().id }
// private val myId by lazy { twitter.verifyCredentials().id }

@Test
@Ignore("expiration time of oauth2.accessToken is too short")
fun searchSpaces_minimum() {

// Scheduled
twitter.searchSpaces("a", Space.State.Scheduled).let { res ->
twitter.v2.searchSpaces("a", Space.State.Scheduled).let { res ->
println(res)

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

// Live
twitter.searchSpaces("a", Space.State.Live).let { res ->
twitter.v2.searchSpaces("a", Space.State.Live).let { res ->
println(res)

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

val res = twitter.searchSpaces(
val res = twitter.v2.searchSpaces(
"a",
Space.State.Live,
maxResults = 10,
Expand Down

0 comments on commit 79ff05d

Please sign in to comment.