Skip to content

Commit

Permalink
Starting preliminary work. Encouraged.
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrence Ryan committed Jun 18, 2012
1 parent e60582a commit 93c5633
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ There are also some things that might be nice, but aren't necessary:
* Prompt for download of apps
* Allow PhoneGap Build Management

Things that we will have to figure out:

* Granting read/write access to PhoneGap Build through Brackets
* Maintaining read/write access to PhoneGap Build through Brackets
40 changes: 40 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */

/** Simple extension that adds a "File > Hello World" menu item */
define(function (require, exports, module) {
'use strict';

var CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus");

// Local modules
require('phonegapbuild');
var phonegapbuild = new PhoneGapBuild();
//hardcode for now. Eventually, we'll save the token in local storage.
phonegapbuild.getToken("", "");


// Function to run when the menu item is clicked
function handlePGList() {
var list = "";
for (var i = 0; i < phonegapbuild.list.length; i++){
list += phonegapbuild.list[i].title + ", ";
}


window.alert(list);
}


// First, register a command - a UI-less object associating an id to a handler
var PG_LIST = "PhoneGap.list";
CommandManager.register("List Build Projects", PG_LIST, handlePGList);

// Then create a menu item bound to the command
// The label of the menu item is the name we gave the command (see above)
var menu;
menu = Menus.addMenu("PhoneGap", "tpryan.phonegap.phonegap");
menu.addMenuItem(PG_LIST);

});
74 changes: 74 additions & 0 deletions phonegapbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

var PhoneGapBuild = function() {

var URL_BASE = "https://build.phonegap.com";
var URL_TOKEN = URL_BASE + "/token";
var URL_LIST = URL_BASE + "/api/v1/apps";

var self = this;

this.token = "";
this.list ="List of PhoneGap Build projects."
this.getToken = getToken;
this.getList = getList;


function setToken(token){
self.token = token;
console.log(this);
}

function setList(list){
self.list = list;
}

function getToken(username,password){
console.log(this);
$.ajax({
url: URL_TOKEN,
type:"post",
error: errorHandler,
context: PhoneGapBuild,
success: handleTokenSuccess,
username: username,
password: password,
cache:false,
crossDomain:true
});
}

function handleTokenSuccess(response, status, jqXHR){
console.log("Token Retreived");
console.log(response);
setToken(response.token);
getList();
}

function errorHandler(error){
console.log("Login Error");
console.log(error.responseText);
}

function getList(){
$.ajax({
url: URL_LIST + "?auth_token=" + this.token,
success: handleListSuccess,
dataType: 'jsonp',
type:"get",
error: errorHandler,
cache:false,
crossDomain:true
});
}

function handleListSuccess(response, status, jqXHR){
console.log("List Retreived");
console.log(response.apps);
setList(response.apps);
}





}

0 comments on commit 93c5633

Please sign in to comment.