-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurbapp.rb
executable file
·84 lines (66 loc) · 3 KB
/
urbapp.rb
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
require 'rubygems'
require 'commander/import'
require 'watir-webdriver'
require 'headless'
require 'json'
program :version, '0.0.1'
program :description, 'CRUD Urban Airship Apps'
command :new do |c|
c.syntax = 'urbapp new [options]'
c.summary = 'Create a new app'
c.description = 'Creates a new Urban Airship app using passed in options'
c.example 'Production App with Headless browser', 'new --username myUsern0me --password P0ny --name "Awesome Pocahontas" --certificate /path/to/certificate.cer --certificate-password mySecretC3rt --headless'
c.example 'Development App', 'new --username myUsern0me --password P0ny --name "Awesome Pocahontas" --development'
c.option '--username USERNAME', String, 'Urban Airship Username'
c.option '--password PASSWORD', String, 'Urban Airship Password'
c.option '--name NAME', String, 'Application name'
c.option '--certificate PATH', String, 'Path to certificate eg. /path/to/certificate.p12'
c.option '--certificate-password PASSWORD', String, 'Certificate password'
c.option '--headless', 'Run a headless browser using Xvfb'
c.option '--development', 'Creates a development certificate, skip --certificate, --certificate-password'
c.option '--respond-with FORMAT', String, 'Responds with specified format. eg. --respond-with json'
c.action do |args, options|
if options.headless
headless = Headless.new
headless = headless.start
end
b = Watir::Browser.new :firefox
b.goto 'https://go.urbanairship.com/accounts/login/'
b.text_field(:id => 'id_username').set(options.username)
b.text_field(:id => 'id_password').set(options.password)
b.input(:xpath, "//input[@value='Log In']").click
b.goto 'https://go.urbanairship.com/apps/new'
b.text_field(:id => 'id_name').set(options.name)
if options.development
b.select_list(:id => "id_mode").select_value 'development'
else
b.select_list(:id => 'id_mode').select_value 'production'
end
b.select_list(:id => 'id_category').select 'Newsstand'
b.checkbox(:id => 'id_push_enabled').set
b.file_field(:id => 'id_certificate').set(options.certificate)
b.text_field(:id => 'id_certificate_password').set(options.certificate_password)
b.button(:value => 'Create your application').click
b.link(:id => 'app_secret_show').click
b.link(:id => 'app_master_secret_show').click
b.link(:xpath, "//a[@id='app_master_secret_hide' and @style='display: inline;']").wait_until_present
app_key = b.dd(:id => 'app_key').text
app_secret = b.span(:id => 'app_secret').text
app_master_secret = b.span(:id => 'app_master_secret').text
if options.respond_with == 'json'
say JSON({app_key: app_key, app_secret: app_secret, app_master_secret: app_master_secret})
else
say "-------------------------------------------"
say "App Key: #{app_key}"
say "App Secret: #{app_secret}"
say "App Master Secret: #{app_master_secret}"
say "-------------------------------------------"
end
begin
b.close
headless.destroy
rescue
# ;-)
end
end
end