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

Fem 2293 #5

Merged
merged 2 commits into from
Nov 22, 2018
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
4 changes: 4 additions & 0 deletions Sources/OTT/Analytics/BaseOTTAnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public class BaseOTTAnalyticsPlugin: BasePlugin, OTTAnalyticsPluginProtocol, App
func reportConcurrencyEvent() {
self.messageBus?.post(OttEvent.Concurrency())
}

func reportBookmarkErrorEvent(code: String?, message: String?) {
self.messageBus?.post(OttEvent.BookmarkError(code: code, message: message))
}
}

/************************************************************/
Expand Down
15 changes: 12 additions & 3 deletions Sources/OTT/Analytics/OTTEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import PlayKit
/// OTT Event
public class OttEvent : PKEvent {

static let codeKey = "code"
static let messageKey = "message"

class Concurrency : OttEvent {}
/// represents the Concurrency event Type.
/// Concurrency events fire when more then the allowed connections are exceeded.
public static let concurrency: OttEvent.Type = Concurrency.self

static let messageKey = "message"
public static let concurrency: OttEvent.Type = OttEvent.Concurrency.self

class Report: OttEvent {
convenience init(message: String) {
Expand All @@ -28,6 +29,14 @@ public class OttEvent : PKEvent {
}

@objc public static let report: OttEvent.Type = OttEvent.Report.self

class BookmarkError : OttEvent {
convenience init(code: String?, message: String?) {
self.init([OttEvent.codeKey: code ?? "", OttEvent.messageKey: message ?? ""])
}
}

@objc public static let bookmarkError: OttEvent.Type = OttEvent.BookmarkError.self
}

extension PKEvent {
Expand Down
11 changes: 8 additions & 3 deletions Sources/OTT/Analytics/Phoenix/PhoenixAnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ public class PhoenixAnalyticsPlugin: BaseOTTAnalyticsPlugin {
PKLog.verbose("\(String(describing: response.data))")
guard let data = response.data as? [String: Any] else { return }
guard let result = data["result"] as? [String: Any] else { return }
guard let errorData = result["error"] as? [String: Any] else { return }
guard let errorCode = errorData["code"] as? Int, errorCode == 4001 else { return }
self.reportConcurrencyEvent()
guard let ottError = OTTError(json: result) else { return }

switch ottError.code {
case "4001":
self.reportConcurrencyEvent()
default:
self.reportBookmarkErrorEvent(code: ottError.code, message: ottError.message)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/OTT/Model/OTTError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ class OTTError: OTTBaseObject {

var message: String?
var code: String?
var objectType: String?

let errorKey = "error"
let messageKey = "message"
let codeKey = "code"
let objectTypeKey = "objectType"

required init?(json: Any) {

let jsonObj: JSON = JSON(json)
let errorDict = jsonObj[errorKey]
self.message = errorDict[messageKey].string
self.code = errorDict[codeKey].string
self.objectType = errorDict[objectTypeKey].string
}
}