Skip to content

MoralAlberto/SlackWebAPIKit

Repository files navigation

CocoaPods Twitter: @albertmoral

SlackWebAPIKit

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

SlackWebAPIKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SlackWebAPIKit"

Examples

The following examples are used in Slackfari

Get users

getUsers()
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] users in
        guard let strongSelf = self else { return }
        strongSelf.buildUsersViewModel(users: users)
    }, onError: { error in
        print("Error \(error)")
}).disposed(by: disposeBag)

Get Channels

getChannels()
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] channels in
        guard let strongSelf = self else { return }
        strongSelf.buildChannelsViewModel(channels: channels)
    }, onError: { error in
        print("Error \(error)")
}).disposed(by: disposeBag)

Get Groups (Private Channels)

getGroups()
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] groups in
        guard let strongSelf = self else { return }
        strongSelf.buildGroupsViewModel(groups: groups)
    }, onError: { error in
        print("Error \( error)")
}).disposed(by: disposeBag)

Get Team Info

getTeamInfo()
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] team in
        guard let strongSelf = self else { return }
        guard let name = team.name else { return }
        strongSelf.delegate?.update(team: name)
    }, onError: { [weak self] error in
        guard let strongSelf = self else { return }
        strongSelf.delegate?.update(team: "Error")
    }, onCompleted: {
        print("Completed")
}).disposed(by: disposeBag)

Send Message

send(message: message, channel: channel, type: type)
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] isSent in
        guard let strongSelf = self else { return }
        strongSelf.delegate?.update(notification: "Last message sent to: \(channel)")
    }, onError: { [weak self] error in
        guard let strongSelf = self else { return }
        strongSelf.delegate?.update(notification: "Error trying to send the message")
}).disposed(by: disposeBag)

Author

MoralAlberto, alberto.moral.g@gmail.com

License

SlackWebAPIKit is available under the MIT license. See the LICENSE file for more info.