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

Commit

Permalink
Merge pull request #65 from pvzig/minor-updates
Browse files Browse the repository at this point in the history
Code styling
  • Loading branch information
pvzig authored Jan 4, 2017
2 parents 346499e + d60a709 commit 29739db
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 371 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ and run
```
carthage bootstrap
```
**Note:** SlackKit currently takes a _long_ time for the compiler to compile with optimizations turned on. I'm currently exploring a potential fix for this issue. In the meantime, you may want to skip the waiting and build it in the debug configuration instead:
```
carthage bootstrap --configuration "Debug"
```
**Note:** If you’re seeing long compile times with optimizations turned on, try updating to the latest version of Xcode, 8.2.1.

Drag the built `SlackKit.framework` into your Xcode project.

Expand Down
12 changes: 6 additions & 6 deletions SlackKit/Sources/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct Action {
confirm = Confirm(confirm:action?["confirm"] as? [String: Any])
}

public init(name: String, text: String, style: ActionStyle = .Default, value: String? = nil, confirm: Confirm? = nil) {
public init(name: String, text: String, style: ActionStyle = .defaultStyle, value: String? = nil, confirm: Confirm? = nil) {
self.type = "button"
self.name = name
self.text = text
Expand Down Expand Up @@ -92,12 +92,12 @@ public struct Action {
}

public enum ActionStyle: String {
case Default = "default"
case Primary = "primary"
case Danger = "danger"
case defaultStyle = "default"
case primary = "primary"
case danger = "danger"
}

public enum ResponseType: String {
case InChannel = "in_channel"
case Ephemeral = "ephemeral"
case inChannel = "in_channel"
case ephemeral = "ephemeral"
}
6 changes: 3 additions & 3 deletions SlackKit/Sources/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public struct Attachment {
}

public enum AttachmentColor: String {
case Good = "good"
case Warning = "warning"
case Danger = "danger"
case good = "good"
case warning = "warning"
case danger = "danger"
}
24 changes: 12 additions & 12 deletions SlackKit/Sources/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class Client: WebSocketDelegate {
}

internal var webSocket: WebSocket?
fileprivate let pingPongQueue = DispatchQueue(label: "com.launchsoft.SlackKit")
private let pingPongQueue = DispatchQueue(label: "com.launchsoft.SlackKit")
internal var ping: Double?
internal var pong: Double?
internal var options: ClientOptions?
Expand Down Expand Up @@ -101,7 +101,7 @@ public final class Client: WebSocketDelegate {
}
}

fileprivate func format(message: String, channel: String) throws -> Data {
private func format(message: String, channel: String) throws -> Data {
let json: [String: Any] = [
"id": Date().slackTimestamp,
"type": "message",
Expand All @@ -112,7 +112,7 @@ public final class Client: WebSocketDelegate {
return try JSONSerialization.data(withJSONObject: json, options: [])
}

fileprivate func addSentMessage(_ dictionary: [String: Any]) {
private func addSentMessage(_ dictionary: [String: Any]) {
var message = dictionary
guard let id = message["id"] as? NSNumber else {
return
Expand All @@ -125,7 +125,7 @@ public final class Client: WebSocketDelegate {
}

//MARK: - RTM Ping
fileprivate func pingRTMServerAt(interval: TimeInterval) {
private func pingRTMServerAt(interval: TimeInterval) {
let delay = DispatchTime.now() + Double(Int64(interval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
pingPongQueue.asyncAfter(deadline: delay, execute: {
guard self.connected && self.timeoutCheck() else {
Expand All @@ -137,7 +137,7 @@ public final class Client: WebSocketDelegate {
})
}

fileprivate func sendRTMPing() {
private func sendRTMPing() {
guard connected else {
return
}
Expand All @@ -154,7 +154,7 @@ public final class Client: WebSocketDelegate {
}
}

fileprivate func timeoutCheck() -> Bool {
private func timeoutCheck() -> Bool {
if let pong = pong, let ping = ping, let timeout = options?.timeout {
if pong - ping < timeout {
return true
Expand All @@ -168,7 +168,7 @@ public final class Client: WebSocketDelegate {
}

//MARK: - Client setup
fileprivate func initialSetup(JSON: [String: Any]) {
private func initialSetup(JSON: [String: Any]) {
team = Team(team: JSON["team"] as? [String: Any])
authenticatedUser = User(user: JSON["self"] as? [String: Any])
authenticatedUser?.doNotDisturbStatus = DoNotDisturbStatus(status: JSON["dnd"] as? [String: Any])
Expand All @@ -181,28 +181,28 @@ public final class Client: WebSocketDelegate {
enumerateSubteams(JSON["subteams"] as? [String: Any])
}

fileprivate func addUser(_ aUser: [String: Any]) {
private func addUser(_ aUser: [String: Any]) {
let user = User(user: aUser)
if let id = user.id {
users[id] = user
}
}

fileprivate func addChannel(_ aChannel: [String: Any]) {
private func addChannel(_ aChannel: [String: Any]) {
let channel = Channel(channel: aChannel)
if let id = channel.id {
channels[id] = channel
}
}

fileprivate func addBot(_ aBot: [String: Any]) {
private func addBot(_ aBot: [String: Any]) {
let bot = Bot(bot: aBot)
if let id = bot.id {
bots[id] = bot
}
}

fileprivate func enumerateSubteams(_ subteams: [String: Any]?) {
private func enumerateSubteams(_ subteams: [String: Any]?) {
if let subteams = subteams {
if let all = subteams["all"] as? [[String: Any]] {
for item in all {
Expand All @@ -222,7 +222,7 @@ public final class Client: WebSocketDelegate {
}

// MARK: - Utilities
fileprivate func enumerateObjects(_ array: [Any]?, initalizer: ([String: Any])-> Void) {
private func enumerateObjects(_ array: [Any]?, initalizer: ([String: Any])-> Void) {
if let array = array {
for object in array {
if let dictionary = object as? [String: Any] {
Expand Down
2 changes: 1 addition & 1 deletion SlackKit/Sources/IncomingWebhook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct IncomingWebhook {
}
}

fileprivate func jsonBody(_ response: [String: Any]) -> [String: Any] {
private func jsonBody(_ response: [String: Any]) -> [String: Any] {
var json = response
json["channel"] = channel
json["username"] = username
Expand Down
9 changes: 3 additions & 6 deletions SlackKit/Sources/NetworkInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ internal struct NetworkInterface {
}
let request = URLRequest(url:url)

URLSession.shared.dataTask(with: request) {
(data, response, internalError) -> Void in
URLSession.shared.dataTask(with: request) {(data, response, internalError) in
do {
successClosure(try self.handleResponse(data, response: response, internalError: internalError))
} catch let error {
Expand All @@ -62,8 +61,7 @@ internal struct NetworkInterface {
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.httpBody = data

URLSession.shared.dataTask(with: request) {
(data, response, internalError) -> Void in
URLSession.shared.dataTask(with: request) {(data, response, internalError) in
if internalError == nil {
success(true)
} else {
Expand Down Expand Up @@ -101,8 +99,7 @@ internal struct NetworkInterface {
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.httpBody = requestBodyData as Data

URLSession.shared.dataTask(with: request) {
(data, response, internalError) -> Void in
URLSession.shared.dataTask(with: request) {(data, response, internalError) in
do {
successClosure(try self.handleResponse(data, response: response, internalError: internalError))
} catch let error {
Expand Down
18 changes: 9 additions & 9 deletions SlackKit/Sources/OAuthServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ internal protocol OAuthDelegate {

public struct OAuthServer {

fileprivate let oauthURL = "https://slack.com/oauth/authorize"
private let oauthURL = "https://slack.com/oauth/authorize"

fileprivate let http = HttpServer()
fileprivate let clientID: String
fileprivate let clientSecret: String
fileprivate let state: String?
fileprivate let redirectURI: String?
fileprivate var delegate: OAuthDelegate?
private let http = HttpServer()
private let clientID: String
private let clientSecret: String
private let state: String?
private let redirectURI: String?
private var delegate: OAuthDelegate?

internal init(clientID: String, clientSecret: String, state: String? = nil, redirectURI: String? = nil, port:in_port_t = 8080, forceIPV4: Bool = false, delegate: OAuthDelegate? = nil) throws {
self.clientID = clientID
Expand All @@ -61,7 +61,7 @@ public struct OAuthServer {
http.stop()
}

fileprivate func oauthRoute() {
private func oauthRoute() {
http["/oauth"] = { request in
guard let response = AuthorizeResponse(queryParameters: request.queryParams), response.state == self.state else {
return .badRequest(.text("Bad request."))
Expand All @@ -78,7 +78,7 @@ public struct OAuthServer {
}
}

fileprivate func oauthURLRequest(_ authorize: AuthorizeRequest) -> URLRequest? {
private func oauthURLRequest(_ authorize: AuthorizeRequest) -> URLRequest? {
var requestString = "\(oauthURL)?client_id=\(authorize.clientID)"
requestString += authorize.parameters.requestStringFromParameters
guard let url = URL(string: requestString) else {
Expand Down
2 changes: 1 addition & 1 deletion SlackKit/Sources/SlackKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class SlackKit: OAuthDelegate {

internal(set) public var oauth: OAuthServer?
internal(set) public var clients: [String: Client] = [:]
fileprivate let clientOptions: ClientOptions
private let clientOptions: ClientOptions
// Initalization block
public var onClientInitalization: ((Client) -> Void)?

Expand Down
Loading

0 comments on commit 29739db

Please sign in to comment.