This repository has been archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ua.js
109 lines (81 loc) · 1.98 KB
/
ua.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var config = require('./config.js');
var casper = require('casper').create({
verbose: !!config.verbose,
logLevel: config.log_level || "info"
});
var existing_apps = {};
casper.start('https://go.urbanairship.com/accounts/login/', function(){
var form_data = {
username: config.username,
password: config.password
};
console.log('Logging in...');
this.fill('form[name="login"]', form_data, true);
});
casper.then(function(){}); // Not really sure why I needed to add this.. maybe because of a re-direct?
casper.then(function(){
if(this.getTitle().match(/Login/))
{
console.error('Incorrect Username/Password');
this.exit();
}
else
{
console.log('Login successful.');
}
});
casper.thenOpen('https://go.urbanairship.com/apps/', function(){
var apps = this.evaluate(function(){
var apps = {};
$('.main-app-list div.app-meta').each(function(i,el){
var $el = $(el);
var title = $el.find('h3').text();
var mode = 'development';
if($el.find('.meta-prod').length > 0)
{
mode = 'production';
}
apps[title+'-'+mode] = {
title: title,
mode: mode
};
});
return apps;
});
existing_apps = apps;
});
casper.then(function(){
config.apps_to_create.forEach(function(app){
var key = app[0]+'-'+app[1];
if(!(key in existing_apps))
{
console.log('Queueing creation of app '+key);
(function(){
var app_to_create = app;
casper.thenOpen('https://go.urbanairship.com/apps/new/', function(){
console.log('Creating app '+app[0]+' - ' + app[1]);
var form_data = {
name: app_to_create[0],
mode: app_to_create[1],
};
var self = this;
this.evaluate(function(){
jQuery('#id_platforms_ios').click();
jQuery('#id_platforms_android').click();
});
this.fill('form.module', form_data, true);
})
casper.then(function(){
});
})();
}
else
{
console.log('App '+key+' already exists. Skipping');
}
});
});
casper.then(function(){
console.log('Done!');
});
casper.run();