Compare commits
185 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2f3731a69 | |||
| 48f80cc13d | |||
| 0396d9c6d5 | |||
| 3514b637c8 | |||
| 78ce839cc1 | |||
| 831bb20ff7 | |||
| 43dda4a2f0 | |||
| 2f0978ccc4 | |||
| 71c5eda4a1 | |||
| 4b241374ea | |||
| dd07b545c7 | |||
| af4ba6623c | |||
| 435607d170 | |||
| 8094bd2c6c | |||
| d8d22f6083 | |||
| 6fcfe2fda4 | |||
| 6ccce1875b | |||
| 433fc1a8ff | |||
| 4f64c952b8 | |||
| 139b25a7f0 | |||
| 3ee4e0fd1d | |||
| f013840cae | |||
| 79457aa13d | |||
| ac2657b7e1 | |||
| 82130f2e67 | |||
| b9573c4e8b | |||
| 6481620e7a | |||
| 35e7ead8d1 | |||
| 0f896fdaee | |||
| 8a4fceaa00 | |||
| 6007f790db | |||
| 05e7f2baa3 | |||
| 39871172e9 | |||
| 491f80741b | |||
| 0eb9ea31e1 | |||
| 8865376c3c | |||
| d86d0108ff | |||
| b45b7085ce | |||
| 91193c6b2e | |||
| 9720b1c05c | |||
| 9766a5ad6c | |||
| 1e181e7580 | |||
| f6d6c779ae | |||
| 11bb50f8d2 | |||
| d721e0ba1a | |||
| ba6066875c | |||
| 0f1a1a9de5 | |||
| a81cebf5c8 | |||
| 007ec7ab69 | |||
| b93d411f63 | |||
| 741a23809d | |||
| a92fd36c17 | |||
| e122610c04 | |||
| 0539e0bac2 | |||
| 3416161818 | |||
| 32a4aa13ea | |||
| cf188ffb6a | |||
| f1a1963ac8 | |||
| 645797b72e | |||
| b9f808f70e | |||
| 74ef3979f5 | |||
| 992879f54f | |||
| ccdf9d5d3c | |||
| 0336b5a9b6 | |||
| aefbeafd28 | |||
| bc6c07f045 | |||
| db24e66d33 | |||
| ef70f935c1 | |||
| afbf8ab6fe | |||
| d39296f496 | |||
| eafceb4645 | |||
| 83cf85a27a | |||
| 06e250a954 | |||
| 5b6622a961 | |||
| a58e291d2e | |||
| a0e1f9844e | |||
| 7d524ddeac | |||
| 94c9f7fe5a | |||
| be8a5879f3 | |||
| c657919704 | |||
| abeef21d7a | |||
| 79e3b14593 | |||
| d9a4cda9b0 | |||
| 12b316da0b | |||
| 13cade5c00 | |||
| 051e8dd6c8 | |||
| 1adea1c54e | |||
| aa51cfb2fd | |||
| 6b8885bd29 | |||
| e0fbf1ab4e | |||
| 366c6e7b77 | |||
| 378c116d9b | |||
| 58bade8ec9 | |||
| 7d7f5c40d6 | |||
| c9fd54d106 | |||
| 2f1ce799ad | |||
| 7f02f4cf99 | |||
| a9066c0d0a | |||
| 29739dba74 | |||
| d60a7094a4 | |||
| 7edd4210f6 | |||
| 2abaecbd14 | |||
| 346499e03b | |||
| bc72a52bf5 | |||
| 0ebd3cb0e7 | |||
| 5d7064ee13 | |||
| d02768ddad | |||
| dbc7b361c8 | |||
| a0de46e3c7 | |||
| 2d6e19baee | |||
| 21ec3cb2a1 | |||
| cb542da068 | |||
| 788b4e4f7a | |||
| 24b2292cba | |||
| 72866262d2 | |||
| acabbb6c03 | |||
| fff0f0befc | |||
| cf0675dac2 | |||
| 1cffa0ba74 | |||
| 9ebd8182a6 | |||
| 63a8ae7f08 | |||
| 992f94e870 | |||
| 1c476c77ad | |||
| 28bd612ca0 | |||
| 45cf2a7ac0 | |||
| f7c986c65c | |||
| ca43df4475 | |||
| ef71b6abf0 | |||
| 3ff922a2c0 | |||
| 646c371bd3 | |||
| 36401009f8 | |||
| b837554dcf | |||
| 0ba0e019ae | |||
| 8771ef3f0a | |||
| 71e7238483 | |||
| b75c10fca6 | |||
| 50f85ac103 | |||
| a7cbb84b34 | |||
| ed6789c9a5 | |||
| ca444930a4 | |||
| 21051864ec | |||
| 36d1553072 | |||
| eb14758846 | |||
| bf3a5c2422 | |||
| 98fd1342e7 | |||
| 183ed91cb8 | |||
| c241dcf1df | |||
| 8007fa6f0f | |||
| 7ab973a03b | |||
| 1889ffeeee | |||
| 987be40c91 | |||
| 2e71ac6876 | |||
| df661762a9 | |||
| c428cac537 | |||
| 18c6516df9 | |||
| fe450a7db2 | |||
| bb57f59553 | |||
| e5a4a67bdb | |||
| 1e304f1f6d | |||
| 81ebf86abd | |||
| afa16e98b3 | |||
| 6596bb2861 | |||
| fd12ab0600 | |||
| 31508e44dc | |||
| b980f371f6 | |||
| 9526d739e1 | |||
| c3af5c33be | |||
| c6258c57a0 | |||
| 45e075aca2 | |||
| 5ebe40a389 | |||
| 0a5a8f83f7 | |||
| 8f4a287ad0 | |||
| deadc8855a | |||
| 98155f00b7 | |||
| a55d3be65b | |||
| 3b8f1834f0 | |||
| 34972eb8af | |||
| f21179f567 | |||
| e1bf5a160f | |||
| c66a5fe0db | |||
| f03908bcc7 | |||
| 591b0d9d55 | |||
| 6e83fb93d8 | |||
| c1d202f433 | |||
| c7db8ac578 |
@@ -16,6 +16,7 @@ DerivedData
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
*.DS_Store
|
||||
|
||||
# SwiftPM
|
||||
Packages/
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
4.0
|
||||
@@ -0,0 +1,7 @@
|
||||
disabled_rules:
|
||||
- identifier_name
|
||||
- function_parameter_count
|
||||
line_length: 140
|
||||
excluded: # paths to ignore during linting. Takes precedence over `included`.
|
||||
- Carthage
|
||||
- Pods
|
||||
@@ -1 +1,4 @@
|
||||
github "daltoniam/Starscream" ~> 1.0
|
||||
github "SlackKit/SKCore" >= 4.1.0
|
||||
github "SlackKit/SKClient" >= 4.1.0
|
||||
github "SlackKit/SKRTMAPI" >= 4.1.0
|
||||
github "SlackKit/SKServer" >= 4.1.0
|
||||
@@ -1 +0,0 @@
|
||||
github "daltoniam/Starscream" "1.1.3"
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Peter Zignego
|
||||
Copyright (c) 2017 Peter Zignego
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// OSX-Sample
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Cocoa
|
||||
import SlackKit
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
@IBOutlet weak var window: NSWindow!
|
||||
|
||||
let leaderboard = Leaderboard(token: "SLACK_AUTH_TOKEN")
|
||||
|
||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||
leaderboard.client.connect()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(aNotification: NSNotification) {
|
||||
// Insert code here to tear down your application
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -1,680 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6233" systemVersion="14A329f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6233"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
<menuItem title="OSX-Sample" id="1Xt-HY-uBw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="OSX-Sample" systemMenu="apple" id="uQy-DD-JDr">
|
||||
<items>
|
||||
<menuItem title="About OSX-Sample" id="5kV-Vb-QxS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
|
||||
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
|
||||
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
|
||||
<menuItem title="Services" id="NMo-om-nkz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
|
||||
<menuItem title="Hide OSX-Sample" keyEquivalent="h" id="Olw-nP-bQN">
|
||||
<connections>
|
||||
<action selector="hide:" target="-1" id="PnN-Uc-m68"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Show All" id="Kd2-mp-pUS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
|
||||
<menuItem title="Quit OSX-Sample" keyEquivalent="q" id="4sb-4s-VLi">
|
||||
<connections>
|
||||
<action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="File" id="dMs-cI-mzQ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="File" id="bib-Uj-vzu">
|
||||
<items>
|
||||
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
|
||||
<connections>
|
||||
<action selector="newDocument:" target="-1" id="4Si-XN-c54"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
|
||||
<connections>
|
||||
<action selector="openDocument:" target="-1" id="bVn-NM-KNZ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Open Recent" id="tXI-mr-wws">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
|
||||
<items>
|
||||
<menuItem title="Clear Menu" id="vNY-rz-j42">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="clearRecentDocuments:" target="-1" id="Daa-9d-B3U"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
|
||||
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
|
||||
<connections>
|
||||
<action selector="performClose:" target="-1" id="HmO-Ls-i7Q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
|
||||
<connections>
|
||||
<action selector="saveDocument:" target="-1" id="teZ-XB-qJY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
|
||||
<connections>
|
||||
<action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Revert to Saved" id="KaW-ft-85H">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
|
||||
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
|
||||
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="runPageLayout:" target="-1" id="Din-rz-gC5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
|
||||
<connections>
|
||||
<action selector="print:" target="-1" id="qaZ-4w-aoO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Edit" id="5QF-Oa-p0T">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Edit" id="W48-6f-4Dl">
|
||||
<items>
|
||||
<menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
|
||||
<connections>
|
||||
<action selector="undo:" target="-1" id="M6e-cu-g7V"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
|
||||
<connections>
|
||||
<action selector="redo:" target="-1" id="oIA-Rs-6OD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
|
||||
<menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
|
||||
<connections>
|
||||
<action selector="cut:" target="-1" id="YJe-68-I9s"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
|
||||
<connections>
|
||||
<action selector="copy:" target="-1" id="G1f-GL-Joy"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
|
||||
<connections>
|
||||
<action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteAsPlainText:" target="-1" id="cEh-KX-wJQ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Delete" id="pa3-QI-u2k">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="delete:" target="-1" id="0Mk-Ml-PaM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
|
||||
<connections>
|
||||
<action selector="selectAll:" target="-1" id="VNm-Mi-diN"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
|
||||
<menuItem title="Find" id="4EN-yA-p0u">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Find" id="1b7-l0-nxx">
|
||||
<items>
|
||||
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="WD3-Gg-5AJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="NDo-RZ-v9R"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="HOh-sY-3ay"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
|
||||
<connections>
|
||||
<action selector="performFindPanelAction:" target="-1" id="U76-nv-p5D"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
|
||||
<connections>
|
||||
<action selector="centerSelectionInVisibleArea:" target="-1" id="IOG-6D-g5B"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
|
||||
<items>
|
||||
<menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
|
||||
<connections>
|
||||
<action selector="showGuessPanel:" target="-1" id="vFj-Ks-hy3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
|
||||
<connections>
|
||||
<action selector="checkSpelling:" target="-1" id="fz7-VC-reM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
|
||||
<menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleContinuousSpellChecking:" target="-1" id="7w6-Qz-0kB"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleGrammarChecking:" target="-1" id="muD-Qn-j4w"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticSpellingCorrection:" target="-1" id="2lM-Qi-WAP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Substitutions" id="9ic-FL-obx">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
|
||||
<items>
|
||||
<menuItem title="Show Substitutions" id="z6F-FW-3nz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="orderFrontSubstitutionsPanel:" target="-1" id="oku-mr-iSq"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
|
||||
<menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleSmartInsertDelete:" target="-1" id="3IJ-Se-DZD"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Quotes" id="hQb-2v-fYv">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="ptq-xd-QOA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Dashes" id="rgM-f4-ycn">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDashSubstitution:" target="-1" id="oCt-pO-9gS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smart Links" id="cwL-P1-jid">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticLinkDetection:" target="-1" id="Gip-E3-Fov"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Data Detectors" id="tRr-pd-1PS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticDataDetection:" target="-1" id="R1I-Nq-Kbl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Text Replacement" id="HFQ-gK-NFA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleAutomaticTextReplacement:" target="-1" id="DvP-Fe-Py6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Transformations" id="2oI-Rn-ZJC">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Transformations" id="c8a-y6-VQd">
|
||||
<items>
|
||||
<menuItem title="Make Upper Case" id="vmV-6d-7jI">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="uppercaseWord:" target="-1" id="sPh-Tk-edu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Make Lower Case" id="d9M-CD-aMd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowercaseWord:" target="-1" id="iUZ-b5-hil"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Capitalize" id="UEZ-Bs-lqG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="capitalizeWord:" target="-1" id="26H-TL-nsh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Speech" id="xrE-MZ-jX0">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Speech" id="3rS-ZA-NoH">
|
||||
<items>
|
||||
<menuItem title="Start Speaking" id="Ynk-f8-cLZ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="startSpeaking:" target="-1" id="654-Ng-kyl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Stop Speaking" id="Oyz-dy-DGm">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="stopSpeaking:" target="-1" id="dX8-6p-jy9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Format" id="jxT-CU-nIS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Format" id="GEO-Iw-cKr">
|
||||
<items>
|
||||
<menuItem title="Font" id="Gi5-1S-RQB">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
|
||||
<items>
|
||||
<menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq">
|
||||
<connections>
|
||||
<action selector="orderFrontFontPanel:" target="YLy-65-1bz" id="WHr-nq-2xA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27">
|
||||
<connections>
|
||||
<action selector="addFontTrait:" target="YLy-65-1bz" id="hqk-hr-sYV"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq">
|
||||
<connections>
|
||||
<action selector="addFontTrait:" target="YLy-65-1bz" id="IHV-OB-c03"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
|
||||
<connections>
|
||||
<action selector="underline:" target="-1" id="FYS-2b-JAY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
|
||||
<menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL">
|
||||
<connections>
|
||||
<action selector="modifyFont:" target="YLy-65-1bz" id="Uc7-di-UnL"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST">
|
||||
<connections>
|
||||
<action selector="modifyFont:" target="YLy-65-1bz" id="HcX-Lf-eNd"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
|
||||
<menuItem title="Kern" id="jBQ-r6-VK2">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Kern" id="tlD-Oa-oAM">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="GUa-eO-cwY">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardKerning:" target="-1" id="6dk-9l-Ckg"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="cDB-IK-hbR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffKerning:" target="-1" id="U8a-gz-Maa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Tighten" id="46P-cB-AYj">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="tightenKerning:" target="-1" id="hr7-Nz-8ro"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Loosen" id="ogc-rX-tC1">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="loosenKerning:" target="-1" id="8i4-f9-FKE"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Ligatures" id="o6e-r0-MWq">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="agt-UL-0e3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useStandardLigatures:" target="-1" id="7uR-wd-Dx6"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use None" id="J7y-lM-qPV">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="turnOffLigatures:" target="-1" id="iX2-gA-Ilz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Use All" id="xQD-1f-W4t">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="useAllLigatures:" target="-1" id="KcB-kA-TuK"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Baseline" id="OaQ-X3-Vso">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Baseline" id="ijk-EB-dga">
|
||||
<items>
|
||||
<menuItem title="Use Default" id="3Om-Ey-2VK">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unscript:" target="-1" id="0vZ-95-Ywn"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Superscript" id="Rqc-34-cIF">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="superscript:" target="-1" id="3qV-fo-wpU"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Subscript" id="I0S-gh-46l">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="subscript:" target="-1" id="Q6W-4W-IGz"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Raise" id="2h7-ER-AoG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="raiseBaseline:" target="-1" id="4sk-31-7Q9"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Lower" id="1tx-W0-xDw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="lowerBaseline:" target="-1" id="OF1-bc-KW4"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
|
||||
<menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
|
||||
<connections>
|
||||
<action selector="orderFrontColorPanel:" target="-1" id="mSX-Xz-DV3"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
|
||||
<menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyFont:" target="-1" id="GJO-xA-L4q"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteFont:" target="-1" id="JfD-CL-leO"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Text" id="Fal-I4-PZk">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Text" id="d9c-me-L2H">
|
||||
<items>
|
||||
<menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
|
||||
<connections>
|
||||
<action selector="alignLeft:" target="-1" id="zUv-R1-uAa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
|
||||
<connections>
|
||||
<action selector="alignCenter:" target="-1" id="spX-mk-kcS"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Justify" id="J5U-5w-g23">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="alignJustified:" target="-1" id="ljL-7U-jND"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
|
||||
<connections>
|
||||
<action selector="alignRight:" target="-1" id="r48-bG-YeY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
|
||||
<menuItem title="Writing Direction" id="H1b-Si-o9J">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
|
||||
<items>
|
||||
<menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="YGs-j5-SAR">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionNatural:" target="-1" id="qtV-5e-UBP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="Lbh-J2-qVU">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionLeftToRight:" target="-1" id="S0X-9S-QSf"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="jFq-tB-4Kx">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeBaseWritingDirectionRightToLeft:" target="-1" id="5fk-qB-AqJ"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
|
||||
<menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem id="Nop-cj-93Q">
|
||||
<string key="title"> Default</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionNatural:" target="-1" id="lPI-Se-ZHp"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="BgM-ve-c93">
|
||||
<string key="title"> Left to Right</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionLeftToRight:" target="-1" id="caW-Bv-w94"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem id="RB4-Sm-HuC">
|
||||
<string key="title"> Right to Left</string>
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="makeTextWritingDirectionRightToLeft:" target="-1" id="EXD-6r-ZUu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
|
||||
<menuItem title="Show Ruler" id="vLm-3I-IUL">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleRuler:" target="-1" id="FOx-HJ-KwY"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="copyRuler:" target="-1" id="71i-fW-3W2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="pasteRuler:" target="-1" id="cSh-wd-qM2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="View" id="H8h-7b-M4v">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="View" id="HyV-fh-RgO">
|
||||
<items>
|
||||
<menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="toggleToolbarShown:" target="-1" id="BXY-wc-z0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="runToolbarCustomizationPalette:" target="-1" id="pQI-g3-MTW"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Window" id="aUF-d1-5bR">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
|
||||
<items>
|
||||
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
|
||||
<connections>
|
||||
<action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Zoom" id="R4o-n2-Eq4">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
|
||||
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Help" id="wpr-3q-Mcd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
|
||||
<items>
|
||||
<menuItem title="OSX-Sample Help" keyEquivalent="?" id="FKE-Sm-Kum">
|
||||
<connections>
|
||||
<action selector="showHelp:" target="-1" id="y7X-2Q-9no"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<window title="OSX-Sample" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
|
||||
<view key="contentView" id="EiT-Mj-1SZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</view>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Launch Software LLC. All rights reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,160 +0,0 @@
|
||||
//
|
||||
// Leaderboard.swift
|
||||
// OSX-Sample
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import SlackKit
|
||||
import Foundation
|
||||
|
||||
class Leaderboard: MessageEventsDelegate {
|
||||
|
||||
var leaderboard: [String: Int] = [String: Int]()
|
||||
let atSet = NSCharacterSet(charactersInString: "@")
|
||||
|
||||
let client: Client
|
||||
|
||||
init(token: String) {
|
||||
client = Client(apiToken: token)
|
||||
client.messageEventsDelegate = self
|
||||
}
|
||||
|
||||
enum Command: String {
|
||||
case Leaderboard = "leaderboard"
|
||||
}
|
||||
|
||||
enum Trigger: String {
|
||||
case PlusPlus = "++"
|
||||
case MinusMinus = "--"
|
||||
}
|
||||
|
||||
// MARK: MessageEventsDelegate
|
||||
func messageReceived(message: Message) {
|
||||
listen(message)
|
||||
}
|
||||
|
||||
func messageSent(message: Message){}
|
||||
func messageChanged(message: Message){}
|
||||
func messageDeleted(message: Message?){}
|
||||
|
||||
// MARK: Leaderboard Internal Logic
|
||||
private func listen(message: Message) {
|
||||
if let id = client.authenticatedUser?.id, text = message.text {
|
||||
if text.lowercaseString.containsString(Command.Leaderboard.rawValue) && text.containsString(id) == true {
|
||||
handleCommand(.Leaderboard, channel: message.channel)
|
||||
}
|
||||
}
|
||||
if message.text?.containsString(Trigger.PlusPlus.rawValue) == true {
|
||||
handleMessageWithTrigger(message, trigger: .PlusPlus)
|
||||
}
|
||||
if message.text?.containsString(Trigger.MinusMinus.rawValue) == true {
|
||||
handleMessageWithTrigger(message, trigger: .MinusMinus)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleMessageWithTrigger(message: Message, trigger: Trigger) {
|
||||
if let text = message.text,
|
||||
end = text.rangeOfString(trigger.rawValue)?.startIndex.predecessor(),
|
||||
start = text.rangeOfCharacterFromSet(atSet, options: .BackwardsSearch, range: text.startIndex..<end)?.startIndex {
|
||||
let string = text.substringWithRange(start...end)
|
||||
let users = client.users.values.filter{$0.id == self.userID(string)}
|
||||
if users.count > 0 {
|
||||
let idString = userID(string)
|
||||
initalizationForValue(&leaderboard, value: idString)
|
||||
scoringForValue(&leaderboard, value: idString, trigger: trigger)
|
||||
} else {
|
||||
initalizationForValue(&leaderboard, value: string)
|
||||
scoringForValue(&leaderboard, value: string, trigger: trigger)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleCommand(command: Command, channel:String?) {
|
||||
switch command {
|
||||
case .Leaderboard:
|
||||
if let id = channel {
|
||||
client.webAPI.sendMessage(id, text: "", linkNames: true, attachments: [constructLeaderboardAttachment()], success: {(response) in
|
||||
|
||||
}, failure: { (error) in
|
||||
print("Leaderboard failed to post due to error:\(error)")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func initalizationForValue(inout dictionary: [String: Int], value: String) {
|
||||
if dictionary[value] == nil {
|
||||
dictionary[value] = 0
|
||||
}
|
||||
}
|
||||
|
||||
private func scoringForValue(inout dictionary: [String: Int], value: String, trigger: Trigger) {
|
||||
switch trigger {
|
||||
case .PlusPlus:
|
||||
dictionary[value]?+=1
|
||||
case .MinusMinus:
|
||||
dictionary[value]?-=1
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Leaderboard Interface
|
||||
private func constructLeaderboardAttachment() -> Attachment? {
|
||||
let 💯 = AttachmentField(title: "💯", value: swapIDsForNames(topItems(&leaderboard)), short: true)
|
||||
let 💩 = AttachmentField(title: "💩", value: swapIDsForNames(bottomItems(&leaderboard)), short: true)
|
||||
return Attachment(fallback: "Leaderboard", title: "Leaderboard", colorHex: AttachmentColor.Good.rawValue, text: "", fields: [💯, 💩])
|
||||
}
|
||||
|
||||
private func topItems(inout dictionary: [String: Int]) -> String {
|
||||
let sortedKeys = Array(dictionary.keys).sort({dictionary[$0] > dictionary[$1]}).filter({dictionary[$0] > 0})
|
||||
let sortedValues = Array(dictionary.values).sort({$0 > $1}).filter({$0 > 0})
|
||||
return leaderboardString(sortedKeys, values: sortedValues)
|
||||
}
|
||||
|
||||
private func bottomItems(inout dictionary: [String: Int]) -> String {
|
||||
let sortedKeys = Array(dictionary.keys).sort({dictionary[$0] < dictionary[$1]}).filter({dictionary[$0] < 0})
|
||||
let sortedValues = Array(dictionary.values).sort({$0 < $1}).filter({$0 < 0})
|
||||
return leaderboardString(sortedKeys, values: sortedValues)
|
||||
}
|
||||
|
||||
private func leaderboardString(keys: [String], values: [Int]) -> String {
|
||||
var returnValue = ""
|
||||
for i in 0..<values.count {
|
||||
returnValue += keys[i] + " (" + "\(values[i])" + ")\n"
|
||||
}
|
||||
return returnValue
|
||||
}
|
||||
|
||||
// MARK: - Utilities
|
||||
private func swapIDsForNames(string: String) -> String {
|
||||
var returnString = string
|
||||
for key in client.users.keys {
|
||||
if let name = client.users[key]?.name {
|
||||
returnString = returnString.stringByReplacingOccurrencesOfString(key, withString: "@"+name, options: NSStringCompareOptions.LiteralSearch, range: returnString.startIndex..<returnString.endIndex)
|
||||
}
|
||||
}
|
||||
return returnString
|
||||
}
|
||||
|
||||
private func userID(string: String) -> String {
|
||||
return string.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet)
|
||||
}
|
||||
|
||||
}
|
||||
+13
-26
@@ -1,33 +1,20 @@
|
||||
//
|
||||
// Package.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
// swift-tools-version:4.0
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "SlackKit",
|
||||
targets: [],
|
||||
products: [
|
||||
.library(name: "SlackKit", targets: ["SlackKit"])
|
||||
],
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/pvzig/Starscream.git",
|
||||
majorVersion: 1),
|
||||
.package(url: "https://github.com/SlackKit/SKCore", .upToNextMinor(from: "4.1.0")),
|
||||
.package(url: "https://github.com/SlackKit/SKClient", .upToNextMinor(from: "4.1.0")),
|
||||
.package(url: "https://github.com/SlackKit/SKRTMAPI", .upToNextMinor(from: "4.1.0")),
|
||||
.package(url: "https://github.com/SlackKit/SKServer", .upToNextMinor(from: "4.1.0"))
|
||||
],
|
||||
targets: [
|
||||
.target(name: "SlackKit",
|
||||
dependencies: ["SKCore", "SKClient", "SKRTMAPI", "SKServer"],
|
||||
path: "Sources")
|
||||
]
|
||||
)
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
source 'https://github.com/CocoaPods/Specs.git'
|
||||
|
||||
use_frameworks!
|
||||
|
||||
target 'SlackKit' do
|
||||
pod 'Starscream'
|
||||
target 'SlackKit macOS' do
|
||||
platform :osx, '10.11'
|
||||
pod 'SKCore', '~> 4.1.0'
|
||||
pod 'SKClient', '~> 4.1.0'
|
||||
pod 'SKWebAPI', '~> 4.1.0'
|
||||
pod 'SKRTMAPI', '~> 4.1.0'
|
||||
pod 'SKServer', '~> 4.1.0'
|
||||
end
|
||||
|
||||
target 'SlackKit_iOS' do
|
||||
pod 'Starscream'
|
||||
target 'SlackKit iOS' do
|
||||
platform :ios, '9.0'
|
||||
pod 'SKCore', '~> 4.1.0'
|
||||
pod 'SKClient', '~> 4.1.0'
|
||||
pod 'SKWebAPI', '~> 4.1.0'
|
||||
pod 'SKRTMAPI', '~> 4.1.0'
|
||||
pod 'SKServer', '~> 4.1.0'
|
||||
end
|
||||
|
||||
target 'SlackKit_tvOS' do
|
||||
pod 'Starscream'
|
||||
target 'SlackKit tvOS' do
|
||||
platform :tvos, '9.0'
|
||||
pod 'SKCore', '~> 4.1.0'
|
||||
pod 'SKClient', '~> 4.1.0'
|
||||
pod 'SKWebAPI', '~> 4.1.0'
|
||||
pod 'SKRTMAPI', '~> 4.1.0'
|
||||
pod 'SKServer', '~> 4.1.0'
|
||||
end
|
||||
@@ -1,12 +0,0 @@
|
||||
PODS:
|
||||
- Starscream (1.1.3)
|
||||
|
||||
DEPENDENCIES:
|
||||
- Starscream
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Starscream: d662732354b40dd19ed1ece3e3c44c80b536b83c
|
||||
|
||||
PODFILE CHECKSUM: d22778f772dbbded8b17fbebf5fa1c879d785aee
|
||||
|
||||
COCOAPODS: 1.0.0
|
||||
@@ -1,256 +1,207 @@
|
||||

|
||||
##iOS, OS X, and tvOS Slack Client Library
|
||||
###Description
|
||||
This is a Slack client library for OS X, iOS, and tvOS 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).
|
||||
<p align="center"><img src="https://cloud.githubusercontent.com/assets/8311605/24083714/e921a0d4-0cb2-11e7-8384-d42113ef5056.png" alt="SlackKit" width="500"/></p>
|
||||
|
||||
####Building the SlackKit Framework
|
||||
To build the SlackKit project directly, first build the dependencies using Carthage or CocoaPods. To use the framework in your application, install it in one of the following ways:
|
||||

|
||||

|
||||

|
||||
[](https://github.com/apple/swift-package-manager)
|
||||
[](https://github.com/Carthage/Carthage)
|
||||
[](https://cocoapods.org)
|
||||
|
||||
###Installation
|
||||
####CocoaPods
|
||||
Add the pod to your podfile:
|
||||
```
|
||||
pod 'SlackKit'
|
||||
```
|
||||
and run
|
||||
```
|
||||
pod install
|
||||
```
|
||||
## SlackKit: Slack Apps in Swift
|
||||
### Description
|
||||
|
||||
####Carthage
|
||||
SlackKit makes it easy to build Slack apps in Swift.
|
||||
|
||||
Add SlackKit to your Cartfile:
|
||||
```
|
||||
github “pvzig/SlackKit” ~> 1.0
|
||||
```
|
||||
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"
|
||||
```
|
||||
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 to [bot users](https://api.slack.com/bot-users). SlackKit also supports Slack’s [OAuth 2.0](https://api.slack.com/docs/oauth) flow including the [Add to Slack](https://api.slack.com/docs/slack-button) and [Sign in with Slack](https://api.slack.com/docs/sign-in-with-slack) buttons, [incoming webhooks](https://api.slack.com/incoming-webhooks), [slash commands](https://api.slack.com/slash-commands), and [message buttons](https://api.slack.com/docs/message-buttons).
|
||||
|
||||
Drag the built `SlackKit.framework` into your Xcode project.
|
||||
### Installation
|
||||
|
||||
####Swift Package Manager
|
||||
Add SlackKit to your Package.swift
|
||||
#### Swift Package Manager
|
||||
|
||||
Add `SlackKit` to your `Package.swift`
|
||||
|
||||
```swift
|
||||
import PackageDescription
|
||||
|
||||
|
||||
let package = Package(
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 1)
|
||||
]
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/SlackKit/SlackKit.git", .upToNextMinor(from: "4.1.0"))
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
Run `swift build` on your application’s main directory.
|
||||
#### Carthage
|
||||
|
||||
Add `SlackKit` to your `Cartfile`:
|
||||
|
||||
To use the library in your project import it:
|
||||
```
|
||||
github "SlackKit/SlackKit"
|
||||
```
|
||||
|
||||
#### CocoaPods
|
||||
Add `SlackKit` to your `Podfile`:
|
||||
|
||||
```
|
||||
pod 'SlackKit'
|
||||
```
|
||||
|
||||
### Usage
|
||||
#### The Basics
|
||||
Create a bot user with an API token:
|
||||
|
||||
```swift
|
||||
import SlackKit
|
||||
```
|
||||
|
||||
###Usage
|
||||
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).
|
||||
|
||||
Once you have a token, initialize a client instance using it:
|
||||
```swift
|
||||
let client = Client(apiToken: "YOUR_SLACK_API_TOKEN")
|
||||
```
|
||||
|
||||
If you want to receive messages from the Slack RTM API, connect to it.
|
||||
```swift
|
||||
client.connect()
|
||||
```
|
||||
|
||||
You can also set options for a ping/pong interval, timeout interval, and automatic reconnection:
|
||||
```swift
|
||||
client.connect(pingInterval: 2, timeout: 10, reconnect: false)
|
||||
```
|
||||
|
||||
Once connected, the client will begin to consume any messages sent by the Slack RTM API.
|
||||
|
||||
####Web API Methods
|
||||
SlackKit currently supports the a subset of the Slack Web APIs that are available to bot users:
|
||||
|
||||
- api.test
|
||||
- auth.test
|
||||
- channels.history
|
||||
- channels.info
|
||||
- channels.list
|
||||
- channels.mark
|
||||
- channels.setPurpose
|
||||
- channels.setTopic
|
||||
- chat.delete
|
||||
- chat.postMessage
|
||||
- chat.update
|
||||
- emoji.list
|
||||
- files.comments.add
|
||||
- files.comments.edit
|
||||
- files.comments.delete
|
||||
- files.delete
|
||||
- files.info
|
||||
- files.upload
|
||||
- groups.close
|
||||
- groups.history
|
||||
- groups.info
|
||||
- groups.list
|
||||
- groups.mark
|
||||
- groups.open
|
||||
- groups.setPurpose
|
||||
- groups.setTopic
|
||||
- im.close
|
||||
- im.history
|
||||
- im.list
|
||||
- im.mark
|
||||
- im.open
|
||||
- mpim.close
|
||||
- mpim.history
|
||||
- mpim.list
|
||||
- mpim.mark
|
||||
- mpim.open
|
||||
- pins.add
|
||||
- pins.list
|
||||
- pins.remove
|
||||
- reactions.add
|
||||
- reactions.get
|
||||
- reactions.list
|
||||
- reactions.remove
|
||||
- rtm.start
|
||||
- stars.add
|
||||
- stars.remove
|
||||
- team.info
|
||||
- users.getPresence
|
||||
- users.info
|
||||
- users.list
|
||||
- users.setActive
|
||||
- users.setPresence
|
||||
|
||||
They can be accessed through a Client object’s `webAPI` property:
|
||||
```swift
|
||||
client.webAPI.authenticationTest({
|
||||
(authenticated) -> Void in
|
||||
print(authenticated)
|
||||
}){(error) -> Void in
|
||||
print(error)
|
||||
let bot = SlackKit()
|
||||
bot.addRTMBotWithAPIToken("xoxb-SLACK-BOT-TOKEN")
|
||||
// Register for event notifications
|
||||
bot.notificationForEvent(.message) { (event, _) in
|
||||
// Your bot logic here
|
||||
print(event.message)
|
||||
}
|
||||
```
|
||||
|
||||
####Delegate methods
|
||||
|
||||
To receive delegate callbacks for certain events, register an object as the delegate for those events:
|
||||
```swift
|
||||
client.slackEventsDelegate = self
|
||||
```
|
||||
|
||||
There are a number of delegates that you can set to receive callbacks for certain events.
|
||||
|
||||
#####SlackEventsDelegate
|
||||
```swift
|
||||
func clientConnectionFailed(error: SlackError)
|
||||
func clientConnected()
|
||||
func clientDisconnected()
|
||||
func preferenceChanged(preference: String, value: AnyObject)
|
||||
func userChanged(user: User)
|
||||
func presenceChanged(user: User?, presence: String?)
|
||||
func manualPresenceChanged(user: User?, presence: String?)
|
||||
func botEvent(bot: Bot)
|
||||
```
|
||||
|
||||
#####MessageEventsDelegate
|
||||
```swift
|
||||
func messageSent(message: Message)
|
||||
func messageReceived(message: Message)
|
||||
func messageChanged(message: Message)
|
||||
func messageDeleted(message: Message?)
|
||||
```
|
||||
|
||||
#####ChannelEventsDelegate
|
||||
```swift
|
||||
func userTyping(channel: Channel?, user: User?)
|
||||
func channelMarked(channel: Channel, timestamp: String?)
|
||||
func channelCreated(channel: Channel)
|
||||
func channelDeleted(channel: Channel)
|
||||
func channelRenamed(channel: Channel)
|
||||
func channelArchived(channel: Channel)
|
||||
func channelHistoryChanged(channel: Channel)
|
||||
func channelJoined(channel: Channel)
|
||||
func channelLeft(channel: Channel)
|
||||
```
|
||||
|
||||
#####DoNotDisturbEventsDelegate
|
||||
```swift
|
||||
doNotDisturbUpdated(dndStatus: DoNotDisturbStatus)
|
||||
doNotDisturbUserUpdated(dndStatus: DoNotDisturbStatus, user: User?)
|
||||
```
|
||||
|
||||
#####GroupEventsDelegate
|
||||
```swift
|
||||
func groupOpened(group: Channel)
|
||||
```
|
||||
|
||||
#####FileEventsDelegate
|
||||
```swift
|
||||
func fileProcessed(file: File)
|
||||
func fileMadePrivate(file: File)
|
||||
func fileDeleted(file: File)
|
||||
func fileCommentAdded(file: File, comment: Comment)
|
||||
func fileCommentEdited(file: File, comment: Comment)
|
||||
func fileCommentDeleted(file: File, comment: Comment)
|
||||
```
|
||||
|
||||
#####PinEventsDelegate
|
||||
```swift
|
||||
func itemPinned(item: Item?, channel: Channel?)
|
||||
func itemUnpinned(item: Item?, channel: Channel?)
|
||||
```
|
||||
|
||||
#####StarEventsDelegate
|
||||
```swift
|
||||
func itemStarred(item: Item, star: Bool)
|
||||
```
|
||||
|
||||
#####ReactionEventsDelegate
|
||||
```swift
|
||||
func reactionAdded(reaction: String?, item: Item?, itemUser: String?)
|
||||
func reactionRemoved(reaction: String?, item: Item?, itemUser: String?)
|
||||
```
|
||||
|
||||
#####TeamEventsDelegate
|
||||
```swift
|
||||
func teamJoined(user: User)
|
||||
func teamPlanChanged(plan: String)
|
||||
func teamPreferencesChanged(preference: String, value: AnyObject)
|
||||
func teamNameChanged(name: String)
|
||||
func teamDomainChanged(domain: String)
|
||||
func teamEmailDomainChanged(domain: String)
|
||||
func teamEmojiChanged()
|
||||
```
|
||||
|
||||
#####SubteamEventsDelegate
|
||||
```swift
|
||||
func subteamEvent(userGroup: UserGroup)
|
||||
func subteamSelfAdded(subteamID: String)
|
||||
func subteamSelfRemoved(subteamID: String)
|
||||
```
|
||||
|
||||
###Examples
|
||||
####Leaderboard
|
||||
Included in the OSX-Sample is an example application of a bot you might make using SlackKit. It’s a basic leaderboard scoring bot, in the spirit of [PlusPlus](https://plusplus.chat).
|
||||
|
||||
To configure it, enter your bot’s API token in `AppDelegate.swift` for the Leaderboard bot:
|
||||
or create a ready-to-launch Slack app with your [application’s `Client ID` and `Client Secret`](https://api.slack.com/apps):
|
||||
|
||||
```swift
|
||||
let learderboard = Leaderboard(token: "SLACK_AUTH_TOKEN")
|
||||
import SlackKit
|
||||
|
||||
let bot = SlackKit()
|
||||
let oauthConfig = OAuthConfig(clientID: "CLIENT_ID", clientSecret: "CLIENT_SECRET")
|
||||
bot.addServer(oauth: oauthConfig)
|
||||
```
|
||||
|
||||
It adds a point for every `@thing++`, subtracts a point for every `@thing--`, and shows a leaderboard when asked `@botname leaderboard`.
|
||||
or just make calls to the Slack Web API:
|
||||
|
||||
###Get In Touch
|
||||
[@pvzig](https://twitter.com/pvzig)
|
||||
```swift
|
||||
import SlackKit
|
||||
|
||||
<peter@launchsoft.co>
|
||||
let bot = SlackKit()
|
||||
bot.addWebAPIAccessWithToken("xoxb-SLACK-BOT-TOKEN")
|
||||
bot.webAPI?.authenticationTest(success: { (success) in
|
||||
print(success)
|
||||
}, failure: nil)
|
||||
|
||||
```
|
||||
|
||||
#### Slash Commands
|
||||
After [configuring your slash command in Slack](https://my.slack.com/services/new/slash-commands) (you can also provide slash commands as part of a [Slack App](https://api.slack.com/slack-apps)), create a route, response middleware for that route, and add it to a responder:
|
||||
|
||||
```swift
|
||||
let slackkit = SlackKit()
|
||||
let middleware = ResponseMiddleware(token: "SLASH_COMMAND_TOKEN", response: SKResponse(text: "👋"))
|
||||
let route = RequestRoute(path: "/hello", middleware: middleware)
|
||||
let responder = SlackKitResponder(routes: [route])
|
||||
slackkit.addServer(responder: responder)
|
||||
```
|
||||
When a user enters that slash command, it will hit your configured route and return the response you specified.
|
||||
|
||||
#### Message Buttons
|
||||
Add [message buttons](https://api.slack.com/docs/message-buttons) to your responses for additional interactivity.
|
||||
|
||||
To send messages with actions, add them to an attachment and send them using the Web API:
|
||||
|
||||
```swift
|
||||
let helloAction = Action(name: "hello", text: "🌎")
|
||||
let attachment = Attachment(fallback: "Hello World", title: "Welcome to SlackKit", callbackID: "hello_world", actions: [helloAction])
|
||||
slackkit.webAPI?.sendMessage(channel: "CXXXXXX", text: "", attachments: [attachment], success: nil, failure: nil)
|
||||
```
|
||||
|
||||
To respond to message actions, add a `RequestRoute` with `MessageActionMiddleware` using your app’s verification token to your `SlackKitResponder`:
|
||||
|
||||
```swift
|
||||
let response = ResponseMiddleware(token: "SLACK_APP_VERIFICATION_TOKEN", response: SKResponse(text: "Hello, world!"))
|
||||
let actionRoute = MessageActionRoute(action: helloAction, middleware: response)
|
||||
let actionMiddleware = MessageActionMiddleware(token: "SLACK_APP_VERIFICATION_TOKEN", routes:[actionRoute])
|
||||
let actions = RequestRoute(path: "/actions", middleware: actionMiddleware)
|
||||
let responder = SlackKitResponder(routes: [actions])
|
||||
slackkit.addServer(responder: responder)
|
||||
```
|
||||
|
||||
#### OAuth
|
||||
Slack has [many different oauth scopes](https://api.slack.com/docs/oauth-scopes) that can be combined in different ways. If your application does not request the proper OAuth scopes, your API calls will fail.
|
||||
|
||||
If you authenticate using OAuth and the Add to Slack or Sign in with Slack buttons this is handled for you.
|
||||
|
||||
For local development of things like OAuth, slash commands, and message buttons, you may want to use a tool like [ngrok](https://ngrok.com).
|
||||
|
||||
#### Web API Methods
|
||||
SlackKit currently supports the a subset of the Slack Web APIs that are available to bot users:
|
||||
|
||||
| Web APIs |
|
||||
| ------------- |
|
||||
| `api.test`|
|
||||
| `api.revoke`|
|
||||
| `auth.test`|
|
||||
| `channels.history`|
|
||||
| `channels.info`|
|
||||
| `channels.list`|
|
||||
| `channels.mark`|
|
||||
| `channels.setPurpose`|
|
||||
| `channels.setTopic`|
|
||||
| `chat.delete`|
|
||||
| `chat.meMessage`|
|
||||
| `chat.postMessage`|
|
||||
| `chat.update`|
|
||||
| `emoji.list`|
|
||||
| `files.comments.add`|
|
||||
| `files.comments.edit`|
|
||||
| `files.comments.delete`|
|
||||
| `files.delete`|
|
||||
| `files.info`|
|
||||
| `files.upload`|
|
||||
| `groups.close`|
|
||||
| `groups.history`|
|
||||
| `groups.info`|
|
||||
| `groups.list`|
|
||||
| `groups.mark`|
|
||||
| `groups.open`|
|
||||
| `groups.setPurpose`|
|
||||
| `groups.setTopic`|
|
||||
| `im.close`|
|
||||
| `im.history`|
|
||||
| `im.list`|
|
||||
| `im.mark`|
|
||||
| `im.open`|
|
||||
| `mpim.close`|
|
||||
| `mpim.history`|
|
||||
| `mpim.list`|
|
||||
| `mpim.mark`|
|
||||
| `mpim.open`|
|
||||
| `oauth.access`|
|
||||
| `pins.add`|
|
||||
| `pins.list`|
|
||||
| `pins.remove`|
|
||||
| `reactions.add`|
|
||||
| `reactions.get`|
|
||||
| `reactions.list`|
|
||||
| `reactions.remove`|
|
||||
| `rtm.start`|
|
||||
| `stars.add`|
|
||||
| `stars.remove`|
|
||||
| `team.info`|
|
||||
| `users.getPresence`|
|
||||
| `users.info`|
|
||||
| `users.list`|
|
||||
| `users.setActive`|
|
||||
| `users.setPresence`|
|
||||
|
||||
Don’t need the whole banana? Want more control over the low-level implementation details? Use the extensible modules SlackKit is built on:
|
||||
|
||||
| Module | Slack Service |
|
||||
| ------------- |------------- |
|
||||
| **[SKClient](https://github.com/SlackKit/SKClient)** | Write your own client implementation|
|
||||
| **[SKRTMAPI](https://github.com/SlackKit/SKRTMAPI)** | Connect to the Slack RTM API|
|
||||
| **[SKServer](https://github.com/SlackKit/SKServer)** | Spin up a server|
|
||||
| **[SKWebAPI](https://github.com/SlackKit/SKWebAPI)** | Access the Slack Web API|
|
||||
|
||||
### Examples
|
||||
You can find the source code for several example applications [here](https://github.com/SlackKit/Examples).
|
||||
|
||||
### Tutorials
|
||||
- [Build a Slack Bot and Deploy to Heroku](https://medium.com/@pvzig/building-slack-bots-in-swift-b99e243e444c)
|
||||
|
||||
### Get In Touch
|
||||
Twitter: [@pvzig](https://twitter.com/pvzig)
|
||||
|
||||
Email: <peter@launchsoft.co>
|
||||
|
||||
+19
-17
@@ -1,18 +1,20 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "SlackKit"
|
||||
s.version = "1.1.0"
|
||||
s.summary = "a Slack client library for OS X, iOS, and tvOS written in Swift"
|
||||
s.homepage = "https://github.com/pvzig/SlackKit"
|
||||
s.license = 'MIT'
|
||||
s.author = { "Peter Zignego" => "peter@launchsoft.co" }
|
||||
s.source = { :git => "https://github.com/pvzig/SlackKit.git", :tag => s.version.to_s }
|
||||
s.social_media_url = 'https://twitter.com/pvzig'
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.osx.deployment_target = '10.10'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.requires_arc = true
|
||||
s.source_files = 'SlackKit/Sources/*.swift'
|
||||
s.frameworks = 'Foundation'
|
||||
s.dependency 'Starscream', '~> 1.1.3'
|
||||
end
|
||||
|
||||
s.name = "SlackKit"
|
||||
s.version = "4.1.0"
|
||||
s.summary = "Write Slack apps in Swift"
|
||||
s.homepage = "https://github.com/pvzig/SlackKit"
|
||||
s.license = 'MIT'
|
||||
s.author = { "Peter Zignego" => "peter@launchsoft.co" }
|
||||
s.source = { :git => "https://github.com/SlackKit/SlackKit.git", :tag => s.version.to_s }
|
||||
s.social_media_url = 'https://twitter.com/pvzig'
|
||||
s.ios.deployment_target = '9.0'
|
||||
s.osx.deployment_target = '10.11'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.requires_arc = true
|
||||
s.source_files = 'Sources/*.swift'
|
||||
s.frameworks = 'Foundation'
|
||||
s.dependency 'SKCore'
|
||||
s.dependency 'SKClient'
|
||||
s.dependency 'SKRTMAPI'
|
||||
s.dependency 'SKServer'
|
||||
end
|
||||
+308
-405
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,6 @@
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:SlackRTMKit.xcodeproj">
|
||||
location = "self:SKCore.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0920"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,7 +14,7 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "263993951CE90EE0004A6E93"
|
||||
BlueprintIdentifier = "2684F1C21E95ABD400536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit iOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
@@ -26,6 +26,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
@@ -36,6 +37,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
@@ -45,7 +47,7 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "263993951CE90EE0004A6E93"
|
||||
BlueprintIdentifier = "2684F1C21E95ABD400536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit iOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
@@ -63,7 +65,7 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "263993951CE90EE0004A6E93"
|
||||
BlueprintIdentifier = "2684F1C21E95ABD400536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit iOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
|
||||
+9
-7
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0920"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,9 +14,9 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26072A331BB48B3A00CD650C"
|
||||
BlueprintIdentifier = "2684F17C1E95AA6900536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit OS X"
|
||||
BlueprintName = "SlackKit macOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
@@ -26,6 +26,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
@@ -36,6 +37,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
@@ -45,9 +47,9 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26072A331BB48B3A00CD650C"
|
||||
BlueprintIdentifier = "2684F17C1E95AA6900536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit OS X"
|
||||
BlueprintName = "SlackKit macOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
@@ -63,9 +65,9 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26072A331BB48B3A00CD650C"
|
||||
BlueprintIdentifier = "2684F17C1E95AA6900536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit OS X"
|
||||
BlueprintName = "SlackKit macOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0730"
|
||||
LastUpgradeVersion = "0920"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,7 +14,7 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "263993B41CE90EED004A6E93"
|
||||
BlueprintIdentifier = "2684F1E61E95ABD600536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit tvOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
@@ -26,6 +26,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
@@ -36,6 +37,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
@@ -45,7 +47,7 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "263993B41CE90EED004A6E93"
|
||||
BlueprintIdentifier = "2684F1E61E95ABD600536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit tvOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
@@ -63,7 +65,7 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "263993B41CE90EED004A6E93"
|
||||
BlueprintIdentifier = "2684F1E61E95ABD600536DCC"
|
||||
BuildableName = "SlackKit.framework"
|
||||
BlueprintName = "SlackKit tvOS"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// SlackKit.h
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for SlackKit.
|
||||
FOUNDATION_EXPORT double SlackKitVersionNumber;
|
||||
|
||||
//! Project version string for SlackKit.
|
||||
FOUNDATION_EXPORT const unsigned char SlackKitVersionString[];
|
||||
@@ -1,132 +0,0 @@
|
||||
//
|
||||
// Attachment.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct Attachment {
|
||||
|
||||
public let fallback: String?
|
||||
public let color: String?
|
||||
public let pretext: String?
|
||||
public let authorName: String?
|
||||
public let authorLink: String?
|
||||
public let authorIcon: String?
|
||||
public let title: String?
|
||||
public let titleLink: String?
|
||||
public let text: String?
|
||||
public let fields: [AttachmentField]?
|
||||
public let imageURL: String?
|
||||
public let thumbURL: String?
|
||||
|
||||
internal init(attachment: [String: AnyObject]?) {
|
||||
fallback = attachment?["fallback"] as? String
|
||||
color = attachment?["color"] as? String
|
||||
pretext = attachment?["pretext"] as? String
|
||||
authorName = attachment?["author_name"] as? String
|
||||
authorLink = attachment?["author_link"] as? String
|
||||
authorIcon = attachment?["author_icon"] as? String
|
||||
title = attachment?["title"] as? String
|
||||
titleLink = attachment?["title_link"] as? String
|
||||
text = attachment?["text"] as? String
|
||||
imageURL = attachment?["image_url"] as? String
|
||||
thumbURL = attachment?["thumb_url"] as? String
|
||||
fields = (attachment?["fields"] as? [[String: AnyObject]])?.map { AttachmentField(field: $0) }
|
||||
}
|
||||
|
||||
public init(fallback: String, title:String, colorHex: String? = nil, pretext: String? = nil, authorName: String? = nil, authorLink: String? = nil, authorIcon: String? = nil, titleLink: String? = nil, text: String? = nil, fields: [AttachmentField]? = nil, imageURL: String? = nil, thumbURL: String? = nil) {
|
||||
self.fallback = fallback
|
||||
self.color = colorHex
|
||||
self.pretext = pretext
|
||||
self.authorName = authorName
|
||||
self.authorLink = authorLink
|
||||
self.authorIcon = authorIcon
|
||||
self.title = title
|
||||
self.titleLink = titleLink
|
||||
self.text = text
|
||||
self.fields = fields
|
||||
self.imageURL = imageURL
|
||||
self.thumbURL = thumbURL
|
||||
}
|
||||
|
||||
internal func dictionary() -> [String: AnyObject] {
|
||||
var attachment = [String: AnyObject]()
|
||||
attachment["fallback"] = fallback
|
||||
attachment["color"] = color
|
||||
attachment["pretext"] = pretext
|
||||
attachment["authorName"] = authorName
|
||||
attachment["author_link"] = authorLink
|
||||
attachment["author_icon"] = authorIcon
|
||||
attachment["title"] = title
|
||||
attachment["title_link"] = titleLink
|
||||
attachment["text"] = text
|
||||
attachment["fields"] = fieldJSONArray(fields)
|
||||
attachment["image_url"] = imageURL
|
||||
attachment["thumb_url"] = thumbURL
|
||||
return attachment
|
||||
}
|
||||
|
||||
private func fieldJSONArray(fields: [AttachmentField]?) -> [[String: AnyObject]] {
|
||||
var returnValue = [[String: AnyObject]]()
|
||||
if let f = fields {
|
||||
for field in f {
|
||||
returnValue.append(field.dictionary())
|
||||
}
|
||||
}
|
||||
return returnValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct AttachmentField {
|
||||
|
||||
public let title: String?
|
||||
public let value: String?
|
||||
public let short: Bool?
|
||||
|
||||
internal init(field: [String: AnyObject]?) {
|
||||
title = field?["title"] as? String
|
||||
value = field?["value"] as? String
|
||||
short = field?["short"] as? Bool
|
||||
}
|
||||
|
||||
public init(title:String, value:String, short: Bool? = nil) {
|
||||
self.title = title
|
||||
self.value = value.slackFormatEscaping()
|
||||
self.short = short
|
||||
}
|
||||
|
||||
internal func dictionary() -> [String: AnyObject] {
|
||||
var field = [String: AnyObject]()
|
||||
field["title"] = title
|
||||
field["value"] = value
|
||||
field["short"] = short
|
||||
return field
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum AttachmentColor: String {
|
||||
case Good = "good"
|
||||
case Warning = "warning"
|
||||
case Danger = "danger"
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
//
|
||||
// Bot.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public struct Bot {
|
||||
|
||||
public let id: String?
|
||||
internal(set) public var name: String?
|
||||
internal(set) public var icons: [String: AnyObject]?
|
||||
|
||||
internal init(bot: [String: AnyObject]?) {
|
||||
id = bot?["id"] as? String
|
||||
name = bot?["name"] as? String
|
||||
icons = bot?["icons"] as? [String: AnyObject]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// Channel.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public struct Channel {
|
||||
|
||||
public let id: String?
|
||||
public let created: Int?
|
||||
public let creator: String?
|
||||
internal(set) public var name: String?
|
||||
internal(set) public var isArchived: Bool?
|
||||
internal(set) public var isGeneral: Bool?
|
||||
public let isGroup: Bool?
|
||||
public let isIM: Bool?
|
||||
public let isMPIM: Bool?
|
||||
internal(set) public var user: String?
|
||||
internal(set) public var isUserDeleted: Bool?
|
||||
internal(set) public var isOpen: Bool?
|
||||
internal(set) public var topic: Topic?
|
||||
internal(set) public var purpose: Topic?
|
||||
internal(set) public var isMember: Bool?
|
||||
internal(set) public var lastRead: String?
|
||||
internal(set) public var latest: Message?
|
||||
internal(set) public var unread: Int?
|
||||
internal(set) public var unreadCountDisplay: Int?
|
||||
internal(set) public var hasPins: Bool?
|
||||
internal(set) public var members: [String]?
|
||||
// Client use
|
||||
internal(set) public var pinnedItems = [Item]()
|
||||
internal(set) public var usersTyping = [String]()
|
||||
internal(set) public var messages = [String: Message]()
|
||||
|
||||
internal init(channel: [String: AnyObject]?) {
|
||||
id = channel?["id"] as? String
|
||||
name = channel?["name"] as? String
|
||||
created = channel?["created"] as? Int
|
||||
creator = channel?["creator"] as? String
|
||||
isArchived = channel?["is_archived"] as? Bool
|
||||
isGeneral = channel?["is_general"] as? Bool
|
||||
isGroup = channel?["is_group"] as? Bool
|
||||
isIM = channel?["is_im"] as? Bool
|
||||
isMPIM = channel?["is_mpim"] as? Bool
|
||||
isUserDeleted = channel?["is_user_deleted"] as? Bool
|
||||
user = channel?["user"] as? String
|
||||
isOpen = channel?["is_open"] as? Bool
|
||||
topic = Topic(topic: channel?["topic"] as? [String: AnyObject])
|
||||
purpose = Topic(topic: channel?["purpose"] as? [String: AnyObject])
|
||||
isMember = channel?["is_member"] as? Bool
|
||||
lastRead = channel?["last_read"] as? String
|
||||
unread = channel?["unread_count"] as? Int
|
||||
unreadCountDisplay = channel?["unread_count_display"] as? Int
|
||||
hasPins = channel?["has_pins"] as? Bool
|
||||
members = channel?["members"] as? [String]
|
||||
|
||||
if let latestMsgDictionary = channel?["latest"] as? [String: AnyObject] {
|
||||
latest = Message(message: latestMsgDictionary)
|
||||
} else {
|
||||
latest = Message(ts: channel?["latest"] as? String)
|
||||
}
|
||||
}
|
||||
|
||||
internal init(id:String?) {
|
||||
self.id = id
|
||||
created = nil
|
||||
creator = nil
|
||||
isGroup = false
|
||||
isIM = false
|
||||
isMPIM = false
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
//
|
||||
// Client+EventDispatching.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
internal extension Client {
|
||||
|
||||
func dispatch(event: [String: AnyObject]) {
|
||||
let event = Event(event: event)
|
||||
guard let type = event.type else {
|
||||
return
|
||||
}
|
||||
switch type {
|
||||
case .Hello:
|
||||
connected = true
|
||||
slackEventsDelegate?.clientConnected()
|
||||
case .Ok:
|
||||
messageSent(event)
|
||||
case .Message:
|
||||
if (event.subtype != nil) {
|
||||
messageDispatcher(event)
|
||||
} else {
|
||||
messageReceived(event)
|
||||
}
|
||||
case .UserTyping:
|
||||
userTyping(event)
|
||||
case .ChannelMarked, .IMMarked, .GroupMarked:
|
||||
channelMarked(event)
|
||||
case .ChannelCreated, .IMCreated:
|
||||
channelCreated(event)
|
||||
case .ChannelJoined, .GroupJoined:
|
||||
channelJoined(event)
|
||||
case .ChannelLeft, .GroupLeft:
|
||||
channelLeft(event)
|
||||
case .ChannelDeleted:
|
||||
channelDeleted(event)
|
||||
case .ChannelRenamed, .GroupRename:
|
||||
channelRenamed(event)
|
||||
case .ChannelArchive, .GroupArchive:
|
||||
channelArchived(event, archived: true)
|
||||
case .ChannelUnarchive, .GroupUnarchive:
|
||||
channelArchived(event, archived: false)
|
||||
case .ChannelHistoryChanged, .IMHistoryChanged, .GroupHistoryChanged:
|
||||
channelHistoryChanged(event)
|
||||
case .DNDUpdated:
|
||||
doNotDisturbUpdated(event)
|
||||
case .DNDUpatedUser:
|
||||
doNotDisturbUserUpdated(event)
|
||||
case .IMOpen, .GroupOpen:
|
||||
open(event, open: true)
|
||||
case .IMClose, .GroupClose:
|
||||
open(event, open: false)
|
||||
case .FileCreated:
|
||||
processFile(event)
|
||||
case .FileShared:
|
||||
processFile(event)
|
||||
case .FileUnshared:
|
||||
processFile(event)
|
||||
case .FilePublic:
|
||||
processFile(event)
|
||||
case .FilePrivate:
|
||||
filePrivate(event)
|
||||
case .FileChanged:
|
||||
processFile(event)
|
||||
case .FileDeleted:
|
||||
deleteFile(event)
|
||||
case .FileCommentAdded:
|
||||
fileCommentAdded(event)
|
||||
case .FileCommentEdited:
|
||||
fileCommentEdited(event)
|
||||
case .FileCommentDeleted:
|
||||
fileCommentDeleted(event)
|
||||
case .PinAdded:
|
||||
pinAdded(event)
|
||||
case .PinRemoved:
|
||||
pinRemoved(event)
|
||||
case .Pong:
|
||||
pong(event)
|
||||
case .PresenceChange:
|
||||
presenceChange(event)
|
||||
case .ManualPresenceChange:
|
||||
manualPresenceChange(event)
|
||||
case .PrefChange:
|
||||
changePreference(event)
|
||||
case .UserChange:
|
||||
userChange(event)
|
||||
case .TeamJoin:
|
||||
teamJoin(event)
|
||||
case .StarAdded:
|
||||
itemStarred(event, star: true)
|
||||
case .StarRemoved:
|
||||
itemStarred(event, star: false)
|
||||
case .ReactionAdded:
|
||||
addedReaction(event)
|
||||
case .ReactionRemoved:
|
||||
removedReaction(event)
|
||||
case .EmojiChanged:
|
||||
emojiChanged(event)
|
||||
case .CommandsChanged:
|
||||
// This functionality is only used by our web client.
|
||||
// The other APIs required to support slash command metadata are currently unstable.
|
||||
// Until they are released other clients should ignore this event.
|
||||
break
|
||||
case .TeamPlanChange:
|
||||
teamPlanChange(event)
|
||||
case .TeamPrefChange:
|
||||
teamPreferenceChange(event)
|
||||
case .TeamRename:
|
||||
teamNameChange(event)
|
||||
case .TeamDomainChange:
|
||||
teamDomainChange(event)
|
||||
case .EmailDomainChange:
|
||||
emailDomainChange(event)
|
||||
case .TeamProfileChange:
|
||||
teamProfileChange(event)
|
||||
case .TeamProfileDelete:
|
||||
teamProfileDeleted(event)
|
||||
case .TeamProfileReorder:
|
||||
teamProfileReordered(event)
|
||||
case .BotAdded:
|
||||
bot(event)
|
||||
case .BotChanged:
|
||||
bot(event)
|
||||
case .AccountsChanged:
|
||||
// The accounts_changed event is used by our web client to maintain a list of logged-in accounts.
|
||||
// Other clients should ignore this event.
|
||||
break
|
||||
case .TeamMigrationStarted:
|
||||
connect(pingInterval: pingInterval, timeout: timeout, reconnect: reconnect)
|
||||
case .ReconnectURL:
|
||||
// The reconnect_url event is currently unsupported and experimental.
|
||||
break
|
||||
case .SubteamCreated, .SubteamUpdated:
|
||||
subteam(event)
|
||||
case .SubteamSelfAdded:
|
||||
subteamAddedSelf(event)
|
||||
case.SubteamSelfRemoved:
|
||||
subteamRemovedSelf(event)
|
||||
case .Error:
|
||||
print("Error: \(event)")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func messageDispatcher(event:Event) {
|
||||
guard let value = event.subtype, subtype = MessageSubtype(rawValue:value) else {
|
||||
return
|
||||
}
|
||||
switch subtype {
|
||||
case .MessageChanged:
|
||||
messageChanged(event)
|
||||
case .MessageDeleted:
|
||||
messageDeleted(event)
|
||||
default:
|
||||
messageReceived(event)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,563 +0,0 @@
|
||||
//
|
||||
// Client+EventHandling.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
internal extension Client {
|
||||
|
||||
//MARK: - Pong
|
||||
func pong(event: Event) {
|
||||
pong = event.replyTo
|
||||
}
|
||||
|
||||
//MARK: - Messages
|
||||
func messageSent(event: Event) {
|
||||
guard let reply = event.replyTo, message = sentMessages[NSNumber(double: reply).stringValue], channel = message.channel, ts = message.ts else {
|
||||
return
|
||||
}
|
||||
|
||||
message.ts = event.ts
|
||||
message.text = event.text
|
||||
channels[channel]?.messages[ts] = message
|
||||
messageEventsDelegate?.messageSent(message)
|
||||
}
|
||||
|
||||
func messageReceived(event: Event) {
|
||||
guard let channel = event.channel, message = event.message, id = channel.id, ts = message.ts else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.messages[ts] = message
|
||||
messageEventsDelegate?.messageReceived(message)
|
||||
}
|
||||
|
||||
func messageChanged(event: Event) {
|
||||
guard let id = event.channel?.id, nested = event.nestedMessage, ts = nested.ts else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.messages[ts] = nested
|
||||
messageEventsDelegate?.messageChanged(nested)
|
||||
}
|
||||
|
||||
func messageDeleted(event: Event) {
|
||||
guard let id = event.channel?.id, key = event.message?.deletedTs, message = channels[id]?.messages[key] else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.messages.removeValueForKey(key)
|
||||
messageEventsDelegate?.messageDeleted(message)
|
||||
}
|
||||
|
||||
//MARK: - Channels
|
||||
func userTyping(event: Event) {
|
||||
guard let channel = event.channel, channelID = channel.id, user = event.user, userID = user.id where
|
||||
channels.indexForKey(channelID) != nil && !channels[channelID]!.usersTyping.contains(userID) else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[channelID]?.usersTyping.append(userID)
|
||||
channelEventsDelegate?.userTyping(channel, user: user)
|
||||
|
||||
let timeout = dispatch_time(DISPATCH_TIME_NOW, Int64(5.0 * Double(NSEC_PER_SEC)))
|
||||
dispatch_after(timeout, dispatch_get_main_queue()) {
|
||||
if let index = self.channels[channelID]?.usersTyping.indexOf(userID) {
|
||||
self.channels[channelID]?.usersTyping.removeAtIndex(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelMarked(event: Event) {
|
||||
guard let channel = event.channel, id = channel.id, timestamp = event.ts else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.lastRead = event.ts
|
||||
channelEventsDelegate?.channelMarked(channel, timestamp: timestamp)
|
||||
}
|
||||
|
||||
func channelCreated(event: Event) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id] = channel
|
||||
channelEventsDelegate?.channelCreated(channel)
|
||||
}
|
||||
|
||||
func channelDeleted(event: Event) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
channels.removeValueForKey(id)
|
||||
channelEventsDelegate?.channelDeleted(channel)
|
||||
}
|
||||
|
||||
func channelJoined(event: Event) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id] = event.channel
|
||||
channelEventsDelegate?.channelJoined(channel)
|
||||
}
|
||||
|
||||
func channelLeft(event: Event) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
if let userID = authenticatedUser?.id, index = channels[id]?.members?.indexOf(userID) {
|
||||
channels[id]?.members?.removeAtIndex(index)
|
||||
}
|
||||
channelEventsDelegate?.channelLeft(channel)
|
||||
}
|
||||
|
||||
func channelRenamed(event: Event) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.name = channel.name
|
||||
channelEventsDelegate?.channelRenamed(channel)
|
||||
}
|
||||
|
||||
func channelArchived(event: Event, archived: Bool) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.isArchived = archived
|
||||
channelEventsDelegate?.channelArchived(channel)
|
||||
}
|
||||
|
||||
func channelHistoryChanged(event: Event) {
|
||||
guard let channel = event.channel else {
|
||||
return
|
||||
}
|
||||
channelEventsDelegate?.channelHistoryChanged(channel)
|
||||
}
|
||||
|
||||
//MARK: - Do Not Disturb
|
||||
func doNotDisturbUpdated(event: Event) {
|
||||
guard let dndStatus = event.dndStatus else {
|
||||
return
|
||||
}
|
||||
|
||||
authenticatedUser?.doNotDisturbStatus = dndStatus
|
||||
doNotDisturbEventsDelegate?.doNotDisturbUpdated(dndStatus)
|
||||
}
|
||||
|
||||
func doNotDisturbUserUpdated(event: Event) {
|
||||
guard let dndStatus = event.dndStatus, user = event.user, id = user.id else {
|
||||
return
|
||||
}
|
||||
|
||||
users[id]?.doNotDisturbStatus = dndStatus
|
||||
doNotDisturbEventsDelegate?.doNotDisturbUserUpdated(dndStatus, user: user)
|
||||
}
|
||||
|
||||
//MARK: - IM & Group Open/Close
|
||||
func open(event: Event, open: Bool) {
|
||||
guard let channel = event.channel, id = channel.id else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.isOpen = open
|
||||
groupEventsDelegate?.groupOpened(channel)
|
||||
}
|
||||
|
||||
//MARK: - Files
|
||||
func processFile(event: Event) {
|
||||
guard let file = event.file, id = file.id else {
|
||||
return
|
||||
}
|
||||
if let comment = file.initialComment, commentID = comment.id {
|
||||
if files[id]?.comments[commentID] == nil {
|
||||
files[id]?.comments[commentID] = comment
|
||||
}
|
||||
}
|
||||
|
||||
files[id] = file
|
||||
fileEventsDelegate?.fileProcessed(file)
|
||||
}
|
||||
|
||||
func filePrivate(event: Event) {
|
||||
guard let file = event.file, id = file.id else {
|
||||
return
|
||||
}
|
||||
|
||||
files[id]?.isPublic = false
|
||||
fileEventsDelegate?.fileMadePrivate(file)
|
||||
}
|
||||
|
||||
func deleteFile(event: Event) {
|
||||
guard let file = event.file, id = file.id else {
|
||||
return
|
||||
}
|
||||
|
||||
if files[id] != nil {
|
||||
files.removeValueForKey(id)
|
||||
}
|
||||
fileEventsDelegate?.fileDeleted(file)
|
||||
}
|
||||
|
||||
func fileCommentAdded(event: Event) {
|
||||
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
|
||||
return
|
||||
}
|
||||
|
||||
files[id]?.comments[commentID] = comment
|
||||
fileEventsDelegate?.fileCommentAdded(file, comment: comment)
|
||||
}
|
||||
|
||||
func fileCommentEdited(event: Event) {
|
||||
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
|
||||
return
|
||||
}
|
||||
|
||||
files[id]?.comments[commentID]?.comment = comment.comment
|
||||
fileEventsDelegate?.fileCommentEdited(file, comment: comment)
|
||||
}
|
||||
|
||||
func fileCommentDeleted(event: Event) {
|
||||
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
|
||||
return
|
||||
}
|
||||
|
||||
files[id]?.comments.removeValueForKey(commentID)
|
||||
fileEventsDelegate?.fileCommentDeleted(file, comment: comment)
|
||||
}
|
||||
|
||||
//MARK: - Pins
|
||||
func pinAdded(event: Event) {
|
||||
guard let id = event.channelID, item = event.item else {
|
||||
return
|
||||
}
|
||||
|
||||
channels[id]?.pinnedItems.append(item)
|
||||
pinEventsDelegate?.itemPinned(item, channel: channels[id])
|
||||
}
|
||||
|
||||
func pinRemoved(event: Event) {
|
||||
guard let id = event.channelID, item = event.item else {
|
||||
return
|
||||
}
|
||||
|
||||
if let pins = channels[id]?.pinnedItems.filter({$0 != item}) {
|
||||
channels[id]?.pinnedItems = pins
|
||||
}
|
||||
pinEventsDelegate?.itemUnpinned(item, channel: channels[id])
|
||||
}
|
||||
|
||||
//MARK: - Stars
|
||||
func itemStarred(event: Event, star: Bool) {
|
||||
guard let item = event.item, type = item.type else {
|
||||
return
|
||||
}
|
||||
switch type {
|
||||
case "message":
|
||||
starMessage(item, star: star)
|
||||
case "file":
|
||||
starFile(item, star: star)
|
||||
case "file_comment":
|
||||
starComment(item)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
starEventsDelegate?.itemStarred(item, star: star)
|
||||
}
|
||||
|
||||
func starMessage(item: Item, star: Bool) {
|
||||
guard let message = item.message, ts = message.ts, channel = item.channel where channels[channel]?.messages[ts] != nil else {
|
||||
return
|
||||
}
|
||||
channels[channel]?.messages[ts]?.isStarred = star
|
||||
}
|
||||
|
||||
func starFile(item: Item, star: Bool) {
|
||||
guard let file = item.file, id = file.id else {
|
||||
return
|
||||
}
|
||||
|
||||
files[id]?.isStarred = star
|
||||
if let stars = files[id]?.stars {
|
||||
if star == true {
|
||||
files[id]?.stars = stars + 1
|
||||
} else {
|
||||
if stars > 0 {
|
||||
files[id]?.stars = stars - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func starComment(item: Item) {
|
||||
guard let file = item.file, id = file.id, comment = item.comment, commentID = comment.id else {
|
||||
return
|
||||
}
|
||||
files[id]?.comments[commentID] = comment
|
||||
}
|
||||
|
||||
//MARK: - Reactions
|
||||
func addedReaction(event: Event) {
|
||||
guard let item = event.item, type = item.type, reaction = event.reaction, userID = event.user?.id, itemUser = event.itemUser else {
|
||||
return
|
||||
}
|
||||
|
||||
switch type {
|
||||
case "message":
|
||||
guard let channel = item.channel, ts = item.ts, message = channels[channel]?.messages[ts] else {
|
||||
return
|
||||
}
|
||||
message.reactions.append(Reaction(name: reaction, user: userID))
|
||||
case "file":
|
||||
guard let id = item.file?.id else {
|
||||
return
|
||||
}
|
||||
files[id]?.reactions.append(Reaction(name: reaction, user: userID))
|
||||
case "file_comment":
|
||||
guard let id = item.file?.id, commentID = item.fileCommentID else {
|
||||
return
|
||||
}
|
||||
files[id]?.comments[commentID]?.reactions.append(Reaction(name: reaction, user: userID))
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
reactionEventsDelegate?.reactionAdded(reaction, item: item, itemUser: itemUser)
|
||||
}
|
||||
|
||||
func removedReaction(event: Event) {
|
||||
guard let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id, itemUser = event.itemUser else {
|
||||
return
|
||||
}
|
||||
|
||||
switch type {
|
||||
case "message":
|
||||
guard let channel = item.channel, ts = item.ts, message = channels[channel]?.messages[ts] else {
|
||||
return
|
||||
}
|
||||
message.reactions = message.reactions.filter({$0.name != key && $0.user != userID})
|
||||
case "file":
|
||||
guard let itemFile = item.file, id = itemFile.id else {
|
||||
return
|
||||
}
|
||||
files[id]?.reactions = files[id]!.reactions.filter({$0.name != key && $0.user != userID})
|
||||
case "file_comment":
|
||||
guard let id = item.file?.id, commentID = item.fileCommentID else {
|
||||
return
|
||||
}
|
||||
files[id]?.comments[commentID]?.reactions = files[id]!.comments[commentID]!.reactions.filter({$0.name != key && $0.user != userID})
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
reactionEventsDelegate?.reactionRemoved(key, item: item, itemUser: itemUser)
|
||||
}
|
||||
|
||||
//MARK: - Preferences
|
||||
func changePreference(event: Event) {
|
||||
guard let name = event.name else {
|
||||
return
|
||||
}
|
||||
|
||||
authenticatedUser?.preferences?[name] = event.value
|
||||
slackEventsDelegate?.preferenceChanged(name, value: event.value)
|
||||
}
|
||||
|
||||
//Mark: - User Change
|
||||
func userChange(event: Event) {
|
||||
guard let user = event.user, id = user.id else {
|
||||
return
|
||||
}
|
||||
|
||||
let preferences = users[id]?.preferences
|
||||
users[id] = user
|
||||
users[id]?.preferences = preferences
|
||||
slackEventsDelegate?.userChanged(user)
|
||||
}
|
||||
|
||||
//MARK: - User Presence
|
||||
func presenceChange(event: Event) {
|
||||
guard let user = event.user, id = user.id, presence = event.presence else {
|
||||
return
|
||||
}
|
||||
|
||||
users[id]?.presence = event.presence
|
||||
slackEventsDelegate?.presenceChanged(user, presence: presence)
|
||||
}
|
||||
|
||||
//MARK: - Team
|
||||
func teamJoin(event: Event) {
|
||||
guard let user = event.user, id = user.id else {
|
||||
return
|
||||
}
|
||||
|
||||
users[id] = user
|
||||
teamEventsDelegate?.teamJoined(user)
|
||||
}
|
||||
|
||||
func teamPlanChange(event: Event) {
|
||||
guard let plan = event.plan else {
|
||||
return
|
||||
}
|
||||
|
||||
team?.plan = plan
|
||||
teamEventsDelegate?.teamPlanChanged(plan)
|
||||
}
|
||||
|
||||
func teamPreferenceChange(event: Event) {
|
||||
guard let name = event.name else {
|
||||
return
|
||||
}
|
||||
|
||||
team?.prefs?[name] = event.value
|
||||
teamEventsDelegate?.teamPreferencesChanged(name, value: event.value)
|
||||
}
|
||||
|
||||
func teamNameChange(event: Event) {
|
||||
guard let name = event.name else {
|
||||
return
|
||||
}
|
||||
|
||||
team?.name = name
|
||||
teamEventsDelegate?.teamNameChanged(name)
|
||||
}
|
||||
|
||||
func teamDomainChange(event: Event) {
|
||||
guard let domain = event.domain else {
|
||||
return
|
||||
}
|
||||
|
||||
team?.domain = domain
|
||||
teamEventsDelegate?.teamDomainChanged(domain)
|
||||
}
|
||||
|
||||
func emailDomainChange(event: Event) {
|
||||
guard let domain = event.emailDomain else {
|
||||
return
|
||||
}
|
||||
|
||||
team?.emailDomain = domain
|
||||
teamEventsDelegate?.teamEmailDomainChanged(domain)
|
||||
}
|
||||
|
||||
func emojiChanged(event: Event) {
|
||||
teamEventsDelegate?.teamEmojiChanged()
|
||||
}
|
||||
|
||||
//MARK: - Bots
|
||||
func bot(event: Event) {
|
||||
guard let bot = event.bot, id = bot.id else {
|
||||
return
|
||||
}
|
||||
|
||||
bots[id] = bot
|
||||
slackEventsDelegate?.botEvent(bot)
|
||||
}
|
||||
|
||||
//MARK: - Subteams
|
||||
func subteam(event: Event) {
|
||||
guard let subteam = event.subteam, id = subteam.id else {
|
||||
return
|
||||
}
|
||||
|
||||
userGroups[id] = subteam
|
||||
subteamEventsDelegate?.subteamEvent(subteam)
|
||||
}
|
||||
|
||||
func subteamAddedSelf(event: Event) {
|
||||
guard let subteamID = event.subteamID, _ = authenticatedUser?.userGroups else {
|
||||
return
|
||||
}
|
||||
|
||||
authenticatedUser?.userGroups![subteamID] = subteamID
|
||||
subteamEventsDelegate?.subteamSelfAdded(subteamID)
|
||||
}
|
||||
|
||||
func subteamRemovedSelf(event: Event) {
|
||||
guard let subteamID = event.subteamID else {
|
||||
return
|
||||
}
|
||||
|
||||
authenticatedUser?.userGroups?.removeValueForKey(subteamID)
|
||||
subteamEventsDelegate?.subteamSelfRemoved(subteamID)
|
||||
}
|
||||
|
||||
//MARK: - Team Profiles
|
||||
func teamProfileChange(event: Event) {
|
||||
guard let profile = event.profile else {
|
||||
return
|
||||
}
|
||||
|
||||
for user in users {
|
||||
for key in profile.fields.keys {
|
||||
users[user.0]?.profile?.customProfile?.fields[key]?.updateProfileField(profile.fields[key])
|
||||
}
|
||||
}
|
||||
|
||||
teamProfileEventsDelegate?.teamProfileChanged(profile)
|
||||
}
|
||||
|
||||
func teamProfileDeleted(event: Event) {
|
||||
guard let profile = event.profile else {
|
||||
return
|
||||
}
|
||||
|
||||
for user in users {
|
||||
if let id = profile.fields.first?.0 {
|
||||
users[user.0]?.profile?.customProfile?.fields[id] = nil
|
||||
}
|
||||
}
|
||||
|
||||
teamProfileEventsDelegate?.teamProfileDeleted(profile)
|
||||
}
|
||||
|
||||
func teamProfileReordered(event: Event) {
|
||||
guard let profile = event.profile else {
|
||||
return
|
||||
}
|
||||
|
||||
for user in users {
|
||||
for key in profile.fields.keys {
|
||||
users[user.0]?.profile?.customProfile?.fields[key]?.ordering = profile.fields[key]?.ordering
|
||||
}
|
||||
}
|
||||
|
||||
teamProfileEventsDelegate?.teamProfileReordered(profile)
|
||||
}
|
||||
|
||||
//MARK: - Authenticated User
|
||||
func manualPresenceChange(event: Event) {
|
||||
guard let presence = event.presence, user = authenticatedUser else {
|
||||
return
|
||||
}
|
||||
|
||||
authenticatedUser?.presence = presence
|
||||
slackEventsDelegate?.manualPresenceChanged(user, presence: presence)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// Client+Utilities.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum ClientError: ErrorType {
|
||||
case ChannelDoesNotExist
|
||||
case UserDoesNotExist
|
||||
}
|
||||
|
||||
public extension Client {
|
||||
|
||||
//MARK: - User & Channel
|
||||
public func getChannelIDByName(name: String) throws -> String {
|
||||
guard let id = channels.filter({$0.1.name == stripString(name)}).first?.0 else {
|
||||
throw ClientError.ChannelDoesNotExist
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
public func getUserIDByName(name: String) throws -> String {
|
||||
guard let id = users.filter({$0.1.name == stripString(name)}).first?.0 else {
|
||||
throw ClientError.UserDoesNotExist
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
public func getImIDForUserWithID(id: String, success: (imID: String?)->Void, failure: (error: SlackError)->Void) {
|
||||
let ims = channels.filter{$0.1.isIM == true}
|
||||
let channel = ims.filter{$0.1.user == id}.first
|
||||
if let channel = channel {
|
||||
success(imID: channel.0)
|
||||
} else {
|
||||
webAPI.openIM(id, success: success, failure: failure)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Utilities
|
||||
internal func stripString(string: String) -> String {
|
||||
var strippedString = string
|
||||
if string[string.startIndex] == "@" || string[string.startIndex] == "#" {
|
||||
strippedString = string.substringFromIndex(string.startIndex.advancedBy(1))
|
||||
}
|
||||
return strippedString
|
||||
}
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
//
|
||||
// Client.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
import Starscream
|
||||
|
||||
public class Client: WebSocketDelegate {
|
||||
|
||||
internal(set) public var connected = false
|
||||
internal(set) public var authenticatedUser: User?
|
||||
internal(set) public var team: Team?
|
||||
|
||||
internal(set) public var channels = [String: Channel]()
|
||||
internal(set) public var users = [String: User]()
|
||||
internal(set) public var userGroups = [String: UserGroup]()
|
||||
internal(set) public var bots = [String: Bot]()
|
||||
internal(set) public var files = [String: File]()
|
||||
internal(set) public var sentMessages = [String: Message]()
|
||||
|
||||
//MARK: - Delegates
|
||||
public weak var slackEventsDelegate: SlackEventsDelegate?
|
||||
public weak var messageEventsDelegate: MessageEventsDelegate?
|
||||
public weak var doNotDisturbEventsDelegate: DoNotDisturbEventsDelegate?
|
||||
public weak var channelEventsDelegate: ChannelEventsDelegate?
|
||||
public weak var groupEventsDelegate: GroupEventsDelegate?
|
||||
public weak var fileEventsDelegate: FileEventsDelegate?
|
||||
public weak var pinEventsDelegate: PinEventsDelegate?
|
||||
public weak var starEventsDelegate: StarEventsDelegate?
|
||||
public weak var reactionEventsDelegate: ReactionEventsDelegate?
|
||||
public weak var teamEventsDelegate: TeamEventsDelegate?
|
||||
public weak var subteamEventsDelegate: SubteamEventsDelegate?
|
||||
public weak var teamProfileEventsDelegate: TeamProfileEventsDelegate?
|
||||
|
||||
public var token = "SLACK_AUTH_TOKEN"
|
||||
|
||||
public func setAuthToken(token: String) {
|
||||
self.token = token
|
||||
}
|
||||
|
||||
public var webAPI: SlackWebAPI {
|
||||
return SlackWebAPI(client: self)
|
||||
}
|
||||
|
||||
internal var webSocket: WebSocket?
|
||||
internal let api = NetworkInterface()
|
||||
|
||||
private let pingPongQueue = dispatch_queue_create("com.launchsoft.SlackKit", DISPATCH_QUEUE_SERIAL)
|
||||
internal var ping: Double?
|
||||
internal var pong: Double?
|
||||
|
||||
internal var pingInterval: NSTimeInterval?
|
||||
internal var timeout: NSTimeInterval?
|
||||
internal var reconnect: Bool?
|
||||
|
||||
required public init(apiToken: String) {
|
||||
self.token = apiToken
|
||||
}
|
||||
|
||||
public func connect(simpleLatest simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, pingInterval: NSTimeInterval? = nil, timeout: NSTimeInterval? = nil, reconnect: Bool? = nil) {
|
||||
self.pingInterval = pingInterval
|
||||
self.timeout = timeout
|
||||
self.reconnect = reconnect
|
||||
webAPI.rtmStart(simpleLatest, noUnreads: noUnreads, mpimAware: mpimAware, success: {
|
||||
(response) -> Void in
|
||||
self.initialSetup(response)
|
||||
if let socketURL = response["url"] as? String {
|
||||
let url = NSURL(string: socketURL)
|
||||
self.webSocket = WebSocket(url: url!)
|
||||
self.webSocket?.delegate = self
|
||||
self.webSocket?.connect()
|
||||
}
|
||||
}, failure: {(error) -> Void in
|
||||
self.slackEventsDelegate?.clientConnectionFailed(error)
|
||||
})
|
||||
}
|
||||
|
||||
public func disconnect() {
|
||||
webSocket?.disconnect()
|
||||
}
|
||||
|
||||
//MARK: - RTM Message send
|
||||
public func sendMessage(message: String, channelID: String) {
|
||||
guard connected else { return }
|
||||
|
||||
if let data = try? formatMessageToSlackJsonString(msg: message, channel: channelID),
|
||||
string = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
|
||||
webSocket?.writeString(string)
|
||||
}
|
||||
}
|
||||
|
||||
private func formatMessageToSlackJsonString(message: (msg: String, channel: String)) throws -> NSData {
|
||||
let json: [String: AnyObject] = [
|
||||
"id": NSDate().slackTimestamp(),
|
||||
"type": "message",
|
||||
"channel": message.channel,
|
||||
"text": message.msg.slackFormatEscaping()
|
||||
]
|
||||
addSentMessage(json)
|
||||
return try NSJSONSerialization.dataWithJSONObject(json, options: [])
|
||||
}
|
||||
|
||||
private func addSentMessage(dictionary: [String: AnyObject]) {
|
||||
var message = dictionary
|
||||
guard let id = message["id"] as? NSNumber else {
|
||||
return
|
||||
}
|
||||
let ts = String(id)
|
||||
message.removeValueForKey("id")
|
||||
message["ts"] = ts
|
||||
message["user"] = self.authenticatedUser?.id
|
||||
sentMessages[ts] = Message(message: message)
|
||||
}
|
||||
|
||||
//MARK: - RTM Ping
|
||||
private func pingRTMServerAtInterval(interval: NSTimeInterval) {
|
||||
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(interval * Double(NSEC_PER_SEC)))
|
||||
dispatch_after(delay, pingPongQueue, {
|
||||
guard self.connected && self.timeoutCheck() else {
|
||||
self.disconnect()
|
||||
return
|
||||
}
|
||||
self.sendRTMPing()
|
||||
self.pingRTMServerAtInterval(interval)
|
||||
})
|
||||
}
|
||||
|
||||
private func sendRTMPing() {
|
||||
guard connected else {
|
||||
return
|
||||
}
|
||||
let json: [String: AnyObject] = [
|
||||
"id": NSDate().slackTimestamp(),
|
||||
"type": "ping",
|
||||
]
|
||||
guard let data = try? NSJSONSerialization.dataWithJSONObject(json, options: []) else {
|
||||
return
|
||||
}
|
||||
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||
if let writePing = string as? String {
|
||||
ping = json["id"] as? Double
|
||||
webSocket?.writeString(writePing)
|
||||
}
|
||||
}
|
||||
|
||||
private func timeoutCheck() -> Bool {
|
||||
if let pong = pong, ping = ping, timeout = timeout {
|
||||
if pong - ping < timeout {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
// Ping-pong or timeout not configured
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Client setup
|
||||
private func initialSetup(json: [String: AnyObject]) {
|
||||
team = Team(team: json["team"] as? [String: AnyObject])
|
||||
authenticatedUser = User(user: json["self"] as? [String: AnyObject])
|
||||
authenticatedUser?.doNotDisturbStatus = DoNotDisturbStatus(status: json["dnd"] as? [String: AnyObject])
|
||||
enumerateObjects(json["users"] as? Array) { (user) in self.addUser(user) }
|
||||
enumerateObjects(json["channels"] as? Array) { (channel) in self.addChannel(channel) }
|
||||
enumerateObjects(json["groups"] as? Array) { (group) in self.addChannel(group) }
|
||||
enumerateObjects(json["mpims"] as? Array) { (mpim) in self.addChannel(mpim) }
|
||||
enumerateObjects(json["ims"] as? Array) { (ims) in self.addChannel(ims) }
|
||||
enumerateObjects(json["bots"] as? Array) { (bots) in self.addBot(bots) }
|
||||
enumerateSubteams(json["subteams"] as? [String: AnyObject])
|
||||
}
|
||||
|
||||
private func addUser(aUser: [String: AnyObject]) {
|
||||
let user = User(user: aUser)
|
||||
if let id = user.id {
|
||||
users[id] = user
|
||||
}
|
||||
}
|
||||
|
||||
private func addChannel(aChannel: [String: AnyObject]) {
|
||||
let channel = Channel(channel: aChannel)
|
||||
if let id = channel.id {
|
||||
channels[id] = channel
|
||||
}
|
||||
}
|
||||
|
||||
private func addBot(aBot: [String: AnyObject]) {
|
||||
let bot = Bot(bot: aBot)
|
||||
if let id = bot.id {
|
||||
bots[id] = bot
|
||||
}
|
||||
}
|
||||
|
||||
private func enumerateSubteams(subteams: [String: AnyObject]?) {
|
||||
if let subteams = subteams {
|
||||
if let all = subteams["all"] as? [[String: AnyObject]] {
|
||||
for item in all {
|
||||
let u = UserGroup(userGroup: item)
|
||||
self.userGroups[u.id!] = u
|
||||
}
|
||||
}
|
||||
if let auth = subteams["self"] as? [String] {
|
||||
for item in auth {
|
||||
authenticatedUser?.userGroups = [String: String]()
|
||||
authenticatedUser?.userGroups![item] = item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Utilities
|
||||
private func enumerateObjects(array: [AnyObject]?, initalizer: ([String: AnyObject])-> Void) {
|
||||
if let array = array {
|
||||
for object in array {
|
||||
if let dictionary = object as? [String: AnyObject] {
|
||||
initalizer(dictionary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - WebSocketDelegate
|
||||
public func websocketDidConnect(socket: WebSocket) {
|
||||
if let pingInterval = pingInterval {
|
||||
pingRTMServerAtInterval(pingInterval)
|
||||
}
|
||||
}
|
||||
|
||||
public func websocketDidDisconnect(socket: WebSocket, error: NSError?) {
|
||||
connected = false
|
||||
webSocket = nil
|
||||
authenticatedUser = nil
|
||||
slackEventsDelegate?.clientDisconnected()
|
||||
if reconnect == true {
|
||||
connect(pingInterval: pingInterval, timeout: timeout, reconnect: reconnect)
|
||||
}
|
||||
}
|
||||
|
||||
public func websocketDidReceiveMessage(socket: WebSocket, text: String) {
|
||||
guard let data = text.dataUsingEncoding(NSUTF8StringEncoding) else {
|
||||
return
|
||||
}
|
||||
|
||||
if let json = (try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)) as? [String: AnyObject] {
|
||||
dispatch(json)
|
||||
}
|
||||
}
|
||||
|
||||
public func websocketDidReceiveData(socket: WebSocket, data: NSData) {}
|
||||
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
//
|
||||
// Event.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
internal enum EventType: String {
|
||||
case Hello = "hello"
|
||||
case Message = "message"
|
||||
case UserTyping = "user_typing"
|
||||
case ChannelMarked = "channel_marked"
|
||||
case ChannelCreated = "channel_created"
|
||||
case ChannelJoined = "channel_joined"
|
||||
case ChannelLeft = "channel_left"
|
||||
case ChannelDeleted = "channel_deleted"
|
||||
case ChannelRenamed = "channel_rename"
|
||||
case ChannelArchive = "channel_archive"
|
||||
case ChannelUnarchive = "channel_unarchive"
|
||||
case ChannelHistoryChanged = "channel_history_changed"
|
||||
case DNDUpdated = "dnd_updated"
|
||||
case DNDUpatedUser = "dnd_updated_user"
|
||||
case IMCreated = "im_created"
|
||||
case IMOpen = "im_open"
|
||||
case IMClose = "im_close"
|
||||
case IMMarked = "im_marked"
|
||||
case IMHistoryChanged = "im_history_changed"
|
||||
case GroupJoined = "group_joined"
|
||||
case GroupLeft = "group_left"
|
||||
case GroupOpen = "group_open"
|
||||
case GroupClose = "group_close"
|
||||
case GroupArchive = "group_archive"
|
||||
case GroupUnarchive = "group_unarchive"
|
||||
case GroupRename = "group_rename"
|
||||
case GroupMarked = "group_marked"
|
||||
case GroupHistoryChanged = "group_history_changed"
|
||||
case FileCreated = "file_created"
|
||||
case FileShared = "file_shared"
|
||||
case FileUnshared = "file_unshared"
|
||||
case FilePublic = "file_public"
|
||||
case FilePrivate = "file_private"
|
||||
case FileChanged = "file_change"
|
||||
case FileDeleted = "file_deleted"
|
||||
case FileCommentAdded = "file_comment_added"
|
||||
case FileCommentEdited = "file_comment_edited"
|
||||
case FileCommentDeleted = "file_comment_deleted"
|
||||
case PinAdded = "pin_added"
|
||||
case PinRemoved = "pin_removed"
|
||||
case Pong = "pong"
|
||||
case PresenceChange = "presence_change"
|
||||
case ManualPresenceChange = "manual_presence_change"
|
||||
case PrefChange = "pref_change"
|
||||
case UserChange = "user_change"
|
||||
case TeamJoin = "team_join"
|
||||
case StarAdded = "star_added"
|
||||
case StarRemoved = "star_removed"
|
||||
case ReactionAdded = "reaction_added"
|
||||
case ReactionRemoved = "reaction_removed"
|
||||
case EmojiChanged = "emoji_changed"
|
||||
case CommandsChanged = "commands_changed"
|
||||
case TeamPlanChange = "team_plan_change"
|
||||
case TeamPrefChange = "team_pref_change"
|
||||
case TeamRename = "team_rename"
|
||||
case TeamDomainChange = "team_domain_change"
|
||||
case EmailDomainChange = "email_domain_change"
|
||||
case TeamProfileChange = "team_profile_change"
|
||||
case TeamProfileDelete = "team_profile_delete"
|
||||
case TeamProfileReorder = "team_profile_reorder"
|
||||
case BotAdded = "bot_added"
|
||||
case BotChanged = "bot_changed"
|
||||
case AccountsChanged = "accounts_changed"
|
||||
case TeamMigrationStarted = "team_migration_started"
|
||||
case ReconnectURL = "reconnect_url"
|
||||
case SubteamCreated = "subteam_created"
|
||||
case SubteamUpdated = "subteam_updated"
|
||||
case SubteamSelfAdded = "subteam_self_added"
|
||||
case SubteamSelfRemoved = "subteam_self_removed"
|
||||
case Ok = "ok"
|
||||
case Error = "error"
|
||||
}
|
||||
|
||||
internal enum MessageSubtype: String {
|
||||
case BotMessage = "bot_message"
|
||||
case MeMessage = "me_message"
|
||||
case MessageChanged = "message_changed"
|
||||
case MessageDeleted = "message_deleted"
|
||||
case ChannelJoin = "channel_join"
|
||||
case ChannelLeave = "channel_leave"
|
||||
case ChannelTopic = "channel_topic"
|
||||
case ChannelPurpose = "channel_purpose"
|
||||
case ChannelName = "channel_name"
|
||||
case ChannelArchive = "channel_archive"
|
||||
case ChannelUnarchive = "channel_unarchive"
|
||||
case GroupJoin = "group_join"
|
||||
case GroupLeave = "group_leave"
|
||||
case GroupTopic = "group_topic"
|
||||
case GroupPurpose = "group_purpose"
|
||||
case GroupName = "group_name"
|
||||
case GroupArchive = "group_archive"
|
||||
case GroupUnarchive = "group_unarchive"
|
||||
case FileShare = "file_share"
|
||||
case FileComment = "file_comment"
|
||||
case FileMention = "file_mention"
|
||||
case PinnedItem = "pinned_item"
|
||||
case UnpinnedItem = "unpinned_item"
|
||||
}
|
||||
|
||||
internal struct Event {
|
||||
|
||||
let type: EventType?
|
||||
let ts: String?
|
||||
let subtype: String?
|
||||
let channelID: String?
|
||||
let text: String?
|
||||
let eventTs: String?
|
||||
let latest: String?
|
||||
let hidden: Bool?
|
||||
let isStarred: Bool?
|
||||
let hasPins: Bool?
|
||||
let pinnedTo: [String]?
|
||||
let fileID: String?
|
||||
let presence: String?
|
||||
let name: String?
|
||||
let value: AnyObject?
|
||||
let plan: String?
|
||||
let url: String?
|
||||
let domain: String?
|
||||
let emailDomain: String?
|
||||
let reaction: String?
|
||||
let replyTo: Double?
|
||||
let reactions: [[String: AnyObject]]?
|
||||
let edited: Edited?
|
||||
let bot: Bot?
|
||||
let channel: Channel?
|
||||
let comment: Comment?
|
||||
let user: User?
|
||||
let file: File?
|
||||
let message: Message?
|
||||
let nestedMessage: Message?
|
||||
let itemUser: String?
|
||||
let item: Item?
|
||||
let dndStatus: DoNotDisturbStatus?
|
||||
let subteam: UserGroup?
|
||||
let subteamID: String?
|
||||
var profile: CustomProfile?
|
||||
|
||||
init(event:[String: AnyObject]) {
|
||||
if let eventType = event["type"] as? String {
|
||||
type = EventType(rawValue:eventType)
|
||||
} else {
|
||||
type = EventType(rawValue: "ok")
|
||||
}
|
||||
ts = event["ts"] as? String
|
||||
subtype = event["subtype"] as? String
|
||||
channelID = event["channel_id"] as? String
|
||||
text = event["text"] as? String
|
||||
eventTs = event["event_ts"] as? String
|
||||
latest = event["latest"] as? String
|
||||
hidden = event["hidden"] as? Bool
|
||||
isStarred = event["is_starred"] as? Bool
|
||||
hasPins = event["has_pins"] as? Bool
|
||||
pinnedTo = event["pinned_top"] as? [String]
|
||||
fileID = event["file_id"] as? String
|
||||
presence = event["presence"] as? String
|
||||
name = event["name"] as? String
|
||||
value = event["value"]
|
||||
plan = event["plan"] as? String
|
||||
url = event["url"] as? String
|
||||
domain = event["domain"] as? String
|
||||
emailDomain = event["email_domain"] as? String
|
||||
reaction = event["reaction"] as? String
|
||||
replyTo = event["reply_to"] as? Double
|
||||
reactions = event["reactions"] as? [[String: AnyObject]]
|
||||
bot = Bot(bot: event["bot"] as? [String: AnyObject])
|
||||
edited = Edited(edited:event["edited"] as? [String: AnyObject])
|
||||
dndStatus = DoNotDisturbStatus(status: event["dnd_status"] as? [String: AnyObject])
|
||||
itemUser = event["item_user"] as? String
|
||||
item = Item(item: event["item"] as? [String: AnyObject])
|
||||
subteam = UserGroup(userGroup: event["subteam"] as? [String: AnyObject])
|
||||
subteamID = event["subteam_id"] as? String
|
||||
message = Message(message: event)
|
||||
nestedMessage = Message(message: event["message"] as? [String: AnyObject])
|
||||
profile = CustomProfile(profile: event["profile"] as? [String: AnyObject])
|
||||
file = File(id: event["file"] as? String)
|
||||
|
||||
// Comment, Channel, and User can come across as Strings or Dictionaries
|
||||
if let commentDictionary = event["comment"] as? [String: AnyObject] {
|
||||
comment = Comment(comment: commentDictionary)
|
||||
} else {
|
||||
comment = Comment(id: event["comment"] as? String)
|
||||
}
|
||||
|
||||
if let userDictionary = event["user"] as? [String: AnyObject] {
|
||||
user = User(user: userDictionary)
|
||||
} else {
|
||||
user = User(id: event["user"] as? String)
|
||||
}
|
||||
|
||||
if let channelDictionary = event["channel"] as? [String: AnyObject] {
|
||||
channel = Channel(channel: channelDictionary)
|
||||
} else {
|
||||
channel = Channel(id: event["channel"] as? String)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
//
|
||||
// EventDelegate.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol SlackEventsDelegate: class {
|
||||
func clientConnectionFailed(error: SlackError)
|
||||
func clientConnected()
|
||||
func clientDisconnected()
|
||||
func preferenceChanged(preference: String, value: AnyObject?)
|
||||
func userChanged(user: User)
|
||||
func presenceChanged(user: User, presence: String)
|
||||
func manualPresenceChanged(user: User, presence: String)
|
||||
func botEvent(bot: Bot)
|
||||
}
|
||||
|
||||
public protocol MessageEventsDelegate: class {
|
||||
func messageSent(message: Message)
|
||||
func messageReceived(message: Message)
|
||||
func messageChanged(message: Message)
|
||||
func messageDeleted(message: Message?)
|
||||
}
|
||||
|
||||
public protocol ChannelEventsDelegate: class {
|
||||
func userTyping(channel: Channel, user: User)
|
||||
func channelMarked(channel: Channel, timestamp: String)
|
||||
func channelCreated(channel: Channel)
|
||||
func channelDeleted(channel: Channel)
|
||||
func channelRenamed(channel: Channel)
|
||||
func channelArchived(channel: Channel)
|
||||
func channelHistoryChanged(channel: Channel)
|
||||
func channelJoined(channel: Channel)
|
||||
func channelLeft(channel: Channel)
|
||||
}
|
||||
|
||||
public protocol DoNotDisturbEventsDelegate: class {
|
||||
func doNotDisturbUpdated(dndStatus: DoNotDisturbStatus)
|
||||
func doNotDisturbUserUpdated(dndStatus: DoNotDisturbStatus, user: User)
|
||||
}
|
||||
|
||||
public protocol GroupEventsDelegate: class {
|
||||
func groupOpened(group: Channel)
|
||||
}
|
||||
|
||||
public protocol FileEventsDelegate: class {
|
||||
func fileProcessed(file: File)
|
||||
func fileMadePrivate(file: File)
|
||||
func fileDeleted(file: File)
|
||||
func fileCommentAdded(file: File, comment: Comment)
|
||||
func fileCommentEdited(file: File, comment: Comment)
|
||||
func fileCommentDeleted(file: File, comment: Comment)
|
||||
}
|
||||
|
||||
public protocol PinEventsDelegate: class {
|
||||
func itemPinned(item: Item, channel: Channel?)
|
||||
func itemUnpinned(item: Item, channel: Channel?)
|
||||
}
|
||||
|
||||
public protocol StarEventsDelegate: class {
|
||||
func itemStarred(item: Item, star: Bool)
|
||||
}
|
||||
|
||||
public protocol ReactionEventsDelegate: class {
|
||||
func reactionAdded(reaction: String, item: Item, itemUser: String)
|
||||
func reactionRemoved(reaction: String, item: Item, itemUser: String)
|
||||
}
|
||||
|
||||
public protocol TeamEventsDelegate: class {
|
||||
func teamJoined(user: User)
|
||||
func teamPlanChanged(plan: String)
|
||||
func teamPreferencesChanged(preference: String, value: AnyObject?)
|
||||
func teamNameChanged(name: String)
|
||||
func teamDomainChanged(domain: String)
|
||||
func teamEmailDomainChanged(domain: String)
|
||||
func teamEmojiChanged()
|
||||
}
|
||||
|
||||
public protocol SubteamEventsDelegate: class {
|
||||
func subteamEvent(userGroup: UserGroup)
|
||||
func subteamSelfAdded(subteamID: String)
|
||||
func subteamSelfRemoved(subteamID: String)
|
||||
}
|
||||
|
||||
public protocol TeamProfileEventsDelegate: class {
|
||||
func teamProfileChanged(profile: CustomProfile)
|
||||
func teamProfileDeleted(profile: CustomProfile)
|
||||
func teamProfileReordered(profile: CustomProfile)
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// Extensions.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension NSDate {
|
||||
|
||||
func slackTimestamp() -> Double {
|
||||
return NSNumber(double: timeIntervalSince1970).doubleValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal extension String {
|
||||
|
||||
func slackFormatEscaping() -> String {
|
||||
var escapedString = stringByReplacingOccurrencesOfString("&", withString: "&")
|
||||
escapedString = stringByReplacingOccurrencesOfString("<", withString: "<")
|
||||
escapedString = stringByReplacingOccurrencesOfString(">", withString: ">")
|
||||
return escapedString
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
//
|
||||
// File.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public struct File {
|
||||
|
||||
public let id: String?
|
||||
public let created: Int?
|
||||
public let name: String?
|
||||
public let title: String?
|
||||
public let mimeType: String?
|
||||
public let fileType: String?
|
||||
public let prettyType: String?
|
||||
public let user: String?
|
||||
public let mode: String?
|
||||
internal(set) public var editable: Bool?
|
||||
public let isExternal: Bool?
|
||||
public let externalType: String?
|
||||
public let size: Int?
|
||||
public let urlPrivate: String?
|
||||
public let urlPrivateDownload: String?
|
||||
public let thumb64: String?
|
||||
public let thumb80: String?
|
||||
public let thumb360: String?
|
||||
public let thumb360gif: String?
|
||||
public let thumb360w: String?
|
||||
public let thumb360h: String?
|
||||
public let thumb480: String?
|
||||
public let thumb480gif: String?
|
||||
public let thumb480w: String?
|
||||
public let thumb480h: String?
|
||||
public let thumb720: String?
|
||||
public let thumb720gif: String?
|
||||
public let thumb720w: String?
|
||||
public let thumb720h: String?
|
||||
public let thumb960: String?
|
||||
public let thumb960gif: String?
|
||||
public let thumb960w: String?
|
||||
public let thumb960h: String?
|
||||
public let thumb1024: String?
|
||||
public let thumb1024gif: String?
|
||||
public let thumb1024w: String?
|
||||
public let thumb1024h: String?
|
||||
public let permalink: String?
|
||||
public let editLink: String?
|
||||
public let preview: String?
|
||||
public let previewHighlight: String?
|
||||
public let lines: Int?
|
||||
public let linesMore: Int?
|
||||
internal(set) public var isPublic: Bool?
|
||||
internal(set) public var publicSharedURL: Bool?
|
||||
internal(set) public var channels: [String]?
|
||||
internal(set) public var groups: [String]?
|
||||
internal(set) public var ims: [String]?
|
||||
public let initialComment: Comment?
|
||||
internal(set) public var stars: Int?
|
||||
internal(set) public var isStarred: Bool?
|
||||
internal(set) public var pinnedTo: [String]?
|
||||
internal(set) public var comments = [String: Comment]()
|
||||
internal(set) public var reactions = [Reaction]()
|
||||
|
||||
public init(file:[String: AnyObject]?) {
|
||||
id = file?["id"] as? String
|
||||
created = file?["created"] as? Int
|
||||
name = file?["name"] as? String
|
||||
title = file?["title"] as? String
|
||||
mimeType = file?["mimetype"] as? String
|
||||
fileType = file?["filetype"] as? String
|
||||
prettyType = file?["pretty_type"] as? String
|
||||
user = file?["user"] as? String
|
||||
mode = file?["mode"] as? String
|
||||
editable = file?["editable"] as? Bool
|
||||
isExternal = file?["is_external"] as? Bool
|
||||
externalType = file?["external_type"] as? String
|
||||
size = file?["size"] as? Int
|
||||
urlPrivate = file?["url_private"] as? String
|
||||
urlPrivateDownload = file?["url_private_download"] as? String
|
||||
thumb64 = file?["thumb_64"] as? String
|
||||
thumb80 = file?["thumb_80"] as? String
|
||||
thumb360 = file?["thumb_360"] as? String
|
||||
thumb360gif = file?["thumb_360_gif"] as? String
|
||||
thumb360w = file?["thumb_360_w"] as? String
|
||||
thumb360h = file?["thumb_360_h"] as? String
|
||||
thumb480 = file?["thumb_480"] as? String
|
||||
thumb480gif = file?["thumb_480_gif"] as? String
|
||||
thumb480w = file?["thumb_480_w"] as? String
|
||||
thumb480h = file?["thumb_480_h"] as? String
|
||||
thumb720 = file?["thumb_720"] as? String
|
||||
thumb720gif = file?["thumb_720_gif"] as? String
|
||||
thumb720w = file?["thumb_720_w"] as? String
|
||||
thumb720h = file?["thumb_720_h"] as? String
|
||||
thumb960 = file?["thumb_960"] as? String
|
||||
thumb960gif = file?["thumb_960_gif"] as? String
|
||||
thumb960w = file?["thumb_960_w"] as? String
|
||||
thumb960h = file?["thumb_960_h"] as? String
|
||||
thumb1024 = file?["thumb_1024"] as? String
|
||||
thumb1024gif = file?["thumb_1024_gif"] as? String
|
||||
thumb1024w = file?["thumb_1024_w"] as? String
|
||||
thumb1024h = file?["thumb_1024_h"] as? String
|
||||
permalink = file?["permalink"] as? String
|
||||
editLink = file?["edit_link"] as? String
|
||||
preview = file?["preview"] as? String
|
||||
previewHighlight = file?["preview_highlight"] as? String
|
||||
lines = file?["lines"] as? Int
|
||||
linesMore = file?["lines_more"] as? Int
|
||||
isPublic = file?["is_public"] as? Bool
|
||||
publicSharedURL = file?["public_url_shared"] as? Bool
|
||||
channels = file?["channels"] as? [String]
|
||||
groups = file?["groups"] as? [String]
|
||||
ims = file?["ims"] as? [String]
|
||||
initialComment = Comment(comment: file?["initial_comment"] as? [String: AnyObject])
|
||||
stars = file?["num_stars"] as? Int
|
||||
isStarred = file?["is_starred"] as? Bool
|
||||
pinnedTo = file?["pinned_to"] as? [String]
|
||||
reactions = Reaction.reactionsFromArray(file?["reactions"] as? [[String: AnyObject]])
|
||||
}
|
||||
|
||||
internal init(id:String?) {
|
||||
self.id = id
|
||||
created = nil
|
||||
name = nil
|
||||
title = nil
|
||||
mimeType = nil
|
||||
fileType = nil
|
||||
prettyType = nil
|
||||
user = nil
|
||||
mode = nil
|
||||
isExternal = nil
|
||||
externalType = nil
|
||||
size = nil
|
||||
urlPrivate = nil
|
||||
urlPrivateDownload = nil
|
||||
thumb64 = nil
|
||||
thumb80 = nil
|
||||
thumb360 = nil
|
||||
thumb360gif = nil
|
||||
thumb360w = nil
|
||||
thumb360h = nil
|
||||
thumb480 = nil
|
||||
thumb480gif = nil
|
||||
thumb480w = nil
|
||||
thumb480h = nil
|
||||
thumb720 = nil
|
||||
thumb720gif = nil
|
||||
thumb720w = nil
|
||||
thumb720h = nil
|
||||
thumb960 = nil
|
||||
thumb960gif = nil
|
||||
thumb960w = nil
|
||||
thumb960h = nil
|
||||
thumb1024 = nil
|
||||
thumb1024gif = nil
|
||||
thumb1024w = nil
|
||||
thumb1024h = nil
|
||||
permalink = nil
|
||||
editLink = nil
|
||||
preview = nil
|
||||
previewHighlight = nil
|
||||
lines = nil
|
||||
linesMore = nil
|
||||
initialComment = nil
|
||||
}
|
||||
}
|
||||
|
||||
extension File: Equatable {}
|
||||
|
||||
public func ==(lhs: File, rhs: File) -> Bool {
|
||||
return lhs.id == rhs.id
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
//
|
||||
// Message.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public class Message {
|
||||
|
||||
public let type = "message"
|
||||
public let subtype: String?
|
||||
internal(set) public var ts: String?
|
||||
public let user: String?
|
||||
public let channel: String?
|
||||
internal(set) public var hidden: Bool?
|
||||
internal(set) public var text: String?
|
||||
public let botID: String?
|
||||
public let username: String?
|
||||
public let icons: [String: AnyObject]?
|
||||
public let deletedTs: String?
|
||||
internal(set) var purpose: String?
|
||||
internal(set) var topic: String?
|
||||
internal(set) var name: String?
|
||||
internal(set) var members: [String]?
|
||||
internal(set) var oldName: String?
|
||||
public let upload: Bool?
|
||||
public let itemType: String?
|
||||
internal(set) public var isStarred: Bool?
|
||||
internal(set) var pinnedTo: [String]?
|
||||
public let comment: Comment?
|
||||
public let file: File?
|
||||
internal(set) public var reactions = [Reaction]()
|
||||
internal(set) public var attachments: [Attachment]?
|
||||
|
||||
public init(message: [String: AnyObject]?) {
|
||||
subtype = message?["subtype"] as? String
|
||||
ts = message?["ts"] as? String
|
||||
user = message?["user"] as? String
|
||||
channel = message?["channel"] as? String
|
||||
hidden = message?["hidden"] as? Bool
|
||||
text = message?["text"] as? String
|
||||
botID = message?["bot_id"] as? String
|
||||
username = message?["username"] as? String
|
||||
icons = message?["icons"] as? [String: AnyObject]
|
||||
deletedTs = message?["deleted_ts"] as? String
|
||||
purpose = message?["purpose"] as? String
|
||||
topic = message?["topic"] as? String
|
||||
name = message?["name"] as? String
|
||||
members = message?["members"] as? [String]
|
||||
oldName = message?["old_name"] as? String
|
||||
upload = message?["upload"] as? Bool
|
||||
itemType = message?["item_type"] as? String
|
||||
isStarred = message?["is_starred"] as? Bool
|
||||
pinnedTo = message?["pinned_to"] as? [String]
|
||||
comment = Comment(comment: message?["comment"] as? [String: AnyObject])
|
||||
file = File(file: message?["file"] as? [String: AnyObject])
|
||||
reactions = Reaction.reactionsFromArray(message?["reactions"] as? [[String: AnyObject]])
|
||||
attachments = (message?["attachments"] as? [[String: AnyObject]])?.map({(attachment) -> Attachment in
|
||||
return Attachment(attachment: attachment)
|
||||
})
|
||||
}
|
||||
|
||||
internal init(ts:String?) {
|
||||
self.ts = ts
|
||||
subtype = nil
|
||||
user = nil
|
||||
channel = nil
|
||||
botID = nil
|
||||
username = nil
|
||||
icons = nil
|
||||
deletedTs = nil
|
||||
upload = nil
|
||||
itemType = nil
|
||||
comment = nil
|
||||
file = nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Message: Equatable {}
|
||||
|
||||
public func ==(lhs: Message, rhs: Message) -> Bool {
|
||||
return lhs.ts == rhs.ts && lhs.user == rhs.user && lhs.text == rhs.text
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
//
|
||||
// NetworkInterface.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
internal struct NetworkInterface {
|
||||
|
||||
private let apiUrl = "https://slack.com/api/"
|
||||
|
||||
internal func request(endpoint: SlackAPIEndpoint, token: String, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
|
||||
var requestString = "\(apiUrl)\(endpoint.rawValue)?token=\(token)"
|
||||
if let params = parameters {
|
||||
requestString += requestStringFromParameters(params)
|
||||
}
|
||||
guard let url = NSURL(string: requestString) else {
|
||||
errorClosure(SlackError.ClientNetworkError)
|
||||
return
|
||||
}
|
||||
let request = NSURLRequest(URL:url)
|
||||
NSURLSession.sharedSession().dataTaskWithRequest(request) {
|
||||
(data, response, internalError) -> Void in
|
||||
self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in
|
||||
successClosure(json)
|
||||
}, errorClosure: {(error) in
|
||||
errorClosure(error)
|
||||
})
|
||||
}.resume()
|
||||
}
|
||||
|
||||
internal func uploadRequest(token: String, data: NSData, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
|
||||
var requestString = "\(apiUrl)\(SlackAPIEndpoint.FilesUpload.rawValue)?token=\(token)"
|
||||
if let params = parameters {
|
||||
requestString = requestString + requestStringFromParameters(params)
|
||||
}
|
||||
guard let url = NSURL(string: requestString) else {
|
||||
errorClosure(SlackError.ClientNetworkError)
|
||||
return
|
||||
}
|
||||
let request = NSMutableURLRequest(URL:url)
|
||||
request.HTTPMethod = "POST"
|
||||
let boundaryConstant = randomBoundary()
|
||||
let contentType = "multipart/form-data; boundary=" + boundaryConstant
|
||||
let boundaryStart = "--\(boundaryConstant)\r\n"
|
||||
let boundaryEnd = "--\(boundaryConstant)--\r\n"
|
||||
let contentDispositionString = "Content-Disposition: form-data; name=\"file\"; filename=\"\(parameters!["filename"])\"\r\n"
|
||||
let contentTypeString = "Content-Type: \(parameters!["filetype"])\r\n\r\n"
|
||||
|
||||
let requestBodyData : NSMutableData = NSMutableData()
|
||||
requestBodyData.appendData(boundaryStart.dataUsingEncoding(NSUTF8StringEncoding)!)
|
||||
requestBodyData.appendData(contentDispositionString.dataUsingEncoding(NSUTF8StringEncoding)!)
|
||||
requestBodyData.appendData(contentTypeString.dataUsingEncoding(NSUTF8StringEncoding)!)
|
||||
requestBodyData.appendData(data)
|
||||
requestBodyData.appendData("\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
|
||||
requestBodyData.appendData(boundaryEnd.dataUsingEncoding(NSUTF8StringEncoding)!)
|
||||
|
||||
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
|
||||
request.HTTPBody = requestBodyData
|
||||
|
||||
NSURLSession.sharedSession().dataTaskWithRequest(request) {
|
||||
(data, response, internalError) -> Void in
|
||||
self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in
|
||||
successClosure(json)
|
||||
}, errorClosure: {(error) in
|
||||
errorClosure(error)
|
||||
})
|
||||
}.resume()
|
||||
}
|
||||
|
||||
private func handleResponse(data: NSData?, response:NSURLResponse?, internalError:NSError?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
|
||||
guard let data = data, response = response as? NSHTTPURLResponse else {
|
||||
errorClosure(SlackError.ClientNetworkError)
|
||||
return
|
||||
}
|
||||
do {
|
||||
guard let json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String: AnyObject] else {
|
||||
errorClosure(SlackError.ClientJSONError)
|
||||
return
|
||||
}
|
||||
|
||||
switch response.statusCode {
|
||||
case 200:
|
||||
if (json["ok"] as! Bool == true) {
|
||||
successClosure(json)
|
||||
} else {
|
||||
if let errorString = json["error"] as? String {
|
||||
throw ErrorDispatcher.dispatch(errorString)
|
||||
} else {
|
||||
throw SlackError.UnknownError
|
||||
}
|
||||
}
|
||||
case 429:
|
||||
throw SlackError.TooManyRequests
|
||||
default:
|
||||
throw SlackError.ClientNetworkError
|
||||
}
|
||||
} catch let error {
|
||||
if let slackError = error as? SlackError {
|
||||
errorClosure(slackError)
|
||||
} else {
|
||||
errorClosure(SlackError.UnknownError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func randomBoundary() -> String {
|
||||
return String(format: "slackkit.boundary.%08x%08x", arc4random(), arc4random())
|
||||
}
|
||||
|
||||
private func requestStringFromParameters(parameters: [String: AnyObject]) -> String {
|
||||
var requestString = ""
|
||||
for key in parameters.keys {
|
||||
if let value = parameters[key] as? String, encodedValue = value.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet()) {
|
||||
requestString += "&\(key)=\(encodedValue)"
|
||||
} else if let value = parameters[key] as? Int {
|
||||
requestString += "&\(key)=\(value)"
|
||||
}
|
||||
}
|
||||
|
||||
return requestString
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,752 +0,0 @@
|
||||
//
|
||||
// SlackWebAPI.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
internal enum SlackAPIEndpoint: String {
|
||||
case APITest = "api.test"
|
||||
case AuthTest = "auth.test"
|
||||
case ChannelsHistory = "channels.history"
|
||||
case ChannelsInfo = "channels.info"
|
||||
case ChannelsList = "channels.list"
|
||||
case ChannelsMark = "channels.mark"
|
||||
case ChannelsSetPurpose = "channels.setPurpose"
|
||||
case ChannelsSetTopic = "channels.setTopic"
|
||||
case ChatDelete = "chat.delete"
|
||||
case ChatPostMessage = "chat.postMessage"
|
||||
case ChatUpdate = "chat.update"
|
||||
case DNDInfo = "dnd.info"
|
||||
case DNDTeamInfo = "dnd.teamInfo"
|
||||
case EmojiList = "emoji.list"
|
||||
case FilesCommentsAdd = "files.comments.add"
|
||||
case FilesCommentsEdit = "files.comments.edit"
|
||||
case FilesCommentsDelete = "files.comments.delete"
|
||||
case FilesDelete = "files.delete"
|
||||
case FilesInfo = "files.info"
|
||||
case FilesUpload = "files.upload"
|
||||
case GroupsClose = "groups.close"
|
||||
case GroupsHistory = "groups.history"
|
||||
case GroupsInfo = "groups.info"
|
||||
case GroupsList = "groups.list"
|
||||
case GroupsMark = "groups.mark"
|
||||
case GroupsOpen = "groups.open"
|
||||
case GroupsSetPurpose = "groups.setPurpose"
|
||||
case GroupsSetTopic = "groups.setTopic"
|
||||
case IMClose = "im.close"
|
||||
case IMHistory = "im.history"
|
||||
case IMList = "im.list"
|
||||
case IMMark = "im.mark"
|
||||
case IMOpen = "im.open"
|
||||
case MPIMClose = "mpim.close"
|
||||
case MPIMHistory = "mpim.history"
|
||||
case MPIMList = "mpim.list"
|
||||
case MPIMMark = "mpim.mark"
|
||||
case MPIMOpen = "mpim.open"
|
||||
case PinsAdd = "pins.add"
|
||||
case PinsRemove = "pins.remove"
|
||||
case ReactionsAdd = "reactions.add"
|
||||
case ReactionsGet = "reactions.get"
|
||||
case ReactionsList = "reactions.list"
|
||||
case ReactionsRemove = "reactions.remove"
|
||||
case RTMStart = "rtm.start"
|
||||
case StarsAdd = "stars.add"
|
||||
case StarsRemove = "stars.remove"
|
||||
case TeamInfo = "team.info"
|
||||
case UsersGetPresence = "users.getPresence"
|
||||
case UsersInfo = "users.info"
|
||||
case UsersList = "users.list"
|
||||
case UsersSetActive = "users.setActive"
|
||||
case UsersSetPresence = "users.setPresence"
|
||||
}
|
||||
|
||||
public class SlackWebAPI {
|
||||
|
||||
public typealias FailureClosure = (error: SlackError)->Void
|
||||
|
||||
public enum InfoType: String {
|
||||
case Purpose = "purpose"
|
||||
case Topic = "topic"
|
||||
}
|
||||
|
||||
public enum ParseMode: String {
|
||||
case Full = "full"
|
||||
case None = "none"
|
||||
}
|
||||
|
||||
public enum Presence: String {
|
||||
case Auto = "auto"
|
||||
case Away = "away"
|
||||
}
|
||||
|
||||
private enum ChannelType: String {
|
||||
case Channel = "channel"
|
||||
case Group = "group"
|
||||
case IM = "im"
|
||||
}
|
||||
|
||||
private let networkInterface: NetworkInterface
|
||||
private let token: String
|
||||
|
||||
init(networkInterface: NetworkInterface, token: String) {
|
||||
self.networkInterface = networkInterface
|
||||
self.token = token
|
||||
}
|
||||
|
||||
convenience public init(client: Client) {
|
||||
self.init(networkInterface: client.api, token: client.token)
|
||||
}
|
||||
|
||||
//MARK: - RTM
|
||||
public func rtmStart(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((response: [String: AnyObject])->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["simple_latest": simpleLatest, "no_unreads": noUnreads, "mpim_aware": mpimAware]
|
||||
networkInterface.request(.RTMStart, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(response: response)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Auth Test
|
||||
public func authenticationTest(success: ((authenticated: Bool)->Void)?, failure: FailureClosure?) {
|
||||
networkInterface.request(.AuthTest, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(authenticated: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Channels
|
||||
public func channelHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
|
||||
history(.ChannelsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
|
||||
(history) -> Void in
|
||||
success?(history: history)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func channelInfo(id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
|
||||
info(.ChannelsInfo, type:ChannelType.Channel, id: id, success: {
|
||||
(channel) -> Void in
|
||||
success?(channel: channel)
|
||||
}) { (error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func channelsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
|
||||
list(.ChannelsList, type:ChannelType.Channel, excludeArchived: excludeArchived, success: {
|
||||
(channels) -> Void in
|
||||
success?(channels: channels)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func markChannel(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
|
||||
mark(.ChannelsMark, channel: channel, timestamp: timestamp, success: {
|
||||
(ts) -> Void in
|
||||
success?(ts:timestamp)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func setChannelPurpose(channel: String, purpose: String, success: ((purposeSet: Bool)->Void)?, failure: FailureClosure?) {
|
||||
setInfo(.ChannelsSetPurpose, type: .Purpose, channel: channel, text: purpose, success: {
|
||||
(purposeSet) -> Void in
|
||||
success?(purposeSet: purposeSet)
|
||||
}) { (error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func setChannelTopic(channel: String, topic: String, success: ((topicSet: Bool)->Void)?, failure: FailureClosure?) {
|
||||
setInfo(.ChannelsSetTopic, type: .Topic, channel: channel, text: topic, success: {
|
||||
(topicSet) -> Void in
|
||||
success?(topicSet: topicSet)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Messaging
|
||||
public func deleteMessage(channel: String, ts: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["channel": channel, "ts": ts]
|
||||
networkInterface.request(.ChatDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in
|
||||
success?(deleted: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func sendMessage(channel: String, text: String, username: String? = nil, asUser: Bool? = nil, parse: ParseMode? = nil, linkNames: Bool? = nil, attachments: [Attachment?]? = nil, unfurlLinks: Bool? = nil, unfurlMedia: Bool? = nil, iconURL: String? = nil, iconEmoji: String? = nil, success: (((ts: String?, channel: String?))->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["channel":channel, "text":text.slackFormatEscaping(), "as_user":asUser, "parse":parse?.rawValue, "link_names":linkNames, "unfurl_links":unfurlLinks, "unfurlMedia":unfurlMedia, "username":username, "attachments":encodeAttachments(attachments), "icon_url":iconURL, "icon_emoji":iconEmoji]
|
||||
networkInterface.request(.ChatPostMessage, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?((ts: response["ts"] as? String, response["channel"] as? String))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func updateMessage(channel: String, ts: String, message: String, attachments: [Attachment?]? = nil, parse:ParseMode = .None, linkNames: Bool = false, success: ((updated: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["channel": channel, "ts": ts, "text": message.slackFormatEscaping(), "parse": parse.rawValue, "link_names": linkNames, "attachments":encodeAttachments(attachments)]
|
||||
networkInterface.request(.ChatUpdate, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(updated: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Do Not Disturb
|
||||
public func dndInfo(user: String? = nil, success: ((status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["user": user]
|
||||
networkInterface.request(.DNDInfo, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(status: DoNotDisturbStatus(status: response))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func dndTeamInfo(users: [String]? = nil, success: ((statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["users":users?.joinWithSeparator(",")]
|
||||
networkInterface.request(.DNDTeamInfo, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
guard let usersDictionary = response["users"] as? [String: AnyObject] else {
|
||||
success?(statuses: [:])
|
||||
return
|
||||
}
|
||||
success?(statuses: self.enumerateDNDStatuses(usersDictionary))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Emoji
|
||||
public func emojiList(success: ((emojiList: [String: AnyObject]?)->Void)?, failure: FailureClosure?) {
|
||||
networkInterface.request(.EmojiList, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(emojiList: response["emoji"] as? [String: AnyObject])
|
||||
}) { (error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Files
|
||||
public func deleteFile(fileID: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters = ["file":fileID]
|
||||
networkInterface.request(.FilesDelete, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(deleted: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func fileInfo(fileID: String, commentCount: Int = 100, totalPages: Int = 1, success: ((file: File)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["file":fileID, "count": commentCount, "totalPages":totalPages]
|
||||
networkInterface.request(.FilesInfo, token: token, parameters: parameters, successClosure: {
|
||||
(response) in
|
||||
var file = File(file: response["file"] as? [String: AnyObject])
|
||||
(response["comments"] as? [[String: AnyObject]])?.forEach { comment in
|
||||
let comment = Comment(comment: comment)
|
||||
if let id = comment.id {
|
||||
file.comments[id] = comment
|
||||
}
|
||||
}
|
||||
success?(file: file)
|
||||
}) {(error) in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func uploadFile(file: NSData, filename: String, filetype: String = "auto", title: String? = nil, initialComment: String? = nil, channels: [String]? = nil, success: ((file: File)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["file":file, "filename": filename, "filetype":filetype, "title":title, "initial_comment":initialComment, "channels":channels?.joinWithSeparator(",")]
|
||||
networkInterface.uploadRequest(token, data: file, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(file: File(file: response["file"] as? [String: AnyObject]))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - File Comments
|
||||
public func addFileComment(fileID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["file":fileID, "comment":comment.slackFormatEscaping()]
|
||||
networkInterface.request(.FilesCommentsAdd, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(comment: Comment(comment: response["comment"] as? [String: AnyObject]))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func editFileComment(fileID: String, commentID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["file":fileID, "id":commentID, "comment":comment.slackFormatEscaping()]
|
||||
networkInterface.request(.FilesCommentsEdit, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(comment: Comment(comment: response["comment"] as? [String: AnyObject]))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func deleteFileComment(fileID: String, commentID: String, success: ((deleted: Bool?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["file":fileID, "id": commentID]
|
||||
networkInterface.request(.FilesCommentsDelete, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(deleted: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Groups
|
||||
public func closeGroup(groupID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
|
||||
close(.GroupsClose, channelID: groupID, success: {
|
||||
(closed) -> Void in
|
||||
success?(closed:closed)
|
||||
}) {(error) -> Void in
|
||||
failure?(error:error)
|
||||
}
|
||||
}
|
||||
|
||||
public func groupHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
|
||||
history(.GroupsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
|
||||
(history) -> Void in
|
||||
success?(history: history)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func groupInfo(id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
|
||||
info(.GroupsInfo, type:ChannelType.Group, id: id, success: {
|
||||
(channel) -> Void in
|
||||
success?(channel: channel)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func groupsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
|
||||
list(.GroupsList, type:ChannelType.Group, excludeArchived: excludeArchived, success: {
|
||||
(channels) -> Void in
|
||||
success?(channels: channels)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func markGroup(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
|
||||
mark(.GroupsMark, channel: channel, timestamp: timestamp, success: {
|
||||
(ts) -> Void in
|
||||
success?(ts: timestamp)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func openGroup(channel: String, success: ((opened: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters = ["channel":channel]
|
||||
networkInterface.request(.GroupsOpen, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(opened: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func setGroupPurpose(channel: String, purpose: String, success: ((purposeSet: Bool)->Void)?, failure: FailureClosure?) {
|
||||
setInfo(.GroupsSetPurpose, type: .Purpose, channel: channel, text: purpose, success: {
|
||||
(purposeSet) -> Void in
|
||||
success?(purposeSet: purposeSet)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func setGroupTopic(channel: String, topic: String, success: ((topicSet: Bool)->Void)?, failure: FailureClosure?) {
|
||||
setInfo(.GroupsSetTopic, type: .Topic, channel: channel, text: topic, success: {
|
||||
(topicSet) -> Void in
|
||||
success?(topicSet: topicSet)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - IM
|
||||
public func closeIM(channel: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
|
||||
close(.IMClose, channelID: channel, success: {
|
||||
(closed) -> Void in
|
||||
success?(closed: closed)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func imHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
|
||||
history(.IMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
|
||||
(history) -> Void in
|
||||
success?(history: history)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func imsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
|
||||
list(.IMList, type:ChannelType.IM, excludeArchived: excludeArchived, success: {
|
||||
(channels) -> Void in
|
||||
success?(channels: channels)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func markIM(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
|
||||
mark(.IMMark, channel: channel, timestamp: timestamp, success: {
|
||||
(ts) -> Void in
|
||||
success?(ts: timestamp)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func openIM(userID: String, success: ((imID: String?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters = ["user":userID]
|
||||
networkInterface.request(.IMOpen, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
let group = response["channel"] as? [String: AnyObject]
|
||||
success?(imID: group?["id"] as? String)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - MPIM
|
||||
public func closeMPIM(channel: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
|
||||
close(.MPIMClose, channelID: channel, success: {
|
||||
(closed) -> Void in
|
||||
success?(closed: closed)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func mpimHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
|
||||
history(.MPIMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
|
||||
(history) -> Void in
|
||||
success?(history: history)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func mpimsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
|
||||
list(.MPIMList, type:ChannelType.Group, excludeArchived: excludeArchived, success: {
|
||||
(channels) -> Void in
|
||||
success?(channels: channels)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func markMPIM(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
|
||||
mark(.MPIMMark, channel: channel, timestamp: timestamp, success: {
|
||||
(ts) -> Void in
|
||||
success?(ts: timestamp)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func openMPIM(userIDs: [String], success: ((mpimID: String?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters = ["users":userIDs.joinWithSeparator(",")]
|
||||
networkInterface.request(.MPIMOpen, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
let group = response["group"] as? [String: AnyObject]
|
||||
success?(mpimID: group?["id"] as? String)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Pins
|
||||
public func pinItem(channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((pinned: Bool)->Void)?, failure: FailureClosure?) {
|
||||
pin(.PinsAdd, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: {
|
||||
(ok) -> Void in
|
||||
success?(pinned: ok)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func unpinItem(channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((unpinned: Bool)->Void)?, failure: FailureClosure?) {
|
||||
pin(.PinsRemove, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: {
|
||||
(ok) -> Void in
|
||||
success?(unpinned: ok)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func pin(endpoint: SlackAPIEndpoint, channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["channel":channel, "file":file, "file_comment":fileComment, "timestamp":timestamp]
|
||||
networkInterface.request(endpoint, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ok: true)
|
||||
}){(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Reactions
|
||||
// One of file, file_comment, or the combination of channel and timestamp must be specified.
|
||||
public func addReaction(name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((reacted: Bool)->Void)?, failure: FailureClosure?) {
|
||||
react(.ReactionsAdd, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
|
||||
(ok) -> Void in
|
||||
success?(reacted: ok)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
// One of file, file_comment, or the combination of channel and timestamp must be specified.
|
||||
public func removeReaction(name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((unreacted: Bool)->Void)?, failure: FailureClosure?) {
|
||||
react(.ReactionsRemove, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
|
||||
(ok) -> Void in
|
||||
success?(unreacted: ok)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func react(endpoint: SlackAPIEndpoint, name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["name":name, "file":file, "file_comment":fileComment, "channel":channel, "timestamp":timestamp]
|
||||
networkInterface.request(endpoint, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ok: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Stars
|
||||
// One of file, file_comment, channel, or the combination of channel and timestamp must be specified.
|
||||
public func addStar(file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((starred: Bool)->Void)?, failure: FailureClosure?) {
|
||||
star(.StarsAdd, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
|
||||
(ok) -> Void in
|
||||
success?(starred: ok)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
// One of file, file_comment, channel, or the combination of channel and timestamp must be specified.
|
||||
public func removeStar(file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((unstarred: Bool)->Void)?, failure: FailureClosure?) {
|
||||
star(.StarsRemove, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
|
||||
(ok) -> Void in
|
||||
success?(unstarred: ok)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func star(endpoint: SlackAPIEndpoint, file: String?, fileComment: String?, channel: String?, timestamp: String?, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject?] = ["file":file, "file_comment":fileComment, "channel":channel, "timestamp":timestamp]
|
||||
networkInterface.request(endpoint, token: token, parameters: filterNilParameters(parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ok: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//MARK: - Team
|
||||
public func teamInfo(success: ((info: [String: AnyObject]?)->Void)?, failure: FailureClosure?) {
|
||||
networkInterface.request(.TeamInfo, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(info: response["team"] as? [String: AnyObject])
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Users
|
||||
public func userPresence(user: String, success: ((presence: String?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["user":user]
|
||||
networkInterface.request(.UsersGetPresence, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(presence: response["presence"] as? String)
|
||||
}){(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func userInfo(id: String, success: ((user: User)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["user":id]
|
||||
networkInterface.request(.UsersInfo, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(user: User(user: response["user"] as? [String: AnyObject]))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func usersList(includePresence: Bool = false, success: ((userList: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["presence":includePresence]
|
||||
networkInterface.request(.UsersList, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(userList: response["members"] as? [[String: AnyObject]])
|
||||
}){(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func setUserActive(success: ((success: Bool)->Void)?, failure: FailureClosure?) {
|
||||
networkInterface.request(.UsersSetActive, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(success: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public func setUserPresence(presence: Presence, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["presence":presence.rawValue]
|
||||
networkInterface.request(.UsersSetPresence, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(success:true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Channel Utilities
|
||||
private func close(endpoint: SlackAPIEndpoint, channelID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["channel":channelID]
|
||||
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(closed: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func history(endpoint: SlackAPIEndpoint, id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["channel": id, "latest": latest, "oldest": oldest, "inclusive":inclusive, "count":count, "unreads":unreads]
|
||||
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(history: History(history: response))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func info(endpoint: SlackAPIEndpoint, type: ChannelType, id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["channel": id]
|
||||
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(channel: Channel(channel: response[type.rawValue] as? [String: AnyObject]))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func list(endpoint: SlackAPIEndpoint, type: ChannelType, excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["exclude_archived": excludeArchived]
|
||||
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(channels: response[type.rawValue+"s"] as? [[String: AnyObject]])
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func mark(endpoint: SlackAPIEndpoint, channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["channel": channel, "ts": timestamp]
|
||||
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ts: timestamp)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func setInfo(endpoint: SlackAPIEndpoint, type: InfoType, channel: String, text: String, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: AnyObject] = ["channel": channel, type.rawValue: text]
|
||||
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(success: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Filter Nil Parameters
|
||||
private func filterNilParameters(parameters: [String: AnyObject?]) -> [String: AnyObject] {
|
||||
var finalParameters = [String: AnyObject]()
|
||||
for key in parameters.keys {
|
||||
if parameters[key] != nil {
|
||||
finalParameters[key] = parameters[key]!
|
||||
}
|
||||
}
|
||||
return finalParameters
|
||||
}
|
||||
|
||||
//MARK: - Encode Attachments
|
||||
private func encodeAttachments(attachments: [Attachment?]?) -> NSString? {
|
||||
if let attachments = attachments {
|
||||
var attachmentArray: [[String: AnyObject]] = []
|
||||
for attachment in attachments {
|
||||
if let attachment = attachment {
|
||||
attachmentArray.append(attachment.dictionary())
|
||||
}
|
||||
}
|
||||
do {
|
||||
let data = try NSJSONSerialization.dataWithJSONObject(attachmentArray, options: [])
|
||||
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||
return string
|
||||
} catch _ {
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//MARK: - Enumerate Do Not Disturb Status
|
||||
private func enumerateDNDStatuses(statuses: [String: AnyObject]) -> [String: DoNotDisturbStatus] {
|
||||
var retVal = [String: DoNotDisturbStatus]()
|
||||
for key in statuses.keys {
|
||||
retVal[key] = DoNotDisturbStatus(status: statuses[key] as? [String: AnyObject])
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
//
|
||||
// SlackWebAPIErrorDispatcher.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum SlackError: ErrorType {
|
||||
case AccountInactive
|
||||
case AlreadyArchived
|
||||
case AlreadyInChannel
|
||||
case AlreadyPinned
|
||||
case AlreadyReacted
|
||||
case AlreadyStarred
|
||||
case BadClientSecret
|
||||
case BadRedirectURI
|
||||
case BadTimeStamp
|
||||
case CantArchiveGeneral
|
||||
case CantDelete
|
||||
case CantDeleteFile
|
||||
case CantDeleteMessage
|
||||
case CantInvite
|
||||
case CantInviteSelf
|
||||
case CantKickFromGeneral
|
||||
case CantKickFromLastChannel
|
||||
case CantKickSelf
|
||||
case CantLeaveGeneral
|
||||
case CantLeaveLastChannel
|
||||
case CantUpdateMessage
|
||||
case ChannelNotFound
|
||||
case ComplianceExportsPreventDeletion
|
||||
case EditWindowClosed
|
||||
case FileCommentNotFound
|
||||
case FileDeleted
|
||||
case FileNotFound
|
||||
case FileNotShared
|
||||
case GroupContainsOthers
|
||||
case InvalidArrayArg
|
||||
case InvalidAuth
|
||||
case InvalidChannel
|
||||
case InvalidCharSet
|
||||
case InvalidClientID
|
||||
case InvalidCode
|
||||
case InvalidFormData
|
||||
case InvalidName
|
||||
case InvalidPostType
|
||||
case InvalidPresence
|
||||
case InvalidTS
|
||||
case InvalidTSLatest
|
||||
case InvalidTSOldest
|
||||
case IsArchived
|
||||
case LastMember
|
||||
case LastRAChannel
|
||||
case MessageNotFound
|
||||
case MessageTooLong
|
||||
case MigrationInProgress
|
||||
case MissingDuration
|
||||
case MissingPostType
|
||||
case NameTaken
|
||||
case NoChannel
|
||||
case NoComment
|
||||
case NoItemSpecified
|
||||
case NoReaction
|
||||
case NoText
|
||||
case NotArchived
|
||||
case NotAuthed
|
||||
case NotEnoughUsers
|
||||
case NotInChannel
|
||||
case NotInGroup
|
||||
case NotPinned
|
||||
case NotStarred
|
||||
case OverPaginationLimit
|
||||
case PaidOnly
|
||||
case PermissionDenied
|
||||
case PostingToGeneralChannelDenied
|
||||
case RateLimited
|
||||
case RequestTimeout
|
||||
case RestrictedAction
|
||||
case SnoozeEndFailed
|
||||
case SnoozeFailed
|
||||
case SnoozeNotActive
|
||||
case TooLong
|
||||
case TooManyEmoji
|
||||
case TooManyReactions
|
||||
case TooManyUsers
|
||||
case UnknownError
|
||||
case UnknownType
|
||||
case UserDisabled
|
||||
case UserDoesNotOwnChannel
|
||||
case UserIsBot
|
||||
case UserIsRestricted
|
||||
case UserIsUltraRestricted
|
||||
case UserListNotSupplied
|
||||
case UserNotFound
|
||||
case UserNotVisible
|
||||
// Client
|
||||
case ClientNetworkError
|
||||
case ClientJSONError
|
||||
// HTTP
|
||||
case TooManyRequests
|
||||
case UnknownHTTPError
|
||||
}
|
||||
|
||||
internal struct ErrorDispatcher {
|
||||
|
||||
static func dispatch(error: String) -> SlackError {
|
||||
switch error {
|
||||
case "account_inactive":
|
||||
return .AccountInactive
|
||||
case "already_in_channel":
|
||||
return .AlreadyInChannel
|
||||
case "already_pinned":
|
||||
return .AlreadyPinned
|
||||
case "already_reacted":
|
||||
return .AlreadyReacted
|
||||
case "already_starred":
|
||||
return .AlreadyStarred
|
||||
case "bad_client_secret":
|
||||
return .BadClientSecret
|
||||
case "bad_redirect_uri":
|
||||
return .BadRedirectURI
|
||||
case "bad_timestamp":
|
||||
return .BadTimeStamp
|
||||
case "cant_delete":
|
||||
return .CantDelete
|
||||
case "cant_delete_file":
|
||||
return .CantDeleteFile
|
||||
case "cant_delete_message":
|
||||
return .CantDeleteMessage
|
||||
case "cant_invite":
|
||||
return .CantInvite
|
||||
case "cant_invite_self":
|
||||
return .CantInviteSelf
|
||||
case "cant_kick_from_general":
|
||||
return .CantKickFromGeneral
|
||||
case "cant_kick_from_last_channel":
|
||||
return .CantKickFromLastChannel
|
||||
case "cant_kick_self":
|
||||
return .CantKickSelf
|
||||
case "cant_leave_general":
|
||||
return .CantLeaveGeneral
|
||||
case "cant_leave_last_channel":
|
||||
return .CantLeaveLastChannel
|
||||
case "cant_update_message":
|
||||
return .CantUpdateMessage
|
||||
case "compliance_exports_prevent_deletion":
|
||||
return .ComplianceExportsPreventDeletion
|
||||
case "channel_not_found":
|
||||
return .ChannelNotFound
|
||||
case "edit_window_closed":
|
||||
return .EditWindowClosed
|
||||
case "file_comment_not_found":
|
||||
return .FileCommentNotFound
|
||||
case "file_deleted":
|
||||
return .FileDeleted
|
||||
case "file_not_found":
|
||||
return .FileNotFound
|
||||
case "file_not_shared":
|
||||
return .FileNotShared
|
||||
case "group_contains_others":
|
||||
return .GroupContainsOthers
|
||||
case "invalid_array_arg":
|
||||
return .InvalidArrayArg
|
||||
case "invalid_auth":
|
||||
return .InvalidAuth
|
||||
case "invalid_channel":
|
||||
return .InvalidChannel
|
||||
case "invalid_charset":
|
||||
return .InvalidCharSet
|
||||
case "invalid_client_id":
|
||||
return .InvalidClientID
|
||||
case "invalid_code":
|
||||
return .InvalidCode
|
||||
case "invalid_form_data":
|
||||
return .InvalidFormData
|
||||
case "invalid_name":
|
||||
return .InvalidName
|
||||
case "invalid_post_type":
|
||||
return .InvalidPostType
|
||||
case "invalid_presence":
|
||||
return .InvalidPresence
|
||||
case "invalid_timestamp":
|
||||
return .InvalidTS
|
||||
case "invalid_ts_latest":
|
||||
return .InvalidTSLatest
|
||||
case "invalid_ts_oldest":
|
||||
return .InvalidTSOldest
|
||||
case "is_archived":
|
||||
return .IsArchived
|
||||
case "last_member":
|
||||
return .LastMember
|
||||
case "last_ra_channel":
|
||||
return .LastRAChannel
|
||||
case "message_not_found":
|
||||
return .MessageNotFound
|
||||
case "msg_too_long":
|
||||
return .MessageTooLong
|
||||
case "migration_in_progress":
|
||||
return .MigrationInProgress
|
||||
case "missing_duration":
|
||||
return .MissingDuration
|
||||
case "missing_post_type":
|
||||
return .MissingPostType
|
||||
case "name_taken":
|
||||
return .NameTaken
|
||||
case "no_channel":
|
||||
return .NoChannel
|
||||
case "no_comment":
|
||||
return .NoComment
|
||||
case "no_reaction":
|
||||
return .NoReaction
|
||||
case "no_item_specified":
|
||||
return .NoItemSpecified
|
||||
case "no_text":
|
||||
return .NoText
|
||||
case "not_archived":
|
||||
return .NotArchived
|
||||
case "not_authed":
|
||||
return .NotAuthed
|
||||
case "not_enough_users":
|
||||
return .NotEnoughUsers
|
||||
case "not_in_channel":
|
||||
return .NotInChannel
|
||||
case "not_in_group":
|
||||
return .NotInGroup
|
||||
case "not_pinned":
|
||||
return .NotPinned
|
||||
case "not_starred":
|
||||
return .NotStarred
|
||||
case "over_pagination_limit":
|
||||
return .OverPaginationLimit
|
||||
case "paid_only":
|
||||
return .PaidOnly
|
||||
case "perimssion_denied":
|
||||
return .PermissionDenied
|
||||
case "posting_to_general_channel_denied":
|
||||
return .PostingToGeneralChannelDenied
|
||||
case "rate_limited":
|
||||
return .RateLimited
|
||||
case "request_timeout":
|
||||
return .RequestTimeout
|
||||
case "snooze_end_failed":
|
||||
return .SnoozeEndFailed
|
||||
case "snooze_failed":
|
||||
return .SnoozeFailed
|
||||
case "snooze_not_active":
|
||||
return .SnoozeNotActive
|
||||
case "too_long":
|
||||
return .TooLong
|
||||
case "too_many_emoji":
|
||||
return .TooManyEmoji
|
||||
case "too_many_reactions":
|
||||
return .TooManyReactions
|
||||
case "too_many_users":
|
||||
return .TooManyUsers
|
||||
case "unknown_type":
|
||||
return .UnknownType
|
||||
case "user_disabled":
|
||||
return .UserDisabled
|
||||
case "user_does_not_own_channel":
|
||||
return .UserDoesNotOwnChannel
|
||||
case "user_is_bot":
|
||||
return .UserIsBot
|
||||
case "user_is_restricted":
|
||||
return .UserIsRestricted
|
||||
case "user_is_ultra_restricted":
|
||||
return .UserIsUltraRestricted
|
||||
case "user_list_not_supplied":
|
||||
return .UserListNotSupplied
|
||||
case "user_not_found":
|
||||
return .UserNotFound
|
||||
case "user_not_visible":
|
||||
return .UserNotVisible
|
||||
default:
|
||||
return .UnknownError
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// Team.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public struct Team {
|
||||
|
||||
public let id: String
|
||||
internal(set) public var name: String?
|
||||
internal(set) public var domain: String?
|
||||
internal(set) public var emailDomain: String?
|
||||
internal(set) public var messageEditWindowMinutes: Int?
|
||||
internal(set) public var overStorageLimit: Bool?
|
||||
internal(set) public var prefs: [String: AnyObject]?
|
||||
internal(set) public var plan: String?
|
||||
internal(set) public var icon: TeamIcon?
|
||||
|
||||
internal init(team: [String: AnyObject]?) {
|
||||
id = team?["id"] as! String
|
||||
name = team?["name"] as? String
|
||||
domain = team?["domain"] as? String
|
||||
emailDomain = team?["email_domain"] as? String
|
||||
messageEditWindowMinutes = team?["msg_edit_window_mins"] as? Int
|
||||
overStorageLimit = team?["over_storage_limit"] as? Bool
|
||||
prefs = team?["prefs"] as? [String: AnyObject]
|
||||
plan = team?["plan"] as? String
|
||||
icon = TeamIcon(icon: team?["icon"] as? [String: AnyObject])
|
||||
}
|
||||
}
|
||||
|
||||
public struct TeamIcon {
|
||||
internal(set) public var image34: String?
|
||||
internal(set) public var image44: String?
|
||||
internal(set) public var image68: String?
|
||||
internal(set) public var image88: String?
|
||||
internal(set) public var image102: String?
|
||||
internal(set) public var image132: String?
|
||||
internal(set) public var imageOriginal: String?
|
||||
internal(set) public var imageDefault: Bool?
|
||||
|
||||
internal init(icon: [String: AnyObject]?) {
|
||||
image34 = icon?["image_34"] as? String
|
||||
image44 = icon?["image_44"] as? String
|
||||
image68 = icon?["image_68"] as? String
|
||||
image88 = icon?["image_88"] as? String
|
||||
image102 = icon?["image_102"] as? String
|
||||
image132 = icon?["image_132"] as? String
|
||||
imageOriginal = icon?["image_original"] as? String
|
||||
imageDefault = icon?["image_default"] as? Bool
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
//
|
||||
// Types.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
// MARK: - Edited
|
||||
public struct Edited {
|
||||
public let user: String?
|
||||
public let ts: String?
|
||||
|
||||
internal init(edited:[String: AnyObject]?) {
|
||||
user = edited?["user"] as? String
|
||||
ts = edited?["ts"] as? String
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - History
|
||||
public struct History {
|
||||
internal(set) public var latest: NSDate?
|
||||
internal(set) public var messages = [Message]()
|
||||
public let hasMore: Bool?
|
||||
|
||||
internal init(history: [String: AnyObject]?) {
|
||||
if let latestStr = history?["latest"] as? String, latestDouble = Double(latestStr) {
|
||||
latest = NSDate(timeIntervalSince1970: NSTimeInterval(latestDouble))
|
||||
}
|
||||
if let msgs = history?["messages"] as? [[String: AnyObject]] {
|
||||
for message in msgs {
|
||||
messages.append(Message(message: message))
|
||||
}
|
||||
}
|
||||
hasMore = history?["has_more"] as? Bool
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Reaction
|
||||
public struct Reaction {
|
||||
public let name: String?
|
||||
internal(set) public var user: String?
|
||||
|
||||
internal init(reaction:[String: AnyObject]?) {
|
||||
name = reaction?["name"] as? String
|
||||
}
|
||||
|
||||
internal init(name: String, user: String) {
|
||||
self.name = name
|
||||
self.user = user
|
||||
}
|
||||
|
||||
static func reactionsFromArray(array: [[String: AnyObject]]?) -> [Reaction] {
|
||||
var reactions = [Reaction]()
|
||||
if let array = array {
|
||||
for reaction in array {
|
||||
if let users = reaction["users"] as? [String], name = reaction["name"] as? String {
|
||||
for user in users {
|
||||
reactions.append(Reaction(name: name, user: user))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reactions
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reaction: Equatable {}
|
||||
|
||||
public func ==(lhs: Reaction, rhs: Reaction) -> Bool {
|
||||
return lhs.name == rhs.name
|
||||
}
|
||||
|
||||
// MARK: - Comment
|
||||
public struct Comment {
|
||||
public let id: String?
|
||||
public let user: String?
|
||||
internal(set) public var created: Int?
|
||||
internal(set) public var comment: String?
|
||||
internal(set) public var starred: Bool?
|
||||
internal(set) public var stars: Int?
|
||||
internal(set) public var reactions = [Reaction]()
|
||||
|
||||
internal init(comment:[String: AnyObject]?) {
|
||||
id = comment?["id"] as? String
|
||||
created = comment?["created"] as? Int
|
||||
user = comment?["user"] as? String
|
||||
starred = comment?["is_starred"] as? Bool
|
||||
stars = comment?["num_stars"] as? Int
|
||||
self.comment = comment?["comment"] as? String
|
||||
}
|
||||
|
||||
internal init(id: String?) {
|
||||
self.id = id
|
||||
self.user = nil
|
||||
}
|
||||
}
|
||||
|
||||
extension Comment: Equatable {}
|
||||
|
||||
public func ==(lhs: Comment, rhs: Comment) -> Bool {
|
||||
return lhs.id == rhs.id
|
||||
}
|
||||
|
||||
// MARK: - Item
|
||||
public struct Item {
|
||||
public let type: String?
|
||||
public let ts: String?
|
||||
public let channel: String?
|
||||
public let message: Message?
|
||||
public let file: File?
|
||||
public let comment: Comment?
|
||||
public let fileCommentID: String?
|
||||
|
||||
internal init(item:[String: AnyObject]?) {
|
||||
type = item?["type"] as? String
|
||||
ts = item?["ts"] as? String
|
||||
channel = item?["channel"] as? String
|
||||
|
||||
message = Message(message: item?["message"] as? [String: AnyObject])
|
||||
|
||||
// Comment and File can come across as Strings or Dictionaries
|
||||
if let commentDictionary = item?["comment"] as? [String: AnyObject] {
|
||||
comment = Comment(comment: commentDictionary)
|
||||
} else {
|
||||
comment = Comment(id: item?["comment"] as? String)
|
||||
}
|
||||
|
||||
if let fileDictionary = item?["file"] as? [String: AnyObject] {
|
||||
file = File(file: fileDictionary)
|
||||
} else {
|
||||
file = File(id: item?["file"] as? String)
|
||||
}
|
||||
|
||||
fileCommentID = item?["file_comment"] as? String
|
||||
}
|
||||
}
|
||||
|
||||
extension Item: Equatable {}
|
||||
|
||||
public func ==(lhs: Item, rhs: Item) -> Bool {
|
||||
return lhs.type == rhs.type && lhs.channel == rhs.channel && lhs.file == rhs.file && lhs.comment == rhs.comment && lhs.message == rhs.message
|
||||
}
|
||||
|
||||
// MARK: - Topic
|
||||
public struct Topic {
|
||||
public let value: String?
|
||||
public let creator: String?
|
||||
public let lastSet: Int?
|
||||
|
||||
internal init(topic: [String: AnyObject]?) {
|
||||
value = topic?["value"] as? String
|
||||
creator = topic?["creator"] as? String
|
||||
lastSet = topic?["last_set"] as? Int
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Do Not Disturb Status
|
||||
public struct DoNotDisturbStatus {
|
||||
internal(set) public var enabled: Bool?
|
||||
internal(set) public var nextDoNotDisturbStart: Int?
|
||||
internal(set) public var nextDoNotDisturbEnd: Int?
|
||||
internal(set) public var snoozeEnabled: Bool?
|
||||
internal(set) public var snoozeEndtime: Int?
|
||||
|
||||
internal init(status: [String: AnyObject]?) {
|
||||
enabled = status?["dnd_enabled"] as? Bool
|
||||
nextDoNotDisturbStart = status?["next_dnd_start_ts"] as? Int
|
||||
nextDoNotDisturbEnd = status?["next_dnd_end_ts"] as? Int
|
||||
snoozeEnabled = status?["snooze_enabled"] as? Bool
|
||||
snoozeEndtime = status?["snooze_endtime"] as? Int
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK - Custom Team Profile
|
||||
public struct CustomProfile {
|
||||
internal(set) public var fields = [String: CustomProfileField]()
|
||||
|
||||
internal init(profile: [String: AnyObject]?) {
|
||||
if let eventFields = profile?["fields"] as? [AnyObject] {
|
||||
for field in eventFields {
|
||||
var cpf: CustomProfileField?
|
||||
if let fieldDictionary = field as? [String: AnyObject] {
|
||||
cpf = CustomProfileField(field: fieldDictionary)
|
||||
} else {
|
||||
cpf = CustomProfileField(id: field as? String)
|
||||
}
|
||||
if let id = cpf?.id { fields[id] = cpf }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal init(customFields: [String: AnyObject]?) {
|
||||
if let customFields = customFields {
|
||||
for key in customFields.keys {
|
||||
let cpf = CustomProfileField(field: customFields[key] as? [String: AnyObject])
|
||||
self.fields[key] = cpf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct CustomProfileField {
|
||||
internal(set) public var id: String?
|
||||
internal(set) public var alt: String?
|
||||
internal(set) public var value: String?
|
||||
internal(set) public var hidden: Bool?
|
||||
internal(set) public var hint: String?
|
||||
internal(set) public var label: String?
|
||||
internal(set) public var options: String?
|
||||
internal(set) public var ordering: Int?
|
||||
internal(set) public var possibleValues: [String]?
|
||||
internal(set) public var type: String?
|
||||
|
||||
internal init(field: [String: AnyObject]?) {
|
||||
id = field?["id"] as? String
|
||||
alt = field?["alt"] as? String
|
||||
value = field?["value"] as? String
|
||||
hidden = field?["is_hidden"] as? Bool
|
||||
hint = field?["hint"] as? String
|
||||
label = field?["label"] as? String
|
||||
options = field?["options"] as? String
|
||||
ordering = field?["ordering"] as? Int
|
||||
possibleValues = field?["possible_values"] as? [String]
|
||||
type = field?["type"] as? String
|
||||
}
|
||||
|
||||
internal init(id: String?) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
internal mutating func updateProfileField(profile: CustomProfileField?) {
|
||||
id = profile?.id != nil ? profile?.id : id
|
||||
alt = profile?.alt != nil ? profile?.alt : alt
|
||||
value = profile?.value != nil ? profile?.value : value
|
||||
hidden = profile?.hidden != nil ? profile?.hidden : hidden
|
||||
hint = profile?.hint != nil ? profile?.hint : hint
|
||||
label = profile?.label != nil ? profile?.label : label
|
||||
options = profile?.options != nil ? profile?.options : options
|
||||
ordering = profile?.ordering != nil ? profile?.ordering : ordering
|
||||
possibleValues = profile?.possibleValues != nil ? profile?.possibleValues : possibleValues
|
||||
type = profile?.type != nil ? profile?.type : type
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
//
|
||||
// User.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public struct User {
|
||||
|
||||
public struct Profile {
|
||||
internal(set) public var firstName: String?
|
||||
internal(set) public var lastName: String?
|
||||
internal(set) public var realName: String?
|
||||
internal(set) public var email: String?
|
||||
internal(set) public var skype: String?
|
||||
internal(set) public var phone: String?
|
||||
internal(set) public var image24: String?
|
||||
internal(set) public var image32: String?
|
||||
internal(set) public var image48: String?
|
||||
internal(set) public var image72: String?
|
||||
internal(set) public var image192: String?
|
||||
internal(set) public var customProfile: CustomProfile?
|
||||
|
||||
internal init(profile: [String: AnyObject]?) {
|
||||
firstName = profile?["first_name"] as? String
|
||||
lastName = profile?["last_name"] as? String
|
||||
realName = profile?["real_name"] as? String
|
||||
email = profile?["email"] as? String
|
||||
skype = profile?["skype"] as? String
|
||||
phone = profile?["phone"] as? String
|
||||
image24 = profile?["image_24"] as? String
|
||||
image32 = profile?["image_32"] as? String
|
||||
image48 = profile?["image_48"] as? String
|
||||
image72 = profile?["image_72"] as? String
|
||||
image192 = profile?["image_192"] as? String
|
||||
customProfile = CustomProfile(customFields: profile?["fields"] as? [String: AnyObject])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public let id: String?
|
||||
internal(set) public var name: String?
|
||||
internal(set) public var deleted: Bool?
|
||||
internal(set) public var profile: Profile?
|
||||
internal(set) public var doNotDisturbStatus: DoNotDisturbStatus?
|
||||
internal(set) public var presence: String?
|
||||
internal(set) public var color: String?
|
||||
public let isBot: Bool?
|
||||
internal(set) public var isAdmin: Bool?
|
||||
internal(set) public var isOwner: Bool?
|
||||
internal(set) public var isPrimaryOwner: Bool?
|
||||
internal(set) public var isRestricted: Bool?
|
||||
internal(set) public var isUltraRestricted: Bool?
|
||||
internal(set) public var has2fa: Bool?
|
||||
internal(set) public var hasFiles: Bool?
|
||||
internal(set) public var status: String?
|
||||
internal(set) public var timeZone: String?
|
||||
internal(set) public var timeZoneLabel: String?
|
||||
internal(set) public var timeZoneOffSet: Int?
|
||||
internal(set) public var preferences: [String: AnyObject]?
|
||||
// Client properties
|
||||
internal(set) public var userGroups: [String: String]?
|
||||
|
||||
internal init(user: [String: AnyObject]?) {
|
||||
id = user?["id"] as? String
|
||||
name = user?["name"] as? String
|
||||
deleted = user?["deleted"] as? Bool
|
||||
profile = Profile(profile: user?["profile"] as? [String: AnyObject])
|
||||
color = user?["color"] as? String
|
||||
isAdmin = user?["is_admin"] as? Bool
|
||||
isOwner = user?["is_owner"] as? Bool
|
||||
isPrimaryOwner = user?["is_primary_owner"] as? Bool
|
||||
isRestricted = user?["is_restricted"] as? Bool
|
||||
isUltraRestricted = user?["is_ultra_restricted"] as? Bool
|
||||
has2fa = user?["has_2fa"] as? Bool
|
||||
hasFiles = user?["has_files"] as? Bool
|
||||
isBot = user?["is_bot"] as? Bool
|
||||
presence = user?["presence"] as? String
|
||||
status = user?["status"] as? String
|
||||
timeZone = user?["tz"] as? String
|
||||
timeZoneLabel = user?["tz_label"] as? String
|
||||
timeZoneOffSet = user?["tz_offset"] as? Int
|
||||
preferences = user?["prefs"] as? [String: AnyObject]
|
||||
}
|
||||
|
||||
internal init(id: String?) {
|
||||
self.id = id
|
||||
self.isBot = nil
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// UserGroup.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
|
||||
public struct UserGroup {
|
||||
|
||||
public let id: String?
|
||||
|
||||
internal(set) public var teamID: String?
|
||||
public let isUserGroup: Bool?
|
||||
internal(set) public var name: String?
|
||||
internal(set) public var description: String?
|
||||
internal(set) public var handle: String?
|
||||
internal(set) public var isExternal: Bool?
|
||||
public let dateCreated: Int?
|
||||
internal(set) public var dateUpdated: Int?
|
||||
internal(set) public var dateDeleted: Int?
|
||||
internal(set) public var autoType: String?
|
||||
public let createdBy: String?
|
||||
internal(set) public var updatedBy: String?
|
||||
internal(set) public var deletedBy: String?
|
||||
internal(set) public var preferences: [String: AnyObject]?
|
||||
internal(set) public var users: [String]?
|
||||
internal(set) public var userCount: Int?
|
||||
|
||||
internal init(userGroup: [String: AnyObject]?) {
|
||||
id = userGroup?["id"] as? String
|
||||
teamID = userGroup?["team_id"] as? String
|
||||
isUserGroup = userGroup?["is_usergroup"] as? Bool
|
||||
name = userGroup?["name"] as? String
|
||||
description = userGroup?["description"] as? String
|
||||
handle = userGroup?["handle"] as? String
|
||||
isExternal = userGroup?["is_external"] as? Bool
|
||||
dateCreated = userGroup?["date_create"] as? Int
|
||||
dateUpdated = userGroup?["date_update"] as? Int
|
||||
dateDeleted = userGroup?["date_delete"] as? Int
|
||||
autoType = userGroup?["auto_type"] as? String
|
||||
createdBy = userGroup?["created_by"] as? String
|
||||
updatedBy = userGroup?["updated_by"] as? String
|
||||
deletedBy = userGroup?["deleted_by"] as? String
|
||||
preferences = userGroup?["prefs"] as? [String: AnyObject]
|
||||
users = userGroup?["users"] as? [String]
|
||||
if let count = userGroup?["user_count"] as? String {
|
||||
userCount = Int(count)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Peter Zignego. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Peter Zignego. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// ClientConnection.swift
|
||||
// SlackKit
|
||||
//
|
||||
// Created by Emory Dunn on 12/28/17.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class ClientConnection {
|
||||
public var client: Client?
|
||||
public var rtm: SKRTMAPI?
|
||||
public var webAPI: WebAPI?
|
||||
|
||||
public init(client: Client?, rtm: SKRTMAPI?, webAPI: WebAPI?) {
|
||||
self.client = client
|
||||
self.rtm = rtm
|
||||
self.webAPI = webAPI
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// SlackKit.swift
|
||||
//
|
||||
// Copyright © 2017 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
@_exported import SKClient
|
||||
@_exported import SKCore
|
||||
@_exported import SKRTMAPI
|
||||
@_exported import SKServer
|
||||
@_exported import SKWebAPI
|
||||
|
||||
public final class SlackKit: RTMAdapter {
|
||||
|
||||
public typealias EventClosure = (Event, ClientConnection?) -> Void
|
||||
internal typealias TypedEvent = (EventType, EventClosure)
|
||||
internal var callbacks = [TypedEvent]()
|
||||
internal(set) public var server: SKServer?
|
||||
internal(set) public var clients: [String: ClientConnection] = [:]
|
||||
|
||||
/// Return the `SKRTMAPI` instance of the first client
|
||||
public var rtm: SKRTMAPI? {
|
||||
return clients.values.first?.rtm
|
||||
}
|
||||
/// Return the `WebAPI` instance of the first client
|
||||
public var webAPI: WebAPI? {
|
||||
return clients.values.first?.webAPI
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
public func addWebAPIAccessWithToken(_ token: String) {
|
||||
let webAPI = WebAPI(token: token)
|
||||
if let clientConnection = clients[token] {
|
||||
clientConnection.webAPI = webAPI
|
||||
} else {
|
||||
clients[token] = ClientConnection(client: nil, rtm: nil, webAPI: webAPI)
|
||||
}
|
||||
}
|
||||
|
||||
public func addRTMBotWithAPIToken(
|
||||
_ token: String,
|
||||
client: Client? = Client(),
|
||||
options: RTMOptions = RTMOptions(),
|
||||
rtm: RTMWebSocket? = nil
|
||||
) {
|
||||
let rtm = SKRTMAPI(withAPIToken: token, options: options, rtm: rtm)
|
||||
rtm.adapter = self
|
||||
|
||||
if let clientConnection = clients[token] {
|
||||
clientConnection.rtm = rtm
|
||||
} else {
|
||||
clients[token] = ClientConnection(client: client, rtm: rtm, webAPI: nil)
|
||||
}
|
||||
clients[token]?.rtm?.connect()
|
||||
}
|
||||
|
||||
public func addServer(_ server: SlackKitServer? = nil, responder: SlackKitResponder? = nil, oauth: OAuthConfig? = nil) {
|
||||
var responder: SlackKitResponder = responder ?? SlackKitResponder(routes: [])
|
||||
if let oauth = oauth {
|
||||
responder.routes.append(oauthRequestRoute(config: oauth))
|
||||
}
|
||||
self.server = SKServer(server: server, responder: responder)
|
||||
self.server?.start()
|
||||
}
|
||||
|
||||
private func oauthRequestRoute(config: OAuthConfig) -> RequestRoute {
|
||||
let oauth = OAuthMiddleware(config: config) { authorization in
|
||||
// User
|
||||
if let token = authorization.accessToken {
|
||||
self.addWebAPIAccessWithToken(token)
|
||||
}
|
||||
// Bot User
|
||||
if let token = authorization.bot?.botToken {
|
||||
self.addRTMBotWithAPIToken(token)
|
||||
}
|
||||
}
|
||||
return RequestRoute(path: "/oauth", middleware: oauth)
|
||||
}
|
||||
|
||||
// MARK: - RTM Adapter
|
||||
public func initialSetup(json: [String: Any], instance: SKRTMAPI) {
|
||||
clients[instance.token]?.client?.initialSetup(JSON: json)
|
||||
}
|
||||
|
||||
public func notificationForEvent(_ event: Event, type: EventType, instance: SKRTMAPI) {
|
||||
let clientConnection = clients[instance.token]
|
||||
clientConnection?.client?.notificationForEvent(event, type: type)
|
||||
executeCallbackForEvent(event, type: type, clientConnection: clientConnection)
|
||||
}
|
||||
|
||||
public func connectionClosed(with error: Error, instance: SKRTMAPI) {}
|
||||
|
||||
// MARK: - Callbacks
|
||||
public func notificationForEvent(_ type: EventType, event: @escaping EventClosure) {
|
||||
callbacks.append((type, event))
|
||||
}
|
||||
|
||||
private func executeCallbackForEvent(_ event: Event, type: EventType, clientConnection: ClientConnection?) {
|
||||
let cbs = callbacks.filter {$0.0 == type}
|
||||
for callback in cbs {
|
||||
callback.1(event, clientConnection)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,11 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<string>4.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Peter Zignego. All rights reserved.</string>
|
||||
<string>Copyright © 2017 Peter Zignego. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
Reference in New Issue
Block a user