Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Re-organize code to make the code available through npm.

  • Loading branch information...
commit 6e03694d77ec67bf9a29a07ea3b306f3aab85138 1 parent 541ba5a
@germallon authored
View
14 README.md
@@ -22,11 +22,10 @@ The interface allows you to interact with the API, but it is mainly provided to
Here's an example on how to display the user data on standard output:
<pre>
- var reader = require('./apiReader');
- var writer = require('./apiWriter');
+ var api = require('phonegapbuildapi');
- writer.createAuthToken("my@email.com:myp4ssw0rd", function(token){
- reader.getUserData(token, function(userData){
+ api.createAuthToken("my@email.com:myp4ssw0rd", function(token){
+ api.getUserData(token, function(userData){
console.log(userData); //Output user data to stdout
});
});
@@ -37,14 +36,13 @@ Here's an example on how to display the user data on standard output:
Error handling is supported through callbacks. The above example can be expanded to handle any errors found.
<pre>
- var reader = require('./apiReader');
- var writer = require('./apiWriter');
+ var api = require('phonegapbuildapi');
- writer.createAuthToken("my@email.com:myp4ssw0rd", {
+ api.createAuthToken("my@email.com:myp4ssw0rd", {
success:function(token){
- reader.getUserData(token, {
+ api.getUserData(token, {
success:function(userData){
console.log(userData); //Output user data to stdout
},
View
200 apiWriter.js → api.js
@@ -16,12 +16,191 @@
**************************************************************************/
var
+_URL = 'build.phonegap.com',
_fs = require('fs'),
_https = require('https'),
_mime = require('mime'),
_req = require('request'),
_URL = 'build.phonegap.com'
+/******************************************************************
+ * Executes the GET Phonegap API call,
+ * and writes the output in a JSON-formatted file
+ ******************************************************************/
+getApiData = function(token, apiCall, callback){
+ var
+ options = null;
+
+ options = {
+ host: _URL,
+ path: '/api/v1/' + apiCall + '?auth_token='+token
+ };
+
+ _https.get(options, function(res){
+ var replyData = '';
+ res.on('data', function(data){
+ replyData+= data;
+ });
+ res.on('end', function(){
+ if(callback instanceof Function){
+ callback(JSON.parse(replyData));
+ }
+ else if (callback.success instanceof Function){
+ callback.success(JSON.parse(replyData));
+ }
+ });
+ }).on('error', function(e){
+ console.log("AJAX Err. Message: " + e.message);
+ if(callback.error && (callback.error instanceof Function)){callback.error(e.message);}
+ });
+ },
+
+/******************************************************************
+ * Downloads the file at the given URL and saves it in the provided
+ * path.
+ ******************************************************************/
+downloadFile = function(url, outputFilepath, callback){
+ var successCallback = (callback instanceof Function)? callback: (callback.success instanceof Function)? callback.success: function(){};
+ var errCallback = (callback.error instanceof Function)? callback.error: function(){};
+
+ _req.get(url).pipe(_fs.createWriteStream(outputFilepath))
+ .on('error', function(e){errCallback(e.message);})
+ .on('close', function(){successCallback(outputFilepath)});
+},
+
+/******************************************************************
+ * Get a JSON-encoded representation of the authenticated user,
+ * as well as a listing of associated resources.
+ *
+ * This should be the starting point for applications traversing
+ * the PhoneGap Build API. It is aliased to
+ * https://build.phonegap.com/api/v1.
+ *
+ * GET https://build.phonegap.com/api/v1/me
+ *****************************************************************/
+_getUserData = function(token, callback){
+ getApiData(token, 'me', callback);
+},
+
+/******************************************************************
+ * Get a JSON-encoded representation of the authenticated user's
+ * apps.
+ *
+ * API clients can follow the link attribute for each app to get
+ * further details, including the associated signing keys and
+ * collaborators.
+ *
+ * GET https://build.phonegap.com/api/v1/apps
+ *****************************************************************/
+_getAppsData = function(token, callback){
+ getApiData(token, 'apps', callback);
+ },
+
+
+/******************************************************************
+ * Get a JSON-encoded representation of a particular app, if the
+ * authenticated user has permission to access it.
+ *
+ * In addition to the fields provided in the list of all apps,
+ * this detail view includes:
+ *
+ * keys: all of the keys that the app is currently being built with.
+ * This will include the owner's default key for a platform,
+ * if selected
+ *
+ * collaborators: each person who has access to this app, along
+ * with their role, if the authenticated user is the owner of
+ * the app. Collaborators who are registered with PhoneGap Build
+ * are listed under active; collaborators you have invited who
+ * have not yet created an account are listed as pending.
+ *
+ * GET https://build.phonegap.com/api/v1/apps/:id
+ *****************************************************************/
+_getAppDataById = function(token, appId, callback){
+ getApiData(token, 'apps/' + appId, callback);
+ },
+
+/******************************************************************
+ * Get a JSON-encoded list of all the signing keys associated with
+ * your account.
+ *
+ * This returns a short listing of all the associated keys--it's
+ * very similar to the list you'll see when requesting /api/v1/me
+ *
+ * GET https://build.phonegap.com/api/v1/keys
+ *****************************************************************/
+_getKeysData = function(token, callback){
+ getApiData(token, 'keys', callback);
+ },
+
+
+/******************************************************************
+ * Get a JSON-encoded list of all the signing keys associated with
+ * your account, for a specific platform. That platform can be one
+ * of ios, android, or blackberry.
+ *
+ * GET https://build.phonegap.com/api/v1/keys/:platform
+ *****************************************************************/
+_getPlatformKeys = function(platform){
+ getApiData('keys/' + platform, METADATA_DIR + '/keys_' + platform + '.json');
+ },
+
+/******************************************************************
+ * Get a JSON-encoded representation of a single signing key.
+ *
+ * GET https://build.phonegap.com/api/v1/keys/:platform/:appId
+ *****************************************************************/
+_getPlatformKeyById = function(platform, appId){
+ getApiData('keys/' + platform + '/' + appId, METADATA_DIR + '/keys_' + platform + '_' + appId + '.json');
+ },
+
+/******************************************************************
+ * Download the app package for the given platform; available
+ * platforms are android, blackberry, ios, symbian, webos and
+ * winphone.
+ *
+ * In the successful case, this API method will return a 302
+ * redirect to the application binary - the actual body of the
+ * response will point to the resource's correct location:
+ *
+ * If using the optional argument for the download location,
+ * please ensure that you are using the right extension for
+ * the platform you are downloading.
+ *
+ * apk for Android
+ * ipa for iOS
+ * ipk for webOS
+ * jad for unsigned BlackBerry builds; zip if you've uploaded your BlackBerry signing keys
+ * wgz for Symbian
+ * xap for Windows Phone
+ *
+ * GET https://build.phonegap.com/api/v1/apps/:id/:platform
+ *****************************************************************/
+_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);
+ },
+
+/*****************************************************************
+ * Get the main icon associated with an app - this is either the
+ * biggest icon specified in your config.xml file, or an icon you
+ * have uploaded through the API or the PhoneGap Build web interface.
+ *
+ * GET https://build.phonegap.com/api/v1/apps/:id/:icon
+*****************************************************************/
+_downloadIcon = function(token, appId, outputFilepath, callback){
+ var url= 'https://' + _URL + '/api/v1/apps/' + appId + '/icon';
+ downloadFile(url, outputFilepath, callback);
+ },
+
+/************************************
+ * Init Write API
+ */
+
+
+
+
encodeFieldHeader = function(boundary, name, value){
var result = [
"--" + boundary + "\r\n",
@@ -237,12 +416,27 @@ _createAuthToken = function(rawCredentials, callback){
}
});
}
-;
-
+
+
+
+/******************************************************************
+ * Module Public Members
+ *****************************************************************/
module.exports = {
+ //Read API
+ getUserData: _getUserData,
+ getAppsData: _getAppsData,
+ getAppDataById: _getAppDataById,
+ getKeysData: _getKeysData,
+ getPlatformKeys:_getPlatformKeys,
+ getPlatformKeyById: _getPlatformKeyById,
+ downloadApp: _downloadApp,
+ downloadIcon:_downloadIcon,
+
+ //Write API
createFileBasedApp:_createFileBasedApp,
updateFileBasedApp:_updateFileBasedApp,
uploadAppIcon: _uploadAppIcon,
- createAuthToken: _createAuthToken,
+ createAuthToken: _createAuthToken
};
View
208 apiReader.js
@@ -1,208 +0,0 @@
-/**************************************************************************
- * Copyright (c) 2012 Adtec Productions, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- **************************************************************************/
-
-var
-_URL = 'build.phonegap.com',
-
-
-/******************************************************************
- * Executes the GET Phonegap API call,
- * and writes the output in a JSON-formatted file
- ******************************************************************/
-getApiData = function(token, apiCall, callback){
- var
- https = require('https'),
- options = null;
-
- options = {
- host: _URL,
- path: '/api/v1/' + apiCall + '?auth_token='+token
- };
-
- https.get(options, function(res){
- var replyData = '';
- res.on('data', function(data){
- replyData+= data;
- });
- res.on('end', function(){
- if(callback instanceof Function){
- callback(JSON.parse(replyData));
- }
- else if (callback.success instanceof Function){
- callback.success(JSON.parse(replyData));
- }
- });
- }).on('error', function(e){
- console.log("AJAX Err. Message: " + e.message);
- if(callback.error && (callback.error instanceof Function)){callback.error(e.message);}
- });
- },
-
-/******************************************************************
- * Downloads the file at the given URL and saves it in the provided
- * path.
- ******************************************************************/
-downloadFile = function(url, outputFilepath, callback){
- var successCallback = (callback instanceof Function)? callback: (callback.success instanceof Function)? callback.success: function(){};
- var errCallback = (callback.error instanceof Function)? callback.error: function(){};
- var req = require('request'),
- fs = require('fs');
- req.get(url).pipe(fs.createWriteStream(outputFilepath))
- .on('error', function(e){errCallback(e.message);})
- .on('close', function(){successCallback(outputFilepath)});
-},
-
-/******************************************************************
- * Get a JSON-encoded representation of the authenticated user,
- * as well as a listing of associated resources.
- *
- * This should be the starting point for applications traversing
- * the PhoneGap Build API. It is aliased to
- * https://build.phonegap.com/api/v1.
- *
- * GET https://build.phonegap.com/api/v1/me
- *****************************************************************/
-_getUserData = function(token, callback){
- getApiData(token, 'me', callback);
-},
-
-/******************************************************************
- * Get a JSON-encoded representation of the authenticated user's
- * apps.
- *
- * API clients can follow the link attribute for each app to get
- * further details, including the associated signing keys and
- * collaborators.
- *
- * GET https://build.phonegap.com/api/v1/apps
- *****************************************************************/
-_getAppsData = function(token, callback){
- getApiData(token, 'apps', callback);
- },
-
-
-/******************************************************************
- * Get a JSON-encoded representation of a particular app, if the
- * authenticated user has permission to access it.
- *
- * In addition to the fields provided in the list of all apps,
- * this detail view includes:
- *
- * keys: all of the keys that the app is currently being built with.
- * This will include the owner's default key for a platform,
- * if selected
- *
- * collaborators: each person who has access to this app, along
- * with their role, if the authenticated user is the owner of
- * the app. Collaborators who are registered with PhoneGap Build
- * are listed under active; collaborators you have invited who
- * have not yet created an account are listed as pending.
- *
- * GET https://build.phonegap.com/api/v1/apps/:id
- *****************************************************************/
-_getAppDataById = function(token, appId, callback){
- getApiData(token, 'apps/' + appId, callback);
- },
-
-/******************************************************************
- * Get a JSON-encoded list of all the signing keys associated with
- * your account.
- *
- * This returns a short listing of all the associated keys--it's
- * very similar to the list you'll see when requesting /api/v1/me
- *
- * GET https://build.phonegap.com/api/v1/keys
- *****************************************************************/
-_getKeysData = function(token, callback){
- getApiData(token, 'keys', callback);
- },
-
-
-/******************************************************************
- * Get a JSON-encoded list of all the signing keys associated with
- * your account, for a specific platform. That platform can be one
- * of ios, android, or blackberry.
- *
- * GET https://build.phonegap.com/api/v1/keys/:platform
- *****************************************************************/
-_getPlatformKeys = function(platform){
- getApiData('keys/' + platform, METADATA_DIR + '/keys_' + platform + '.json');
- },
-
-/******************************************************************
- * Get a JSON-encoded representation of a single signing key.
- *
- * GET https://build.phonegap.com/api/v1/keys/:platform/:appId
- *****************************************************************/
-_getPlatformKeyById = function(platform, appId){
- getApiData('keys/' + platform + '/' + appId, METADATA_DIR + '/keys_' + platform + '_' + appId + '.json');
- },
-
-/******************************************************************
- * Download the app package for the given platform; available
- * platforms are android, blackberry, ios, symbian, webos and
- * winphone.
- *
- * In the successful case, this API method will return a 302
- * redirect to the application binary - the actual body of the
- * response will point to the resource's correct location:
- *
- * If using the optional argument for the download location,
- * please ensure that you are using the right extension for
- * the platform you are downloading.
- *
- * apk for Android
- * ipa for iOS
- * ipk for webOS
- * jad for unsigned BlackBerry builds; zip if you've uploaded your BlackBerry signing keys
- * wgz for Symbian
- * xap for Windows Phone
- *
- * GET https://build.phonegap.com/api/v1/apps/:id/:platform
- *****************************************************************/
-_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);
- },
-
-/*****************************************************************
- * Get the main icon associated with an app - this is either the
- * biggest icon specified in your config.xml file, or an icon you
- * have uploaded through the API or the PhoneGap Build web interface.
- *
- * GET https://build.phonegap.com/api/v1/apps/:id/:icon
-*****************************************************************/
-_downloadIcon = function(token, appId, outputFilepath, callback){
- var url= 'https://' + _URL + '/api/v1/apps/' + appId + '/icon';
- downloadFile(url, outputFilepath, callback);
- }
- ;
-
-/******************************************************************
- * Module Public Members
- *****************************************************************/
-module.exports = {
- getUserData: _getUserData,
- getAppsData: _getAppsData,
- getAppDataById: _getAppDataById,
- getKeysData: _getKeysData,
- getPlatformKeys:_getPlatformKeys,
- getPlatformKeyById: _getPlatformKeyById,
- downloadApp: _downloadApp,
- downloadIcon:_downloadIcon
-};
View
15 interface.js
@@ -1,8 +1,7 @@
#!/usr/bin/env node
var
- _apiReader = require('./apiReader'),
- _apiWriter = require('./apiWriter'),
+ _api = require('./phonegapbuildapi'),
_program = require('commander'),
_req = require('request'),
_tools = require('./tools'),
@@ -48,7 +47,7 @@ doMenuOption = function (menuOption){
switch(menuOption){
case _MENU.getUserData.idx:
- _apiReader.getUserData(_token, {success: function(data){
+ _api.getUserData(_token, {success: function(data){
console.log(data);
showMenu();
}, error: stdErrorHandler});
@@ -56,7 +55,7 @@ doMenuOption = function (menuOption){
case _MENU.getAppsData.idx:
- _apiReader.getAppsData(_token, {success: function(data){
+ _api.getAppsData(_token, {success: function(data){
console.log(data);
showMenu();
}, error: stdErrorHandler});
@@ -64,7 +63,7 @@ doMenuOption = function (menuOption){
case _MENU.getAppDataById.idx:
_program.prompt("App ID: ", function(appId){
- _apiReader.getAppDataById(_token, appId, {success: function(data){
+ _api.getAppDataById(_token, appId, {success: function(data){
console.log(data);
showMenu();
}, error: stdErrorHandler});
@@ -72,7 +71,7 @@ doMenuOption = function (menuOption){
break;
case _MENU.getKeysData.idx:
- _apiReader.getKeysData(_token, {success: function(data){
+ _api.getKeysData(_token, {success: function(data){
console.log(data);
showMenu();
}, error: stdErrorHandler});
@@ -88,7 +87,7 @@ doMenuOption = function (menuOption){
_program.choose(platformList, function(platformIdx){
_program.prompt("Output filepath: ", function(outFpath){
- _apiReader.downloadApp(_token, appId, platformList[platformIdx], outFpath, {success: function(data){
+ _api.downloadApp(_token, appId, platformList[platformIdx], outFpath, {success: function(data){
console.log("File successfully downloaded to: " + data);
showMenu();
}, error: stdErrorHandler});
@@ -125,7 +124,7 @@ showMenu = function(){
* Executes login by requesting an authentication token from the server
*****************************************************************/
doLogin = function(loginCredentials){
- _apiWriter.createAuthToken(loginCredentials, {success: function(token){
+ _api.createAuthToken(loginCredentials, {success: function(token){
_token = token;
showMenu();
},
View
19 package.json
@@ -0,0 +1,19 @@
+{ "name" : "phonegapbuildapi"
+, "description" : "A client interface for the Phonegap Build API."
+, "tags" : ["phonegap", "phonegap build", "phonegap build api", "api client"]
+, "version" : "1.0.0"
+, "author" : "German Escallon <germane@adtecinc.com>",
+, "homepage" : "http://github.com/germallon/phonegapbuildapi",
+, "dependencies:{
+ "request": "git://github.com/mikeal/request.git#9746bb4d00851c060d4d20a6860b25101fad1ba5",
+ "mime": "git://github.com/broofa/node-mime.git#640f377e2bdc926e4c5bf47ca0b8aa6767699ed3"
+ }
+, "repository" :
+ { "type" : "git"
+ , "url" : "http://github.com/germallon/phonegapbuildapi.git"
+ }
+, "bugs" :
+ { "url" : "http://github.com/mikeal/phonegapbuildapi/issues" }
+, "engines" : ["node >= 1.2.6"]
+, "main": "./api"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.