Skip to content

Commit

Permalink
Set channel topic
Browse files Browse the repository at this point in the history
  • Loading branch information
sjednac committed Aug 4, 2015
1 parent 4cb59ba commit b674f05
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -11,6 +11,7 @@ is subject to frequent change._
- auth.test
- channels.history
- channels.list
- channels.setTopic
- chat.delete
- chat.postMessage
- chat.update
Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/com/flyberrycapital/slack/Methods/Channels.scala
Expand Up @@ -134,4 +134,21 @@ class Channels(httpClient: HttpClient, apiToken: String) {

ChannelListResponse((responseDict \ "ok").as[Boolean], channels)
}

/**
* https://api.slack.com/methods/channels.setTopic
*
* @param channel The channel ID to set topic for
* @param topic The topic to set
* @param params A map of optional parameters and their values.
* @return A ChannelSetTopicResponse object.
*/
def setTopic(channel: String, topic: String, params: Map[String, String] = Map()): ChannelSetTopicResponse = {

val cleanedParams = params + ("channel" -> channel, "topic" -> topic, "token" -> apiToken)

val responseDict = httpClient.get("channels.setTopic", cleanedParams)

ChannelSetTopicResponse((responseDict \ "ok").as[Boolean], (responseDict \ "topic").as[String])
}
}
1 change: 1 addition & 0 deletions src/main/scala/com/flyberrycapital/slack/Responses.scala
Expand Up @@ -37,6 +37,7 @@ object Responses {
case class ChannelHistoryResponse(ok: Boolean, messages: List[SlackMessage],
hasMore: Boolean, isLimited: Boolean)
case class ChannelListResponse(ok: Boolean, channels: List[SlackChannel]) extends SlackResponse
case class ChannelSetTopicResponse(ok: Boolean, topic: String) extends SlackResponse
case class IMCloseResponse(ok: Boolean, no_op: Boolean, already_closed: Boolean) extends SlackResponse
case class IMMarkResponse(ok: Boolean) extends SlackResponse
case class IMOpenResponse(ok: Boolean, channelId: String, no_op: Boolean,
Expand Down
18 changes: 18 additions & 0 deletions src/test/scala/ChannelsSpec.scala
Expand Up @@ -185,6 +185,15 @@ class ChannelsSpec extends FlatSpec with MockitoSugar with Matchers with BeforeA
|}
""".stripMargin))

when(mockHttpClient.get("channels.setTopic", Map("channel" -> "C12345", "topic" -> "Test Topic", "token" -> testApiKey)))
.thenReturn(Json.parse(
"""
|{
| "ok": true,
| "topic": "Test Topic"
|}
""".stripMargin))

channels = new Channels(mockHttpClient, testApiKey)
}

Expand Down Expand Up @@ -235,4 +244,13 @@ class ChannelsSpec extends FlatSpec with MockitoSugar with Matchers with BeforeA
verify(mockHttpClient).get("channels.list", Map("token" -> testApiKey))
}

"Channels.setTopic()" should "make a call to channels.setTopic and return the response in an ChannelSetTopicResponse object" in {
val response = channels.setTopic("C12345", "Test Topic")

response.ok shouldBe true
response.topic shouldBe "Test Topic"

verify(mockHttpClient).get("channels.setTopic", Map("channel" -> "C12345", "topic" -> "Test Topic", "token" -> testApiKey))
}

}

0 comments on commit b674f05

Please sign in to comment.