Skip to content

Commit

Permalink
Module structure property restructuring, get, post, del and oauth obj…
Browse files Browse the repository at this point in the history
…ects for oAuth2 and api. Update tests to incorporate mapping endpoints
  • Loading branch information
MrSwitch committed Oct 18, 2013
1 parent 3d35d3f commit 5d651a9
Show file tree
Hide file tree
Showing 14 changed files with 575 additions and 350 deletions.
242 changes: 134 additions & 108 deletions src/hello.js

Large diffs are not rendered by default.

49 changes: 29 additions & 20 deletions src/modules/dropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,44 @@ hello.init({
// Signin once token expires?
autorefresh : false,

uri : {
//auth : "https://www.dropbox.com/1/oauth/authorize",
base : "https://api.dropbox.com/1/",
me : 'account/info',
"me/files" : function(p,callback){
if(p.method === 'get'){
callback('metadata/dropbox');
return;
// API Base URL
base : "https://api.dropbox.com/1/",

// Map GET requests
get : {
"me" : 'account/info',
"me/files" : "metadata/dropbox",
"me/folder" : "metadata/dropbox/@{id}",
"me/folders" : 'metadata/dropbox/',
"default" : function(p,callback){
if(p.path.match("https://api-content.dropbox.com/1/files/")){
// this is a file, return binary data
p.method = 'blob';
}
var path = p.data.dir;
delete p.data.dir;
callback('https://api-content.dropbox.com/1/files/dropbox/'+path);
callback(p.path);
}
},
post : {
"me/files" : function(p,callback){

var path = p.data.id,
file_name = p.data.name;

p.data = {
file : p.data.file
};

callback('https://api-content.dropbox.com/1/files_put/dropbox/'+path+"/"+file_name);
},
"me/folders" : function(p, callback){

var name = p.data.name;
p.data = null;

callback('fileops/create_folder?'+hello.utils.param({
path : name,
root : 'dropbox'
}));
},
"default" : function(p,callback){
if(p.path.match("https://api-content.dropbox.com/1/files/")){
// this is a file, return binary data
if(p.method === 'get'){
p.method = 'blob';
}
}
callback(p.path);
}
},
wrap : {
Expand Down
59 changes: 44 additions & 15 deletions src/modules/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ hello.init({
facebook : {
name : 'Facebook',

uri : {
// REF: http://developers.facebook.com/docs/reference/dialogs/oauth/
auth : 'http://www.facebook.com/dialog/oauth/',
base : 'https://graph.facebook.com/',
'me/friends' : 'me/friends',
'me/following' : 'me/friends',
'me/followers' : 'me/friends',
'me/share' : 'me/feed',
'me/files' : 'me/albums'
// REF: http://developers.facebook.com/docs/reference/dialogs/oauth/
oauth : {
version : 2,
auth : 'http://www.facebook.com/dialog/oauth/'
},

// Authorization scopes
scope : {
basic : '',
email : 'email',
Expand All @@ -51,6 +48,36 @@ hello.init({

offline_access : 'offline_access'
},

// API Base URL
base : 'https://graph.facebook.com/',

// Map GET requests
get : {
'me' : 'me',
'me/friends' : 'me/friends',
'me/following' : 'me/friends',
'me/followers' : 'me/friends',
'me/share' : 'me/feed',
'me/files' : 'me/albums',
'me/albums' : 'me/albums',
'me/album' : '@{id}/photos',
'me/photos' : 'me/photos',
'me/photo' : '@{id}'
},

// Map POST requests
post : {
'me/share' : 'me/feed',
'me/albums' : 'me/albums',
'me/album' : '@{id}/photos'
},

// Map DELETE requests
del : {
//'me/album' : '@{id}'
},

wrap : {
me : formatUser,
'me/friends' : formatFriends,
Expand Down Expand Up @@ -92,23 +119,25 @@ hello.init({
xhr : function(p,qs){
if(p.method==='get'||p.method==='post'){
qs.suppress_response_codes = true;
return true;
}
else{
return false;
else if(p.method === "delete"){
qs.method = 'delete';
p.method = "post";
}
return true;
},

// Special requirements for handling JSONP fallback
jsonp : function(p){
if( p.method.toLowerCase() !== 'get' && !hello.utils.hasBinary(p.data) ){
p.data.method = p.method.toLowerCase();
var m = p.method.toLowerCase();
if( m !== 'get' && !hello.utils.hasBinary(p.data) ){
p.data.method = m;
p.method = 'get';
}
},

// Special requirements for iframe form hack
post : function(p){
form : function(p){
return {
// fire the callback onload
callbackonload : true
Expand Down
42 changes: 23 additions & 19 deletions src/modules/flickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function formatError(o){

function formatPhotos(o){
if (o.photoset || o.photos){
var set = (o.photoset) ? 'photoset' : 'photos';
var set = ("photoset" in o) ? 'photoset' : 'photos';
o = checkResponse(o, set);
o.data = o.photo;
delete o.photo;
Expand All @@ -90,6 +90,7 @@ function formatPhotos(o){
photo.thumbnail = getPhoto(photo.id, photo.farm, photo.server, photo.secret, 'm');
}
}
return o;
}
function checkResponse(o, key){

Expand Down Expand Up @@ -124,13 +125,17 @@ function formatFriends(o){

hello.init({
'flickr' : {

name : "Flickr",

// Ensure that you define an oauth_proxy
oauth : {
version : "1.0a",
auth : "http://www.flickr.com/services/oauth/authorize?perms=read",
request : 'http://www.flickr.com/services/oauth/request_token',
token : 'http://www.flickr.com/services/oauth/access_token'
},

logout : function(){
// Function is executed when the user logs out.
user_id = null;
Expand All @@ -140,23 +145,19 @@ hello.init({
// Signin once token expires?
autorefresh : false,

// API base URL
base : "http://api.flickr.com/services/rest",

name : "Flickr",
jsonp: function(p,qs){
if(p.method.toLowerCase() == "get"){
delete qs.callback;
qs.jsoncallback = '?';
}
},
uri : {
base : "http://api.flickr.com/services/rest",
// Map GET resquests
get : {
"me" : sign("flickr.people.getInfo"),
"me/friends": sign("flickr.contacts.getList"),
"me/following": sign("flickr.contacts.getList"),
"me/followers": sign("flickr.contacts.getList"),
"me/albums" : sign("flickr.photosets.getList"),
"me/photos" : sign("flickr.people.getPhotos")
},

wrap : {
me : function(o){
formatError(o);
Expand All @@ -179,7 +180,7 @@ hello.init({
"me/albums" : function(o){
formatError(o);
o = checkResponse(o, "photosets");
if(o.photosets){
if(o.photoset){
o.data = o.photoset;
delete o.photoset;
for(var i=0;i<o.data.length;i++){
Expand All @@ -192,19 +193,22 @@ hello.init({
},
"me/photos" : function(o){
formatError(o);
formatPhotos(o);

return o;
return formatPhotos(o);
},
"default" : function(o){

formatError(o);
formatPhotos(o);

return o;
return formatPhotos(o);
}
},
xhr : false

xhr : false,

jsonp: function(p,qs){
if(p.method.toLowerCase() == "get"){
delete qs.callback;
qs.jsoncallback = p.callbackID;
}
}
}
});
})();
14 changes: 11 additions & 3 deletions src/modules/foursquare.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,25 @@ function formatUser(o){

hello.init({
foursquare : {

name : 'FourSquare',

oauth : {
version : 2,
auth : 'https://foursquare.com/oauth2/authenticate'
},

// Alter the querystring
querystring : function(qs){
var token = qs.access_token;
delete qs.access_token;
qs.oauth_token = token;
qs.v = 20121125;
},
uri : {
auth : 'https://foursquare.com/oauth2/authenticate',
base : 'https://api.foursquare.com/v2/',

base : 'https://api.foursquare.com/v2/',

get : {
'me' : 'users/self',
'me/friends' : 'users/self/friends',
'me/followers' : 'users/self/friends',
Expand Down
6 changes: 3 additions & 3 deletions src/modules/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ hello.init({
name : 'GitHub',
oauth : {
version : 2,
auth : 'https://github.com/login/oauth/authorize',
grant : 'https://github.com/login/oauth/access_token'
},
uri : {
auth : 'https://github.com/login/oauth/authorize',
base : 'https://api.github.com/',
base : 'https://api.github.com/',
get : {
'me' : 'user',
'me/friends' : 'user/following',
'me/following' : 'user/following',
Expand Down
51 changes: 37 additions & 14 deletions src/modules/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,13 @@
}
},

uri : {
// REF: http://code.google.com/apis/accounts/docs/OAuth2UserAgent.html
auth : "https://accounts.google.com/o/oauth2/auth",
// me : "plus/v1/people/me?pp=1",
me : 'oauth2/v1/userinfo?alt=json',
base : "https://www.googleapis.com/",
'me/friends' : 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000',
'me/following' : 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000',
'me/followers' : 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000',
'me/share' : 'plus/v1/people/me/activities/public',
'me/feed' : 'plus/v1/people/me/activities/public',
'me/albums' : 'https://picasaweb.google.com/data/feed/api/user/default?alt=json',
'me/photos' : 'https://picasaweb.google.com/data/feed/api/user/default?alt=json&kind=photo&max-results=100',
"me/files" : 'https://www.googleapis.com/drive/v2/files?q=%22root%22+in+parents'
// REF: http://code.google.com/apis/accounts/docs/OAuth2UserAgent.html
oauth : {
version : 2,
auth : "https://accounts.google.com/o/oauth2/auth"
},

// Authorization scopes
scope : {
//,
basic : "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",
Expand All @@ -188,6 +180,37 @@
offline_access : ''
},
scope_delim : ' ',

// API base URI
base : "https://www.googleapis.com/",

// Map GET requests
get : {
// me : "plus/v1/people/me?pp=1",
'me' : 'oauth2/v1/userinfo?alt=json',
'me/friends' : 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000',
'me/following' : 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000',
'me/followers' : 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000',
'me/share' : 'plus/v1/people/me/activities/public',
'me/feed' : 'plus/v1/people/me/activities/public',
'me/albums' : 'https://picasaweb.google.com/data/feed/api/user/default?alt=json',
'me/album' : function(p,callback){
var key = p.data.id;
delete p.data.id;
callback(key.replace("/entry/", "/feed/"));
},
'me/photos' : 'https://picasaweb.google.com/data/feed/api/user/default?alt=json&kind=photo&max-results=100',
'me/files' : 'drive/v2/files?q=%22root%22+in+parents'
},

post : {
// 'me/albums' : 'https://picasaweb.google.com/data/feed/api/user/default?alt=json'
},

// Map DELETE requests
del : {
},

wrap : {
me : function(o){
if(o.id){
Expand Down
Loading

0 comments on commit 5d651a9

Please sign in to comment.