Permalink
Browse files

Enforced consistent naming conventions, and enhanced example interface.

  • Loading branch information...
1 parent 8a0a076 commit bbbb2958ed4f3a979ad3162a7ad6637256151039 @germallon committed Jun 22, 2012
Showing with 55 additions and 49 deletions.
  1. +16 −13 apiReader.js
  2. +8 −9 apiWriter.js
  3. +6 −15 interface.js
  4. +25 −12 tools.js
View
@@ -76,7 +76,7 @@ downloadFile = function(url, outputFilepath, callback){
*
* GET https://build.phonegap.com/api/v1/me
*****************************************************************/
-getUser = function(token, callback){
+_getUserData = function(token, callback){
getApiData(token, 'me', callback);
},
@@ -90,7 +90,7 @@ getUser = function(token, callback){
*
* GET https://build.phonegap.com/api/v1/apps
*****************************************************************/
-getApps = function(token, callback){
+_getAppsData = function(token, callback){
getApiData(token, 'apps', callback);
},
@@ -114,7 +114,7 @@ getApps = function(token, callback){
*
* GET https://build.phonegap.com/api/v1/apps/:id
*****************************************************************/
-getAppById = function(token, appId, callback){
+_getAppDataById = function(token, appId, callback){
getApiData(token, 'apps/' + appId, callback);
},
@@ -127,7 +127,7 @@ getAppById = function(token, appId, callback){
*
* GET https://build.phonegap.com/api/v1/keys
*****************************************************************/
-getKeys = function(token, callback){
+_getKeysData = function(token, callback){
getApiData(token, 'keys', callback);
},
@@ -139,7 +139,7 @@ getKeys = function(token, callback){
*
* GET https://build.phonegap.com/api/v1/keys/:platform
*****************************************************************/
-getPlatformKeys = function(platform){
+_getPlatformKeys = function(platform){
getApiData('keys/' + platform, METADATA_DIR + '/keys_' + platform + '.json');
},
@@ -148,7 +148,7 @@ getPlatformKeys = function(platform){
*
* GET https://build.phonegap.com/api/v1/keys/:platform/:appId
*****************************************************************/
-getPlatformKeyById = function(platform, appId){
+_getPlatformKeyById = function(platform, appId){
getApiData('keys/' + platform + '/' + appId, METADATA_DIR + '/keys_' + platform + '_' + appId + '.json');
},
@@ -174,7 +174,7 @@ getPlatformKeyById = function(platform, appId){
*
* GET https://build.phonegap.com/api/v1/apps/:id/:platform
*****************************************************************/
-downloadApp = function(token, appId, platform, outputFilepath, callback){
+_downloadApp = function(token, appId, platform, outputFilepath, callback){
var url= 'https://' + _URL + '/api/v1/apps/' + appId + '/' + platform + '?auth_token='+token;
console.info("\n\nStarting Download...");
downloadFile(url, outputFilepath, callback);
@@ -187,7 +187,7 @@ downloadApp = function(token, appId, platform, outputFilepath, callback){
*
* GET https://build.phonegap.com/api/v1/apps/:id/:icon
*****************************************************************/
-downloadIcon = function(token, appId, outputFilepath, callback){
+_downloadIcon = function(token, appId, outputFilepath, callback){
var url= 'https://' + _URL + '/api/v1/apps/' + appId + '/icon';
downloadFile(url, outputFilepath, callback);
}
@@ -197,9 +197,12 @@ downloadIcon = function(token, appId, outputFilepath, callback){
* Module Public Members
*****************************************************************/
module.exports = {
- getUserData: getUser,
- getAppsData: getApps,
- getAppDataById: getAppById,
- getKeysData: getKeys,
- downloadApp: downloadApp
+ getUserData: _getUserData,
+ getAppsData: _getAppsData,
+ getAppDataById: _getAppDataById,
+ getKeysData: _getKeysData,
+ getPlatformKeys:_getPlatformKeys,
+ getPlatformKeyById: _getPlatformKeyById,
+ downloadApp: _downloadApp,
+ downloadIcon:_downloadIcon
};
View
@@ -138,7 +138,7 @@ initMultipartUpload = function(token, inputFile, reqData, apiCall, fieldName, ca
*
* POST https://build.phonegap.com/api/v1/apps
*****************************************************************/
-createFileBasedApp = function(token, inputFile, dataObj, callback){
+_createFileBasedApp = function(token, inputFile, dataObj, callback){
initMultipartUpload(token, inputFile, dataObj, 'apps', "file", callback);
},
@@ -151,7 +151,7 @@ createFileBasedApp = function(token, inputFile, dataObj, callback){
*
* PUT https://build.phonegap.com/api/v1/apps/:id
*****************************************************************/
-updateFileBasedApp = function(token, inputFile, appId, callback){
+_updateFileBasedApp = function(token, inputFile, appId, callback){
var apiPath = '/api/v1/apps/' + appId + '?auth_token=' + token;
_fs.createReadStream(inputFile).pipe(_req.put('https://build.phonegap.com' + apiPath))
.on('error', function(e){callback.error(e.message);})
@@ -172,7 +172,7 @@ updateFileBasedApp = function(token, inputFile, appId, callback){
* The response will have a 201 created status, and the
* application will be queued for building.
******************************************************************/
-uploadAppIcon = function(token, appId, inputFile, callback){
+_uploadAppIcon = function(token, appId, inputFile, callback){
initMultipartUpload(token, inputFile, null, 'apps/' + appId + "/icon", "icon", callback);
},
@@ -197,7 +197,7 @@ uploadAppIcon = function(token, appId, inputFile, callback){
//
//},
-createToken = function(rawCredentials, callback){
+_createAuthToken = function(rawCredentials, callback){
var
auth = "Basic " + new Buffer(rawCredentials).toString("base64"),
options = {
@@ -220,9 +220,8 @@ createToken = function(rawCredentials, callback){
module.exports = {
- createFileBasedApp:createFileBasedApp,
- updateFileBasedApp:updateFileBasedApp,
- uploadAppIcon: uploadAppIcon,
-// rebuildApp: rebuildApp,
- createAuthToken: createToken,
+ createFileBasedApp:_createFileBasedApp,
+ updateFileBasedApp:_updateFileBasedApp,
+ uploadAppIcon: _uploadAppIcon,
+ createAuthToken: _createAuthToken,
};
View
21 interface.js 100644 → 100755
@@ -1,8 +1,11 @@
+#!/usr/bin/env node
+
var
_apiReader = require('./apiReader'),
_apiWriter = require('./apiWriter'),
_program = require('commander'),
_req = require('request'),
+ _tools = require('./tools'),
URL = 'https://build.phonegap.com',
_MENU =
@@ -15,15 +18,6 @@ var
quit: {name: "Quit", idx: 5}
},
- _PLATFORMLIST = {
- android: {name:"android", idx: 0},
- blackberry: {name:"blackberry", idx: 1},
- ios: {name:"ios", idx: 2},
- symbian: {name:"symbian", idx: 3},
- webos: {name:"webos", idx: 4},
- winphone: {name:"winphone", idx: 5}
- },
-
_token = null,
/******************************************************************
@@ -87,8 +81,8 @@ doMenuOption = function (menuOption){
_program.prompt("App ID: ", function(appId){
- var platformList=[], platformKeys = Object.keys(_PLATFORMLIST);
- for(i=0; i<platformKeys.length; i++){platformList.push(_PLATFORMLIST[platformKeys[i]].name);}
+ var platformList=[], platformKeys = Object.keys(_tools.platforms);
+ for(i=0; i<platformKeys.length; i++){platformList.push(_tools.platforms[platformKeys[i]].name);}
console.log('\nPlatform:');
_program.choose(platformList, function(platformIdx){
@@ -102,9 +96,6 @@ doMenuOption = function (menuOption){
});
});
-
-
-
break;
case _MENU.quit.idx:
@@ -139,7 +130,7 @@ doLogin = function(loginCredentials){
showMenu();
},
error: function(errMsg){
- stdErrorHandler(errmsg);
+ stdErrorHandler(errMsg);
quit();
}});
},
View
@@ -15,24 +15,37 @@
* limitations under the License.
**************************************************************************/
+var
+_platforms = {
+ android: {name:"android", ext: 'apk', idx: 0},
+ blackberry: {name:"blackberry", ext: 'jad', idx: 1}, //signed. Extension for unsigned blackberry applications is 'zip'
+ ios: {name:"ios", ext: 'ipa', idx: 2},
+ symbian: {name:"symbian", ext: 'wgz', idx: 3},
+ webos: {name:"webos", ext: 'ipk', idx: 4},
+ winphone: {name:"winphone", ext: 'xap', idx: 5}
+},
/*
* Returns The extension for the given platform
*/
-var getExtByPlatform = function(platform){
+_getExtByPlatform = function(platformName){
var result = 'ext'; //default extension
- if(platform){ //prevent errors
- switch(platform){
- case 'android': result = 'apk'; break;
- case 'blackberry': result = 'jad'; break;//unsigned. Extension for unsigned blackberry applications is 'zip'
- case 'ios': result = 'ipa'; break;
- case 'symbian': result = 'wgz'; break;
- case 'webos': result = 'ipk'; break;
- case 'winphone': result = 'xap'; break;
- }
+ if(platformName){ //prevent errors
+ switch(platformName){
+ case 'android':
+ case 'blackberry':
+ case 'ios':
+ case 'symbian':
+ case 'webos':
+ case 'winphone':
+ result = _platforms[platformName].ext;
+ break;
+ }
}
return result;
-};
+}
+;
module.exports = {
- getExtByPlatform: getExtByPlatform
+ platforms: _platforms,
+ getExtByPlatform: _getExtByPlatform
};

0 comments on commit bbbb295

Please sign in to comment.