<commit_before>// Copyright 2015-2016 the slack-rs authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Get info on your team's Slack channels, create or archive channels, invite
//! users, set the topic and purpose, and mark a channel as read.
//!
//! For more information, see [Slack's API
//! documentation](https://api.slack.com/methods).

use std::collections::HashMap;
use hyper;

use super::ApiResult;
use super::make_authed_api_call;

/// Archives a channel.
///
/// Wraps https://api.slack.com/methods/channels.archive
pub fn archive(client: &hyper::Client, token: &str, channel: &str) -> ApiResult<ArchiveResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    make_authed_api_call(client, "channels.archive", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct ArchiveResponse;

/// Creates a channel.
///
/// Wraps https://api.slack.com/methods/channels.create
pub fn create(client: &hyper::Client, token: &str, name: &str) -> ApiResult<CreateResponse> {
    let mut params = HashMap::new();
    params.insert("name", name);
    make_authed_api_call(client, "channels.create", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct CreateResponse {
    pub channel: super::Channel,
}

/// Fetches history of messages and events from a channel.
///
/// Wraps https://api.slack.com/methods/channels.history
pub fn history(client: &hyper::Client,
               token: &str,
               channel: &str,
               latest: Option<&str>,
               oldest: Option<&str>,
               inclusive: Option<bool>,
               count: Option<u32>)
               -> ApiResult<HistoryResponse> {
    let count = count.map(|c| c.to_string());
    let mut params = HashMap::new();
    params.insert("channel", channel);
    if let Some(latest) = latest {
        params.insert("latest", latest);
    }
    if let Some(oldest) = oldest {
        params.insert("oldest", oldest);
    }
    if let Some(inclusive) = inclusive {
        params.insert("inclusive",
                      if inclusive {
                          "1"
                      } else {
                          "0"
                      });
    }
    if let Some(ref count) = count {
        params.insert("count", count);
    }
    make_authed_api_call(client, "channels.history", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct HistoryResponse {
    pub latest: Option<String>,
    pub oldest: Option<String>,
    pub messages: Vec<super::Message>,
    pub has_more: bool,
}

/// Gets information about a channel.
///
/// Wraps https://api.slack.com/methods/channels.info
pub fn info(client: &hyper::Client, token: &str, channel: &str) -> ApiResult<InfoResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    make_authed_api_call(client, "channels.info", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct InfoResponse {
    channel: super::Channel,
}

/// Invites a user to a channel.
///
/// Wraps https://api.slack.com/methods/channels.invite
pub fn invite(client: &hyper::Client, token: &str, channel: &str, user: &str) -> ApiResult<InviteResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    params.insert("user", user);
    make_authed_api_call(client, "channels.invite", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct InviteResponse {
    channel: super::Channel,
}

/// Joins a channel, creating it if needed.
///
/// Wraps https://api.slack.com/methods/channels.join
pub fn join(client: &hyper::Client, token: &str, name: &str) -> ApiResult<JoinResponse> {
    let mut params = HashMap::new();
    params.insert("name", name);
    make_authed_api_call(client, "channels.join", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct JoinResponse {
    already_in_channel: Option<bool>,
    channel: super::Channel,
}

/// Removes a user from a channel.
///
/// Wraps https://api.slack.com/methods/channels.kick
pub fn kick(client: &hyper::Client, token: &str, channel: &str, user: &str) -> ApiResult<KickResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    params.insert("user", user);
    make_authed_api_call(client, "channels.kick", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct KickResponse;

/// Leaves a channel.
///
/// Wraps https://api.slack.com/methods/channels.leave
pub fn leave(client: &hyper::Client, token: &str, channel: &str) -> ApiResult<LeaveResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    make_authed_api_call(client, "channels.leave", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct LeaveResponse {
    pub not_in_channel: Option<bool>,
}<commit_msg>Add missing pub from fields in structs that were missing them<commit_after>// Copyright 2015-2016 the slack-rs authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Get info on your team's Slack channels, create or archive channels, invite
//! users, set the topic and purpose, and mark a channel as read.
//!
//! For more information, see [Slack's API
//! documentation](https://api.slack.com/methods).

use std::collections::HashMap;
use hyper;

use super::ApiResult;
use super::make_authed_api_call;

/// Archives a channel.
///
/// Wraps https://api.slack.com/methods/channels.archive
pub fn archive(client: &hyper::Client, token: &str, channel: &str) -> ApiResult<ArchiveResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    make_authed_api_call(client, "channels.archive", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct ArchiveResponse;

/// Creates a channel.
///
/// Wraps https://api.slack.com/methods/channels.create
pub fn create(client: &hyper::Client, token: &str, name: &str) -> ApiResult<CreateResponse> {
    let mut params = HashMap::new();
    params.insert("name", name);
    make_authed_api_call(client, "channels.create", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct CreateResponse {
    pub channel: super::Channel,
}

/// Fetches history of messages and events from a channel.
///
/// Wraps https://api.slack.com/methods/channels.history
pub fn history(client: &hyper::Client,
               token: &str,
               channel: &str,
               latest: Option<&str>,
               oldest: Option<&str>,
               inclusive: Option<bool>,
               count: Option<u32>)
               -> ApiResult<HistoryResponse> {
    let count = count.map(|c| c.to_string());
    let mut params = HashMap::new();
    params.insert("channel", channel);
    if let Some(latest) = latest {
        params.insert("latest", latest);
    }
    if let Some(oldest) = oldest {
        params.insert("oldest", oldest);
    }
    if let Some(inclusive) = inclusive {
        params.insert("inclusive",
                      if inclusive {
                          "1"
                      } else {
                          "0"
                      });
    }
    if let Some(ref count) = count {
        params.insert("count", count);
    }
    make_authed_api_call(client, "channels.history", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct HistoryResponse {
    pub latest: Option<String>,
    pub oldest: Option<String>,
    pub messages: Vec<super::Message>,
    pub has_more: bool,
}

/// Gets information about a channel.
///
/// Wraps https://api.slack.com/methods/channels.info
pub fn info(client: &hyper::Client, token: &str, channel: &str) -> ApiResult<InfoResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    make_authed_api_call(client, "channels.info", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct InfoResponse {
    pub channel: super::Channel,
}

/// Invites a user to a channel.
///
/// Wraps https://api.slack.com/methods/channels.invite
pub fn invite(client: &hyper::Client, token: &str, channel: &str, user: &str) -> ApiResult<InviteResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    params.insert("user", user);
    make_authed_api_call(client, "channels.invite", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct InviteResponse {
    pub channel: super::Channel,
}

/// Joins a channel, creating it if needed.
///
/// Wraps https://api.slack.com/methods/channels.join
pub fn join(client: &hyper::Client, token: &str, name: &str) -> ApiResult<JoinResponse> {
    let mut params = HashMap::new();
    params.insert("name", name);
    make_authed_api_call(client, "channels.join", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct JoinResponse {
    pub already_in_channel: Option<bool>,
    pub channel: super::Channel,
}

/// Removes a user from a channel.
///
/// Wraps https://api.slack.com/methods/channels.kick
pub fn kick(client: &hyper::Client, token: &str, channel: &str, user: &str) -> ApiResult<KickResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    params.insert("user", user);
    make_authed_api_call(client, "channels.kick", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct KickResponse;

/// Leaves a channel.
///
/// Wraps https://api.slack.com/methods/channels.leave
pub fn leave(client: &hyper::Client, token: &str, channel: &str) -> ApiResult<LeaveResponse> {
    let mut params = HashMap::new();
    params.insert("channel", channel);
    make_authed_api_call(client, "channels.leave", token, params)
}

#[derive(Clone,Debug,RustcDecodable)]
pub struct LeaveResponse {
    pub not_in_channel: Option<bool>,
}
{'fraction_non_alphanumeric': 0.1447565543071161, 'fraction_numerical': 0.00299625468164794, 'mean_word_length': 3.347171347171347, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 53, 'https://': 18, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '756039', 'n_tokens_mistral': 3248, 'n_tokens_neox': 3266, 'n_words': 894}