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

Analytics plugins #26

Merged
merged 5 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Swinject

public protocol AnalyticsService {
public protocol AnalyticsService: Sendable {
func identify(id: String, username: String?, email: String?)
func logEvent(_ event: String, parameters: [String: Any]?)
func logScreenEvent(_ event: String, parameters: [String: Any]?)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the filename to DeepLinkManagerProtocol.swift

// OEXFoundation
//
// Created by Anton Yarmolenka on 26/11/2024.
//

import Foundation
import UIKit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this import for protocol?


@MainActor
public protocol DeepLinkManagerProtocol: Sendable {
func processLinkFrom(userInfo: [AnyHashable: Any])
func processDeepLink(with params: [AnyHashable: Any]?)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// File.swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the filename to DeepLinkManagerProtocolMock.swift

// OEXFoundation
//
// Created by Anton Yarmolenka on 13/01/2025.
//

import Foundation

public class DeepLinkManagerProtocolMock: DeepLinkManagerProtocol {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for tests or users?
Can we remove public to hide it from plugin users if it's for tests?

public var processLinkFromUserInfo: [AnyHashable: Any] = [:]
public var processLinkFromCallsCount: Int = 0

public func processLinkFrom(userInfo: [AnyHashable: Any]) {
processLinkFromCallsCount += 1
processLinkFromUserInfo = userInfo
}

public var processDeepLinkUserInfo: [AnyHashable: Any]?
public var processDeepLinkCallsCount: Int = 0

public func processDeepLink(with params: [AnyHashable: Any]?) {
processDeepLinkCallsCount += 1
processDeepLinkUserInfo = params
}
public init() {}
}
1 change: 1 addition & 0 deletions Sources/OEXFoundation/Extensions/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public extension Notification.Name {
public extension Notification {
enum UserInfoKey: String {
case isForced
case status
}
}
32 changes: 32 additions & 0 deletions Sources/OEXFoundation/Network/Alamofire+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,35 @@ public extension Error {
}
}
}

public extension Error {
var errorCode: Int {
guard let afError = self.asAFError else {
return (self as NSError).code
}

if let validationError = afError.validationError {
return validationError.statusCode
}

if let code = afError.responseCode {
return code
}

return (self as NSError).code
}

var errorMessage: String {
guard let afError = self.asAFError else {
return (self as NSError).localizedDescription
}

if let validationError = afError.validationError,
let data = validationError.data,
let error = data["error"] as? String {
return error
}

return afError.localizedDescription
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// PushNotificationService.swift
// OpenEdX
//
// Created by Anton Yarmolenka on 22/11/2024.
//

import Foundation

public protocol PushNotificationsProvider: Sendable {
func didRegisterWithDeviceToken(deviceToken: Data)
}

public extension PushNotificationsProvider {
func didFailToRegisterForRemoteNotificationsWithError(error: Error) {}
func synchronizeToken() {}
func refreshToken() {}
}

@MainActor
public protocol PushNotificationsListener: Sendable {
func shouldListenNotification(userinfo: [AnyHashable: Any]) -> Bool
func didReceiveRemoteNotification(userInfo: [AnyHashable: Any])
}