From 46107fd61a54c8422417b31aef3d964fb8b82f89 Mon Sep 17 00:00:00 2001 From: Bernat Fortet Date: Sun, 19 May 2013 22:52:41 -0700 Subject: [PATCH] First commit - not working yet --- likemashup.behance.js | 46 +++++++++++++++++++++++++++++++++++++++++++ test.html | 15 ++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 likemashup.behance.js create mode 100644 test.html diff --git a/likemashup.behance.js b/likemashup.behance.js new file mode 100644 index 0000000..4c287a7 --- /dev/null +++ b/likemashup.behance.js @@ -0,0 +1,46 @@ +;(function($, window, document, undefined) { + 'use strict'; + + $.lm_behance = {}; + + var jsonpGET = function (path, args) { + $.ajax({ + type: 'GET', + url: ' http://www.behance.net/v2' + path + "?api_key=gPVGVtNKZxWBqYZbM4jF37ionx4ugsmN", + data: args[1] || {}, + success: function (data) { + if (typeof (data) === 'undefined') { + args[0]({error: true}); + } + else { + args[0](data); + } + } + }); + }; + + var methods = { + 'getUserAppreciations': '/users/$/appreciations', + 'getProject': '/projects/$/', + }; + + + var createAPIMethod = function (urlPattern) { + return function () { + var // Convert arguments to a real Array + args = [].slice.call(arguments), + + + // We run shift() on args here because we don't need to send + // the first argument to jsonpGET. + url = urlPattern.replace('$', args.shift()); + + jsonpGET(url, args); + }; + }; + + for (var method in methods) { + $.lm_behance[method] = createAPIMethod(methods[method]); + } + +})(jQuery, window , document); \ No newline at end of file diff --git a/test.html b/test.html new file mode 100644 index 0000000..ad90e51 --- /dev/null +++ b/test.html @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file