Compare commits

...

4 Commits

Author SHA1 Message Date
Peter Zignego 3823aee4cf Revert oauth endpoint change and query params fix (#207)
* Fix extracting query parameters from request

* downgrade oauth access path

Co-authored-by: David Jennes <david.jennes@gmail.com>
2022-01-23 20:20:59 -05:00
Peter Zignego b95391b03b Revert oauth endpoint change and query params fix (#207)
* Fix extracting query parameters from request

* downgrade oauth access path

Co-authored-by: David Jennes <david.jennes@gmail.com>
2022-01-23 20:01:37 -05:00
Peter Zignego 56be11a950 Revert oauth endpoint change and query params fix (#207)
* Fix extracting query parameters from request

* downgrade oauth access path

Co-authored-by: David Jennes <david.jennes@gmail.com>
2022-01-23 20:01:24 -05:00
Peter Zignego f6f4252075 Update podspec 2021-12-29 10:00:18 -05:00
8 changed files with 18 additions and 48 deletions
+2 -1
View File
@@ -40,4 +40,5 @@ Carthage/Build
# Swift Package Manager
.swiftpm/
*.resolved
*.resolved
.vscode
+1 -1
View File
@@ -1 +1 @@
5.2.4
5.5.2
@@ -58,6 +58,7 @@ extension HttpRequest {
return try! Request(
method: HTTPMethod.custom(named: method),
path: path,
queryPairs: queryParams,
body: String(bytes: body, encoding: .utf8) ?? "",
headers: HTTPHeaders(headers: headers.map ({ Header(name: $0.key, value: $0.value) }))
)
@@ -17,8 +17,10 @@ import Foundation
public protocol RequestType {
/// The HTTP request body.
var body: Data { get }
/// The HTTP request path, including query string and any fragments.
/// The HTTP request path
var path: String { get }
/// The HTTP request query pairs
var queryPairs: [(String, String)] { get }
/// The HTTP request method.
var method: HTTPMethod { get }
/// The HTTP request headers.
@@ -30,14 +32,16 @@ public struct Request: RequestType {
public var method: HTTPMethod
public var path: String
public var queryPairs: [(String, String)]
public var body: Data
public var headers: HTTPHeaders
/// Create a Request
/// Throws an error if the body parameter cannot be converted to Data
public init(method: HTTPMethod, path: String, body: String, headers: HTTPHeaders) throws {
public init(method: HTTPMethod, path: String, queryPairs: [(String, String)], body: String, headers: HTTPHeaders) throws {
self.method = method
self.path = path
self.queryPairs = queryPairs
guard let data = body.data(using: .utf8) else {
throw TitanError.dataConversion
}
@@ -46,9 +50,10 @@ public struct Request: RequestType {
}
/// Create a Request
public init(method: HTTPMethod, path: String, body: Data, headers: HTTPHeaders) {
public init(method: HTTPMethod, path: String, queryPairs: [(String, String)], body: Data, headers: HTTPHeaders) {
self.method = method
self.path = path
self.queryPairs = queryPairs
self.body = body
self.headers = headers
}
@@ -57,7 +62,7 @@ public struct Request: RequestType {
extension Request {
/// Create a Request from a RequestType
public init(request: RequestType) {
self.init(method: request.method, path: request.path, body: request.body, headers: request.headers)
self.init(method: request.method, path: request.path, queryPairs: request.queryPairs, body: request.body, headers: request.headers)
}
}
@@ -14,43 +14,6 @@
import Foundation
public extension RequestType {
/// The pairs of keys and values in the query string of the `RequestType`s path.
/// Complexity: 0(n) on all invocations.
var queryPairs: [(key: String, value: String)] {
// Ensure there is a query string, otherwise return
guard let indexOfQuery = self.path.firstIndex(of: "?") else {
return []
}
let query = self.path.suffix(from: indexOfQuery).dropFirst()
// Create an array of the individual query pairs, e.g. ["foo=bar", "baz=qux"]
let pairs = query.split(separator: "&")
// Decode `foo=bar` -> `(key: "foo", value: "bar")`, percent decoding any values along the way
return pairs.map { pair -> (key: String, value: String) in
// Separate the query pair into an array, e.g. "foo=bar" -> ["foo", "bar"]
let comps = pair.split(separator: "=")
// Split returns an array of subsequences which should conform to StringProtocol, however on Linux StringProtocol is out of date.
// Workaround for https://bugs.swift.org/browse/SR-5727 by converting to a String directly
.map(String.init)
.map {
// Percent encoding mandates that "%20" = <space>"
// however, many applications use "+" to mean space as well, so decode those (before we decode any percent-encoded plus signs!)
return $0.replacingOccurrences(of: "+", with: " ")
}.map {
return $0.removingPercentEncoding ?? ""
}
switch comps.count {
case 1: // "?foo="
return (key: String(comps[0]), value: "")
case 2: // "?foo=bar"
return (key: String(comps[0]), value: String(comps[1]))
default: // "?"
return (key: "", value: "")
}
}
}
/// Access the query string as a dictionary, with case sensitive keys.
/// Complexity: 0(n) on all invocations.
var query: [String: String] {
@@ -14,8 +14,8 @@
import Foundation
extension Request {
public init(_ method: HTTPMethod = .get, _ path: String = "/", _ body: String = "", _ headers: HTTPHeaders = HTTPHeaders()) {
self.init(method: method, path: path, body: body.data(using: .utf8) ?? Data(), headers: headers)
public init(_ method: HTTPMethod = .get, _ path: String = "/", _ queryPairs: [(String, String)] = [], _ body: String = "", _ headers: HTTPHeaders = HTTPHeaders()) {
self.init(method: method, path: path, queryPairs: queryPairs, body: body.data(using: .utf8) ?? Data(), headers: headers)
}
}
+1 -1
View File
@@ -70,7 +70,7 @@ public enum Endpoint: String {
case mpimList = "mpim.list"
case mpimMark = "mpim.mark"
case mpimOpen = "mpim.open"
case oauthAccess = "oauth.v2.access"
case oauthAccess = "oauth.access"
case pinsAdd = "pins.add"
case pinsList = "pins.list"
case pinsRemove = "pins.remove"
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SlackKit"
s.version = "4.6.0"
s.version = "4.7.0"
s.summary = "Write Slack apps in Swift"
s.homepage = "https://github.com/pvzig/SlackKit"
s.license = "MIT"
@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/pvzig/SlackKit.git", :tag => s.version.to_s }
s.social_media_url = "https://twitter.com/pvzig"
s.platforms = { :ios => '10.0', :osx => '10.11', :tvos => '10.0' }
s.swift_version = '5.2.4'
s.swift_version = '5.5.2'
s.cocoapods_version = '>= 1.4.0'
s.default_subspec = "SlackKit"