diff --git a/Cartfile b/Cartfile index c598467..0721639 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "SlackKit/SKCore" >= 4.0.0 \ No newline at end of file +github "SlackKit/SKCore" >= 4.1.0 \ No newline at end of file diff --git a/Package.swift b/Package.swift index ba6cfc8..724f1a2 100644 --- a/Package.swift +++ b/Package.swift @@ -1,11 +1,17 @@ +// swift-tools-version:4.0 import PackageDescription let package = Package( name: "SKWebAPI", - targets: [ - Target(name: "SKWebAPI") + products: [ + .library(name: "SKWebAPI", targets: ["SKWebAPI"]) ], dependencies: [ - .Package(url: "https://github.com/SlackKit/SKCore", majorVersion: 4) + .package(url: "https://github.com/SlackKit/SKCore", .upToNextMinor(from: "4.1.0")) + ], + targets: [ + .target(name: "SKWebAPI", + dependencies: ["SKCore"], + path: "Sources") ] ) diff --git a/Podfile b/Podfile index 97fe024..d1eac50 100644 --- a/Podfile +++ b/Podfile @@ -2,15 +2,15 @@ use_frameworks! target 'SKWebAPI macOS' do platform :osx, '10.11' - pod 'SKCore' + pod 'SKCore', '~> 4.1.0' end target 'SKWebAPI iOS' do platform :ios, '9.0' - pod 'SKCore' + pod 'SKCore', '~> 4.1.0' end target 'SKWebAPI tvOS' do platform :tvos, '9.0' - pod 'SKCore' + pod 'SKCore', '~> 4.1.0' end diff --git a/README.md b/README.md index cbf1a03..75fc9c3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # SKWebAPI: SlackKit Web API Module -![Swift Version](https://img.shields.io/badge/Swift-3.1.1-orange.svg) +![Swift Version](https://img.shields.io/badge/Swift-4.0.3-orange.svg) ![Plaforms](https://img.shields.io/badge/Platforms-macOS,iOS,tvOS,Linux-lightgrey.svg) ![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg) [![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) @@ -21,7 +21,7 @@ pod 'SKWebAPI' and run ``` -# Use CocoaPods version >= 1.1.0 +# Use CocoaPods version >= 1.4.0 pod install ``` @@ -49,7 +49,7 @@ import PackageDescription let package = Package( dependencies: [ - .Package(url: "https://github.com/SlackKit/SKWebAPI.git", majorVersion: 4) + .package(url: "https://github.com/SlackKit/SKWebAPI.git", .upToNextMinor(from: "4.1.0")) ] ) ``` diff --git a/SKWebAPI.podspec b/SKWebAPI.podspec index 4d2f843..6e0fc04 100644 --- a/SKWebAPI.podspec +++ b/SKWebAPI.podspec @@ -1,17 +1,18 @@ Pod::Spec.new do |s| - s.name = "SKWebAPI" - s.version = "4.0.7" - s.summary = "A Swift library to help make requests to the Slack Web API" - s.homepage = "https://github.com/SlackKit/SKWebAPI" - s.license = 'MIT' - s.author = { "Peter Zignego" => "peter@launchsoft.co" } - s.source = { :git => "https://github.com/SlackKit/SKWebAPI.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.name = "SKWebAPI" + s.version = "4.1.0" + s.summary = "A Swift library to help make requests to the Slack Web API" + s.homepage = "https://github.com/SlackKit/SKWebAPI" + s.license = 'MIT' + s.author = { "Peter Zignego" => "peter@launchsoft.co" } + s.source = { :git => "https://github.com/SlackKit/SKWebAPI.git", :tag => s.version.to_s } + s.social_media_url = 'https://twitter.com/pvzig' + s.swift_version = '4.0' + 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' end diff --git a/SKWebAPI.xcodeproj/project.pbxproj b/SKWebAPI.xcodeproj/project.pbxproj index f523ee3..d2d997b 100644 --- a/SKWebAPI.xcodeproj/project.pbxproj +++ b/SKWebAPI.xcodeproj/project.pbxproj @@ -209,7 +209,7 @@ 2684F1741E95AA6900536DCC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = "Peter Zignego"; TargetAttributes = { 2684F17C1E95AA6900536DCC = { @@ -356,7 +356,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -364,7 +366,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -409,7 +415,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -417,7 +425,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -467,7 +479,7 @@ PRODUCT_NAME = SKWebAPI; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -494,7 +506,7 @@ PRODUCT_NAME = SKWebAPI; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -521,7 +533,7 @@ PRODUCT_NAME = SKWebAPI; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -548,7 +560,7 @@ PRODUCT_NAME = SKWebAPI; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -574,7 +586,7 @@ PRODUCT_NAME = SKWebAPI; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -601,7 +613,7 @@ PRODUCT_NAME = SKWebAPI; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; diff --git a/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI iOS.xcscheme b/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI iOS.xcscheme index b1a001b..266a238 100644 --- a/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI iOS.xcscheme +++ b/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI iOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI macOS.xcscheme b/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI macOS.xcscheme index 4c8e767..5882dcd 100644 --- a/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI macOS.xcscheme +++ b/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI macOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI tvOS.xcscheme b/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI tvOS.xcscheme index f82da0f..d9afc61 100644 --- a/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI tvOS.xcscheme +++ b/SKWebAPI.xcodeproj/xcshareddata/xcschemes/SKWebAPI tvOS.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Sources/Endpoint.swift b/Sources/Endpoint.swift index 495765c..1a6f0bf 100644 --- a/Sources/Endpoint.swift +++ b/Sources/Endpoint.swift @@ -65,6 +65,7 @@ public enum Endpoint: String { case mpimMark = "mpim.mark" case mpimOpen = "mpim.open" case oauthAccess = "oauth.access" + case pinsList = "pins.list" case pinsAdd = "pins.add" case pinsRemove = "pins.remove" case reactionsAdd = "reactions.add" diff --git a/Sources/NetworkInterface.swift b/Sources/NetworkInterface.swift index 7af1fe0..50658a9 100644 --- a/Sources/NetworkInterface.swift +++ b/Sources/NetworkInterface.swift @@ -169,7 +169,7 @@ public struct NetworkInterface { if parameters.count > 0 { components?.queryItems = filterNilParameters(parameters).map { URLQueryItem(name: $0.0, value: "\($0.1)") } } - + // As discussed http://www.openradar.me/24076063 and https://stackoverflow.com/a/37314144/407523, Apple considers // a + and ? as valid characters in a URL query string, but Slack has recently started enforcing that they be // encoded when included in a query string. As a result, we need to manually apply the encoding after Apple's @@ -178,10 +178,10 @@ public struct NetworkInterface { encodedQuery = encodedQuery?.replacingOccurrences(of: "?", with: "%3F") encodedQuery = encodedQuery?.replacingOccurrences(of: "+", with: "%2B") components?.percentEncodedQuery = encodedQuery - + return components?.url } - + private func requestBodyData(data: Data, boundaryConstant: String, filename: String, filetype: String) -> Data? { let boundaryStart = "--\(boundaryConstant)\r\n" let boundaryEnd = "--\(boundaryConstant)--\r\n" diff --git a/Sources/WebAPI.swift b/Sources/WebAPI.swift index 1f24dbb..695fa29 100644 --- a/Sources/WebAPI.swift +++ b/Sources/WebAPI.swift @@ -34,6 +34,7 @@ public final class WebAPI { public typealias MessageClosure = (_ message: Message) -> Void public typealias HistoryClosure = (_ history: History) -> Void public typealias FileClosure = (_ file: File) -> Void + public typealias ItemsClosure = (_ items: [Item]?) -> Void public enum InfoType: String { case purpose, topic @@ -199,8 +200,8 @@ extension WebAPI { create(.channelsCreate, name: channel, success: success, failure: failure) } - public func inviteToChannel(_ channelID: String, userID: String, success: SuccessClosure?, failure: FailureClosure?) { - invite(.channelsInvite, channelID: channelID, userID: userID, success: success, failure: failure) + public func inviteToChannel(_ channel: String, user: String, success: SuccessClosure?, failure: FailureClosure?) { + invite(.channelsInvite, channel: channel, user: user, success: success, failure: failure) } public func setChannelPurpose(channel: String, purpose: String, success: SuccessClosure?, failure: FailureClosure?) { @@ -234,6 +235,7 @@ extension WebAPI { public func sendMessage( channel: String, text: String, + escapeCharacters: Bool = true, username: String? = nil, asUser: Bool? = nil, parse: ParseMode? = nil, @@ -249,7 +251,7 @@ extension WebAPI { let parameters: [String: Any?] = [ "token": token, "channel": channel, - "text": text.slackFormatEscaping, + "text": escapeCharacters ? text.slackFormatEscaping : text, "as_user": asUser, "parse": parse?.rawValue, "link_names": linkNames, @@ -271,6 +273,7 @@ extension WebAPI { channel: String, thread: String, text: String, + escapeCharacters: Bool = true, broadcastReply: Bool = false, username: String? = nil, asUser: Bool? = nil, @@ -288,7 +291,7 @@ extension WebAPI { "token": token, "channel": channel, "thread_ts": thread, - "text": text.slackFormatEscaping, + "text": escapeCharacters ? text.slackFormatEscaping : text, "broadcastReply": broadcastReply, "as_user": asUser, "parse": parse?.rawValue, @@ -310,10 +313,11 @@ extension WebAPI { public func sendMeMessage( channel: String, text: String, + escapeCharacters: Bool = true, success: (((ts: String?, channel: String?)) -> Void)?, failure: FailureClosure? ) { - let parameters: [String: Any?] = ["token": token, "channel": channel, "text": text.slackFormatEscaping] + let parameters: [String: Any?] = ["token": token, "channel": channel, "text": escapeCharacters ? text.slackFormatEscaping : text] networkInterface.request(.chatMeMessage, parameters: parameters, successClosure: {(response) in success?((ts: response["ts"] as? String, response["channel"] as? String)) }) {(error) in @@ -328,6 +332,7 @@ extension WebAPI { attachments: [Attachment?]? = nil, parse: ParseMode = .none, linkNames: Bool = false, + escapeCharacters: Bool = true, success: SuccessClosure?, failure: FailureClosure? ) { @@ -335,7 +340,7 @@ extension WebAPI { "token": token, "channel": channel, "ts": ts, - "text": message.slackFormatEscaping, + "text": escapeCharacters ? message.slackFormatEscaping : message, "parse": parse.rawValue, "link_names": linkNames, "attachments": encodeAttachments(attachments) @@ -700,6 +705,23 @@ extension WebAPI { // MARK: - Pins extension WebAPI { + public func pinsList( + channel: String, + success: ItemsClosure?, + failure: FailureClosure? + ) { + let parameters: [String: Any?] = [ + "token": token, + "channel": channel + ] + networkInterface.request(.pinsList, parameters: parameters, successClosure: { response in + let items = response["items"] as? [[String: Any]] + success?(items?.map({ Item(item: $0) })) + }) {(error) in + failure?(error) + } + } + public func pinItem( channel: String, file: String? = nil, @@ -909,7 +931,7 @@ extension WebAPI { full: Bool = true, count: Int = 100, page: Int = 1, - success: ((_ items: [Item]?) -> Void)?, + success: ItemsClosure?, failure: FailureClosure? ) { let parameters: [String: Any?] = [ @@ -1216,13 +1238,13 @@ extension WebAPI { fileprivate func invite( _ endpoint: Endpoint, - channelID: String, - userID: String, + channel: String, + user: String, success: SuccessClosure?, failure: FailureClosure? ) { - let parameters: [String: Any] = ["token": token, "channel": channelID, "user": userID] - networkInterface.request(endpoint, parameters: parameters, successClosure: {(response) in + let parameters: [String: Any] = ["token": token, "channel": channel, "user": user] + networkInterface.request(endpoint, parameters: parameters, successClosure: { _ in success?(true) }) {(error) in failure?(error) diff --git a/Supporting Files/Info.plist b/Supporting Files/Info.plist index 3cc7b8d..020969e 100644 --- a/Supporting Files/Info.plist +++ b/Supporting Files/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.0.7 + 4.1.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright