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

Added initObj key to the media mark request. It was missing. #84

Merged
2 commits merged into from
Feb 13, 2017
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
2 changes: 1 addition & 1 deletion Plugins/Phoenix/BookmarkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class BookmarkService {
private static func createBookmark(eventType: String, position: Int32, assetId: String, fileId: String) -> JSON {
var json: JSON = JSON.init(["objectType": "KalturaBookmark"])
json["type"] = JSON("media")
//json["id"] = JSON(assetId)
json["id"] = JSON(assetId)
json["position"] = JSON(position)
json["playerData"] = JSON.init(["action": JSON(eventType), "objectType": JSON("KalturaBookmarkPlayerData"), "fileId": JSON(fileId)])

Expand Down
8 changes: 2 additions & 6 deletions Plugins/Phoenix/MediaMarkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftyJSON
internal class MediaMarkService {

internal static func sendTVPAPIEVent(baseURL: String,
initObj: JSON?,
initObj: [String : Any],
eventType: String,
currentTime: Int32,
assetId: String,
Expand All @@ -21,11 +21,7 @@ internal class MediaMarkService {
if let request: RequestBuilder = RequestBuilder(url: baseURL) {
request
.set(method: "POST")

if let obj = initObj {
request.set(jsonBody: obj)
}
request
.setBody(key: "initObj", value: JSON(initObj))
.setBody(key: "iFileID", value: JSON(fileId))
.setBody(key: "iMediaID", value: JSON(assetId))
.setBody(key: "iLocation", value: JSON(currentTime))
Expand Down
28 changes: 12 additions & 16 deletions Plugins/Phoenix/PhoenixAnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,22 @@ public class PhoenixAnalyticsPlugin: PKPlugin, KalturaPluginManagerDelegate {
}

if let builder: KalturaRequestBuilder = BookmarkService.actionAdd(baseURL: baseUrl,
partnerId: parterId,
ks: ks,
eventType: action.rawValue.uppercased(),
currentTime: self.player.currentTime.toInt32(),
assetId: mediaEntry.id,
fileId: fileId) {
partnerId: parterId,
ks: ks,
eventType: action.rawValue.uppercased(),
currentTime: self.player.currentTime.toInt32(),
assetId: mediaEntry.id,
fileId: fileId) {
builder.set { (response: Response) in
PKLog.trace("Response: \(response)")
if response.statusCode == 0 {
PKLog.trace("\(response.data)")
if let data : [String: Any] = response.data as! [String : Any]? {
if let result = data["result"] as! [String: Any]? {
if let errorData = result["error"] as! [String: Any]? {
if let errorCode = errorData["code"] as? Int, errorCode == 4001 {

self.kalturaPluginManager.reportConcurrencyEvent()
}
}
}
}
PKLog.trace("\(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.kalturaPluginManager.reportConcurrencyEvent()
}
}
USRExecutor.shared.send(request: builder.build())
Expand Down
36 changes: 15 additions & 21 deletions Plugins/Phoenix/TVPAPIAnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,50 +54,44 @@ public class TVPAPIAnalyticsPlugin: PKPlugin, KalturaPluginManagerDelegate {

var fileId = ""
var baseUrl = ""
var initObj : JSON? = nil

guard let initObj = self.config?.params["initObj"] as? [String : Any] else {
PKLog.error("send analytics failed due to no initObj data")
return
}

guard let mediaEntry = self.mediaEntry else {
PKLog.error("send analytics failed due to nil mediaEntry")
return
}

let method = action == .hit ? "MediaHit" : "MediaMark"

if let url = self.config?.params["baseUrl"] as? String {
baseUrl = url
}
if let fId = self.config?.params["fileId"] as? String {
fileId = fId
}
if let obj = self.config?.params["initObj"] as? JSON {
initObj = obj
}


baseUrl = "\(baseUrl)m=\(method)"

guard let mediaEntry = self.mediaEntry else {
PKLog.error("send analytics failed due to nil mediaEntry")
return
}

if let builder: RequestBuilder = MediaMarkService.sendTVPAPIEVent(baseURL: baseUrl,
initObj: initObj,
eventType: action.rawValue,
currentTime: self.player.currentTime.toInt32(),
assetId: mediaEntry.id,
fileId: fileId) {
builder.set { (response: Response) in

PKLog.trace("Response: \(response)")
if response.statusCode == 0 {

PKLog.trace("\(response.data)")
if let data : [String: Any] = response.data as! [String : Any]? {
if let result = data["concurrent"] as! [String: Any]? {
self.kalturaPluginManager.reportConcurrencyEvent()
}
}

guard let data : [String: Any] = response.data as? [String : Any] else { return }
guard let result = data["concurrent"] as? [String : Any] else { return }
self.kalturaPluginManager.reportConcurrencyEvent()
}
}

USRExecutor.shared.send(request: builder.build())

}

}
Expand Down