Skip to content

Commit

Permalink
Changes access control for several objects (#32)
Browse files Browse the repository at this point in the history
* Changes access control for several objects to better mesh with third-party namspaces
  • Loading branch information
Craig Lane committed Nov 21, 2019
1 parent 480877e commit 6a6f0a2
Show file tree
Hide file tree
Showing 88 changed files with 4,183 additions and 3,959 deletions.
20 changes: 19 additions & 1 deletion .pubnub.yml
@@ -1,9 +1,27 @@
---
name: swift
scm: github.com/pubnub/swift
version: "2.1.2"
version: "2.2.0"
schema: 1
changelog:
-
changes:
- test: "`Timetoken` was changed from an Int64 to UInt64 to avoid negative timetoken values"
type: improvement
- test: "Removed `PubNubRouter`, and replaced with multiple service specific `HTTPRouter` implementations"
type: improvement
- test: "Removed `Endpoint` type"
type: improvement
- test: "Renamed `Response` to `EndpointResponse`"
type: improvement
- test: "Removed `HTTPHeader` & `HTTPHeader`, and replaced with `[String: String]`"
type: improvement
- test: "Renamed `Session` to `HTTPSession` and made it an internal type"
type: improvement
- test: "Created `RequestReplaceable` and made `Request` an internal type"
type: improvement
date: 2019-11-14
version: v2.2.0
-
changes:
- test: "PubNub Info.plist is now included on Cocoapod and Carthage deployed builds"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1120"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
238 changes: 108 additions & 130 deletions PubNub.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion PubNub.xcodeproj/xcshareddata/xcschemes/Linting.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1120"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion PubNub.xcodeproj/xcshareddata/xcschemes/PubNub.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1120"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1120"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1120"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1120"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions PubNubErrorTests.swift
Expand Up @@ -29,10 +29,10 @@
import XCTest

class PubNubErrorTests: XCTestCase {
let error: PubNubError = PubNubError(reason: .badRequest)
let error: PubNubError = PubNubError(.badRequest)
let reason: PubNubError.Reason = .badRequest

let optionalError: PubNubError? = PubNubError(reason: .badRequest)
let optionalError: PubNubError? = PubNubError(.badRequest)
let optionalReason: PubNubError.Reason? = .badRequest

// MARK: Equatable
Expand Down
2 changes: 1 addition & 1 deletion PubNubSwift.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PubNubSwift'
s.version = '2.1.2'
s.version = '2.2.0'
s.homepage = 'https://github.com/pubnub/swift'
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
s.authors = { 'PubNub, Inc.' => 'support@pubnub.com' }
Expand Down
82 changes: 82 additions & 0 deletions Sources/PubNub/Errors/ErrorDescription.swift
Expand Up @@ -70,6 +70,88 @@ public struct ErrorDescription {
}()
}

extension ErrorDescription {
public static let emptyChannelString: String = {
"Channel is an empty `String`"
}()

public static let emptyChannelArray: String = {
"Channels is an empty `Array`"
}()

public static let emptyGroupString: String = {
"Group is an empty `String`"
}()

public static let missingChannelsAnyGroups: String = {
"No Channels or Groups were provided"
}()

public static let missingTimetoken: String = {
"No `Timetoken` value provided"
}()

public static let invalidHistoryTimetokens: String = {
"Timetokens `Array` count does not match Channels `Array` count"
}()

public static let invalidMessageAction: String = {
"Message Action is invalid"
}()

public static let emptyMessagePayload: String = {
"Message is an empty Object"
}()

public static let emptyUUIDString: String = {
"UUID is an empty `String`"
}()

public static let emptyDeviceTokenData: String = {
"Device Token is an empty `Data`"
}()

public static let emptySpaceID: String = {
"SpaceID is an empty `String`"
}()

public static let invalidPubNubSpace: String = {
"The Object is not a valid `PubNubSpace`"
}()

public static let emptyUserID: String = {
"UserID is an empty `String`"
}()

public static let invalidPubNubUser: String = {
"The Object is not a valid `PubNubUser`"
}()

public static let invalidJoiningMember: String = {
"A joining Member Object is not valid"
}()

public static let invalidUpdatingMember: String = {
"An updating Member Object is not valid"
}()

public static let invalidLeavingMember: String = {
"A removing Member Object is not valid"
}()

public static let invalidJoiningMembership: String = {
"A joining Membership Object is not valid"
}()

public static let invalidUpdatingMembership: String = {
"An updating Membership Object is not valid"
}()

public static let invalidLeavingMembership: String = {
"A removing Membership Object is not valid"
}()
}

extension PubNubError: LocalizedError, CustomStringConvertible {
public var description: String {
return errorDescription ?? reason.description
Expand Down
59 changes: 23 additions & 36 deletions Sources/PubNub/Errors/PubNubError.swift
Expand Up @@ -40,12 +40,7 @@ public struct PubNubError: Error {
let coorelation: [CorrelationIdentifier]
let affected: [AffectedValue]

/// The Endpoint category the error is associated with
public let endpointCategory: Endpoint.Category
/// The domain of the Endpoint the error is associated with
public var endpointDomain: Endpoint.OperationType {
return endpointCategory.operationCategory
}
let router: HTTPRouter?

/// The domain of the `Error`
public let domain = "PubNub"
Expand Down Expand Up @@ -212,58 +207,50 @@ public struct PubNubError: Error {

init(
_ reason: Reason,
endpoint category: Endpoint.Category,
router: HTTPRouter? = nil,
coorelation identifiers: [CorrelationIdentifier] = [],
underlying error: Error? = nil,
additional details: [String] = [],
affected values: [AffectedValue] = []
) {
endpointCategory = category
self.router = router
self.reason = reason
coorelation = identifiers
underlying = error
self.details = details
affected = values
}

init(reason: Reason) {
self.init(reason, endpoint: Endpoint.unknown)
}

init(_ reason: Reason, endpoint: Endpoint, error: Error? = nil) {
self.init(reason, endpoint: endpoint.category, underlying: error)
}

init(
reason: Reason?,
endpoint: Endpoint,
router: HTTPRouter,
request: URLRequest,
response: HTTPURLResponse,
affected details: [ErrorDetail]? = nil
) {
let reasonOrResponse = reason ?? Reason(rawValue: response.statusCode)

self.init(reasonOrResponse ?? .unrecognizedStatusCode,
endpoint: endpoint.category,
router: router,
additional: details?.compactMap { $0.message } ?? [],
affected: [.request(request), .response(response)])
}

init(router: Router, request: URLRequest, response: HTTPURLResponse) {
init(router: HTTPRouter, request: URLRequest, response: HTTPURLResponse) {
self.init(PubNubError.Reason(rawValue: response.statusCode) ?? .unknown,
endpoint: router.endpoint.category,
router: router,
affected: [.request(request), .response(response)])
}

init<ResponseType>(_ reason: Reason, response: Response<ResponseType>, error: Error? = nil) {
init<ResponseType>(_ reason: Reason, response: EndpointResponse<ResponseType>, error: Error? = nil) {
if let error = error {
self.init(reason,
endpoint: response.endpoint.category,
router: response.router,
underlying: error,
affected: [.request(response.request), .response(response.response)])
}
self.init(reason,
endpoint: response.endpoint.category,
router: response.router,
affected: [.request(response.request), .response(response.response)])
}
}
Expand All @@ -283,49 +270,49 @@ extension PubNubError: Hashable {
// MARK: - Error Coersion Helpers

extension PubNubError {
static func convert(_ error: Error, router: Router, default reason: Reason = .unknown) -> PubNubError {
static func convert(_ error: Error, router: HTTPRouter, default reason: Reason = .unknown) -> PubNubError {
if let pubnub = error.pubNubError {
return pubnub
} else if let reason = error.genericPubNubReason {
return PubNubError(reason, endpoint: router.endpoint.category, underlying: error)
return PubNubError(reason, router: router, underlying: error)
} else {
return PubNubError(reason, endpoint: router.endpoint.category, underlying: error)
return PubNubError(reason, router: router, underlying: error)
}
}

static func urlCreation(_ error: Error, router: Router) -> PubNubError {
static func urlCreation(_ error: Error, router: HTTPRouter) -> PubNubError {
return PubNubError.convert(error, router: router, default: .invalidURL)
}

static func sessionDelegate(_ error: Error, router: Router) -> PubNubError {
static func sessionDelegate(_ error: Error, router: HTTPRouter) -> PubNubError {
return PubNubError.convert(error, router: router, default: .unknown)
}

static func retry(_ error: Error, router: Router) -> PubNubError {
static func retry(_ error: Error, router: HTTPRouter) -> PubNubError {
return PubNubError.convert(error, router: router, default: .requestRetryFailed)
}

static func cancellation(_ reason: Reason?, error: Error?, router: Router) -> PubNubError {
static func cancellation(_ reason: Reason?, error: Error?, router: HTTPRouter) -> PubNubError {
if let reason = reason {
return PubNubError(reason, endpoint: router.endpoint, error: error)
return PubNubError(reason, router: router, underlying: error)
}

if let pubnub = error?.pubNubError {
return pubnub
} else if let urlError = error?.urlError {
return PubNubError(.clientCancelled, endpoint: router.endpoint.category, underlying: urlError)
return PubNubError(.clientCancelled, router: router, underlying: urlError)
} else {
return PubNubError(.clientCancelled, endpoint: router.endpoint.category, underlying: error)
return PubNubError(.clientCancelled, router: router, underlying: error)
}
}

static func event(_ error: Error, endpoint category: Endpoint.Category) -> PubNubError {
static func event(_ error: Error, router: HTTPRouter?) -> PubNubError {
if let pubnub = error.pubNubError {
return pubnub
} else if let urlError = error.urlError {
return PubNubError(.clientCancelled, endpoint: category, underlying: urlError)
return PubNubError(.clientCancelled, router: router, underlying: urlError)
} else {
return PubNubError(.unknown, endpoint: category, underlying: error)
return PubNubError(.unknown, router: router, underlying: error)
}
}
}
Expand Down

0 comments on commit 6a6f0a2

Please sign in to comment.