Skip to content
This repository was archived by the owner on Dec 2, 2022. It is now read-only.

Commit d8c8c3c

Browse files
committed
Updates
1 parent 02eff54 commit d8c8c3c

File tree

3 files changed

+85
-23
lines changed

3 files changed

+85
-23
lines changed

README.md

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
![SlackKit](https://cloud.githubusercontent.com/assets/8311605/10260893/5ec60f96-694e-11e5-91fd-da6845942201.png)
22
##iOS/OS X Slack Client Library
33
###Description
4-
This is a Slack client library for iOS and OS X written in Swift. It's intended to expose all of the functionality of Slack's [Real Time Messaging API](https://api.slack.com/rtm).
4+
This is a Slack client library for iOS and OS X written in Swift. It's intended to expose all of the functionality of Slack's [Real Time Messaging API](https://api.slack.com/rtm) as well as the [web APIs](https://api.slack.com/web) that are accessible by [bot users](https://api.slack.com/bot-users).
55

66
###Installation
7-
####Swift Package Manager (Swift 2.2 and up)
7+
####Swift Package Manager
88
Add SlackKit to your Package.swift
99

1010
```swift
@@ -37,17 +37,88 @@ import SlackKit
3737
###Usage
3838
To use SlackKit you'll need a bearer token which identifies a single user. You can generate a [full access token or create one using OAuth 2](https://api.slack.com/web).
3939

40-
Once you have a token, give it to the Client:
40+
Once you have a token, initialize a client instance using it:
4141
```swift
42-
Client.sharedInstance.setAuthToken("YOUR_SLACK_AUTH_TOKEN")
42+
let client = Client(apiToken: "YOUR_SLACK_API_TOKEN")
43+
4344
```
44-
and connect:
45+
46+
If you want to receive messages from the Slack RTM API, connect to it.
4547
```swift
46-
Client.sharedInstance.connect()
48+
client.connect()
4749
```
50+
4851
Once connected, the client will begin to consume any messages sent by the Slack RTM API.
4952

53+
####Web API Methods
54+
SlackKit currently supports the a subset of the Slack Web APIs that is available to bot users:
55+
56+
- api.test
57+
- auth.test
58+
- channels.history
59+
- channels.info
60+
- channels.list
61+
- channels.mark
62+
- channels.setPurpose
63+
- channels.setTopic
64+
- chat.delete
65+
- chat.postMessage
66+
- chat.update
67+
- emoji.list
68+
- files.delete
69+
- files.upload
70+
- groups.close
71+
- groups.history
72+
- groups.info
73+
- groups.list
74+
- groups.mark
75+
- groups.open
76+
- groups.setPurpose
77+
- groups.setTopic
78+
- im.close
79+
- im.history
80+
- im.list
81+
- im.mark
82+
- im.open
83+
- mpim.close
84+
- mpim.history
85+
- mpim.list
86+
- mpim.mark
87+
- mpim.open
88+
- pins.add
89+
- pins.list
90+
- pins.remove
91+
- reactions.add
92+
- reactions.get
93+
- reactions.list
94+
- reactions.remove
95+
- rtm.start
96+
- stars.add
97+
- stars.remove
98+
- team.info
99+
- users.getPresence
100+
- users.info
101+
- users.list
102+
- users.setActive
103+
- users.setPresence
104+
105+
They can be accessed through a Client object’s `webAPI` property:
106+
```swift
107+
client.webAPI.authenticationTest({
108+
(authenticated) -> Void in
109+
print(authenticated)
110+
}){(error) -> Void in
111+
print(error)
112+
}
113+
```
114+
50115
####Delegate methods
116+
117+
To receive delegate callbacks for certain events, register an object as the delegate for those events:
118+
```swift
119+
client.slackEventsDelegate = self
120+
```
121+
51122
There are a number of delegates that you can set to receive callbacks for certain events.
52123

53124
#####SlackEventsDelegate
@@ -138,18 +209,6 @@ func subteamSelfAdded(subteamID: String)
138209
func subteamSelfRemoved(subteamID: String)
139210
```
140211

141-
###Examples
142-
####Sending a Message:
143-
```swift
144-
Client.sharedInstance.sendMessage(message: "Hello, world!", channelID: "CHANNEL_ID")
145-
```
146-
147-
####Print a List of Users in a Channel:
148-
```swift
149-
let users = Client.sharedInstance.channels?["CHANNEL_ID"]?.members
150-
print(users)
151-
```
152-
153212
###Get In Touch
154213
[@pvzig](https://twitter.com/pvzig)
155214

SlackKit/Sources/Client.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ public class Client: WebSocketDelegate {
5757
self.token = token
5858
}
5959

60-
public var webAPI: SlackWebAPI?
60+
public var webAPI: SlackWebAPI {
61+
return SlackWebAPI(client: self)
62+
}
6163

6264
internal var webSocket: WebSocket?
6365
private var dispatcher: EventDispatcher?
6466

6567
internal let api = NetworkInterface()
6668

67-
required public init() {}
69+
required public init(apiToken: String) {
70+
self.token = apiToken
71+
}
6872

6973
public func connect() {
7074
dispatcher = EventDispatcher(client: self)
71-
webAPI = SlackWebAPI(client: self)
72-
webAPI?.rtmStart(success: {
75+
webAPI.rtmStart(success: {
7376
(response) -> Void in
7477
self.initialSetup(response)
7578
if let socketURL = response["url"] as? String {

SlackKit/Sources/ClientExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension Client {
4949
if let channel = channel {
5050
success(imID: channel.0)
5151
} else {
52-
webAPI?.openIM(id, success: success, failure: failure)
52+
webAPI.openIM(id, success: success, failure: failure)
5353
}
5454
}
5555

0 commit comments

Comments
 (0)