Created
November 22, 2010 05:39
-
-
Save jakobo/709571 to your computer and use it in GitHub Desktop.
BLOG: Extensions in LinkedIn's JavaScript API
This file contains 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
<script type="text/javascript" src="http://platform.linkedin.com/in.js"> | |
api_key: api_key_123456 | |
extensions: MyExtension@http://www.felocity.com/myextension.js | |
</script> |
This file contains 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
IN.$extensions("MyExtension", function() { | |
// modifies IN.API.base to add a method that converts results to JSON | |
var IN_APIS_BASE = Sslac.definitionOf("IN.APIs.Base"), | |
construct = IN_APIS_BASE.getConstructor(), | |
handleSuccess = IN_APIS_BASE.getMethod("handleSuccessResults"); | |
// change the constructor to also add a "json" handler | |
IN_APIS_BASE | |
.Constructor(function() { | |
construct.apply(this, arguments); | |
this.handlers.json = []; | |
}) | |
/** | |
* Perform an API get, and the invoke the supplied function with the result | |
* @method json | |
* @param fn {Function} a function to invoke | |
* @param scope {Object} a scope to run "fn" in | |
* @return this | |
*/ | |
.Method("json", function() { | |
this.addHandler(this.handlers.json, [].slice.apply(arguments)); | |
this.get(); | |
return this; | |
}) | |
// override handleSuccessResults to also run the json() handlers | |
.Method("handleSuccessResults", function(results) { | |
// run and clear the json handlers | |
this.runHandler(this.handlers.json, JSON.stringify(results)); | |
this.markHandlerAsRan(this.handlers.json); | |
// run original method | |
return handleSuccess.apply(this, arguments); | |
}); | |
}); |
This file contains 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
IN.$extensions("MyExtension", function() { | |
// body of extension goes here | |
}); |
This file contains 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
<script type="text/javascript" src="http://platform.linkedin.com/in.js"> | |
api_key: api_key_123456 | |
extensions: MyExtension@https://gist.github.com/raw/709571/hotswap.js | |
</script> |
This file contains 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
IN.API.Profile("me").json(function(r) { | |
// "r" contains a JSON string | |
// and behaves similar to .result() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment