Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return Error instead of AEPError #456

Merged
merged 5 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AEPCore/Sources/core/MobileCore+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public extension MobileCore {
/// Get a JSON string containing all of the user's identities known by the SDK and calls a handler upon completion.
/// - Parameter completion: a closure that is invoked with a `String?` containing the SDK identities in JSON format and an `AEPError` if the request failed
@objc(getSdkIdentities:)
static func getSdkIdentities(completion: @escaping (String?, AEPError) -> Void) {
static func getSdkIdentities(completion: @escaping (String?, Error?) -> Void) {
let event = Event(name: CoreConstants.EventNames.GET_SDK_IDENTITIES, type: EventType.configuration, source: EventSource.requestIdentity, data: nil)

EventHub.shared.registerResponseListener(triggerEvent: event, timeout: 1) { responseEvent in
guard let responseEvent = responseEvent else {
completion(nil, .callbackTimeout)
completion(nil, AEPError.callbackTimeout)
return
}

guard let identities = responseEvent.data?[CoreConstants.Keys.ALL_IDENTIFIERS] as? String else {
completion(nil, .unexpected)
completion(nil, AEPError.unexpected)
return
}

Expand Down
4 changes: 2 additions & 2 deletions AEPCore/Sources/core/MobileCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public final class MobileCore: NSObject {

/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched
/// - Parameters:
/// - type: An `String` indicating the event type the current listener is listening for
/// - source: An `String` indicating the event source the current listener is listening for
/// - type: A `String` indicating the event type the current listener is listening for
/// - source: A `String` indicating the event source the current listener is listening for
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched type and source
@objc(registerEventListenerWithType:source:listener:)
public static func registerEventListener(type: String, source: String, listener: @escaping EventListener) {
Expand Down
4 changes: 2 additions & 2 deletions AEPCore/Sources/eventhub/EventHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ final class EventHub {

/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched
/// - Parameters:
/// - type: An `String` indicating the event type the current listener is listening for
/// - source: An `String` indicating the event source the current listener is listening for
/// - type: A `String` indicating the event type the current listener is listening for
/// - source: A `String` indicating the event source the current listener is listening for
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched type and source
func registerEventListener(type: String, source: String, listener: @escaping EventListener) {
eventHubQueue.async {
Expand Down
2 changes: 1 addition & 1 deletion AEPCore/Tests/MobileCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class MobileCoreTests: XCTestCase {
MobileCore.dispatch(event: expectedEvent2)

// verify
wait(for: [responseExpectation1,responseExpectation2], timeout: 1.0)
wait(for: [responseExpectation1,responseExpectation2], timeout: 2.0)
}

// MARK: setWrapperType(...) tests
Expand Down
16 changes: 8 additions & 8 deletions AEPIdentity/Sources/Identity+PublicAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
/// - Parameters:
/// - url: URL to which the visitor info needs to be appended. Returned as is if it is nil or empty.
/// - completion: closure which will be invoked once the updated url is available, along with an error if any occurred
static func appendTo(url: URL?, completion: @escaping (URL?, AEPError) -> Void) {
static func appendTo(url: URL?, completion: @escaping (URL?, Error?) -> Void) {
let data = [IdentityConstants.EventDataKeys.BASE_URL: url?.absoluteString ?? ""]
let event = Event(name: IdentityConstants.EventNames.IDENTITY_REQUEST_IDENTITY,
type: EventType.identity,
Expand All @@ -27,12 +27,12 @@ import Foundation

MobileCore.dispatch(event: event) { responseEvent in
guard let responseEvent = responseEvent else {
completion(nil, .callbackTimeout)
completion(nil, AEPError.callbackTimeout)
return
}

guard let updatedUrlStr = responseEvent.data?[IdentityConstants.EventDataKeys.UPDATED_URL] as? String else {
completion(nil, .unexpected)
completion(nil, AEPError.unexpected)
return
}
completion(URL(string: updatedUrlStr), .none)
Expand All @@ -42,20 +42,20 @@ import Foundation
/// Returns all customer identifiers which were previously synced with the Adobe Experience Cloud.
/// - Parameter completion: closure which will be invoked once the customer identifiers are available.
@objc(getIdentifiers:)
static func getIdentifiers(completion: @escaping ([Identifiable]?, AEPError) -> Void) {
static func getIdentifiers(completion: @escaping ([Identifiable]?, Error?) -> Void) {
let event = Event(name: IdentityConstants.EventNames.IDENTITY_REQUEST_IDENTITY,
type: EventType.identity,
source: EventSource.requestIdentity,
data: nil)

MobileCore.dispatch(event: event) { responseEvent in
guard let responseEvent = responseEvent else {
completion(nil, .callbackTimeout)
completion(nil, AEPError.callbackTimeout)
return
}

guard let identifiers = responseEvent.data?[IdentityConstants.EventDataKeys.VISITOR_IDS_LIST] as? [Identifiable] else {
completion(nil, .unexpected)
completion(nil, AEPError.unexpected)
return
}

Expand Down Expand Up @@ -117,15 +117,15 @@ import Foundation
/// Gets Visitor ID Service identifiers in URL query string form for consumption in hybrid mobile apps.
/// - Parameter completion: closure invoked with a value containing the visitor identifiers as a query string upon completion of the service request
@objc(getUrlVariables:)
static func getUrlVariables(completion: @escaping (String?, AEPError) -> Void) {
static func getUrlVariables(completion: @escaping (String?, Error?) -> Void) {
let event = Event(name: IdentityConstants.EventNames.IDENTITY_REQUEST_IDENTITY,
type: EventType.identity,
source: EventSource.requestIdentity,
data: [IdentityConstants.EventDataKeys.URL_VARIABLES: true])

MobileCore.dispatch(event: event) { responseEvent in
guard let responseEvent = responseEvent else {
completion(nil, .callbackTimeout)
completion(nil, AEPError.callbackTimeout)
return
}

Expand Down