Last active
August 29, 2015 14:21
-
-
Save send2moran/211a2eb19c4a7bf494e8 to your computer and use it in GitHub Desktop.
Mapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Channel.js | |
Sdk.Channel = function (json) { | |
var __propMap = { | |
"id": {"prop": "channelId"}, | |
"name": {"prop": "name"}, | |
"watermarkImages": {"prop": "_watermarkImages", "class": Sdk.Image}, | |
"currentProgram": {"prop": "currentProgram", "class": Sdk.Program}, | |
"officialUrl": {"prop": "officialUrl"}, | |
"callSign": {"prop": "callSign"}, | |
"preRollUrl": {"prop": "preRollUrl"}, | |
"images": {"prop": "_logoImages", "class": Sdk.Image} | |
}; | |
}; | |
this._sdk._jsonMapper.mapJsonProperties(this, json, __propMap); | |
//JSONMapper.js | |
for (var key in map) { | |
var ClassConstructor = map[key]["class"]; | |
var propName = map[key].prop; | |
var propContent = jsonContentFromPath(parsedJson, key); | |
if (typeof propContent == "undefined") | |
continue; | |
if (typeof ClassConstructor == "undefined") | |
object[propName] = propContent; | |
else { | |
// handle array of WhipSdk. classes | |
if (Object.prototype.toString.call(propContent) == "[object Array]") { | |
var propArray = []; | |
for (var i = 0; i < propContent.length; i++) | |
propArray.push(this._sdk._createSdkObject(ClassConstructor, propContent[i])); | |
object[propName] = propArray; | |
} | |
else | |
object[propName] = this._sdk._createSdkObject(ClassConstructor, propContent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment