wod 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/bin/wod +9 -2
- data/lib/wod.rb +0 -6
- data/lib/wod/client.rb +19 -17
- data/lib/wod/command.rb +8 -3
- data/lib/wod/commands/auth.rb +19 -15
- data/lib/wod/helpers.rb +8 -0
- data/lib/wod/version.rb +1 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
data/bin/wod
CHANGED
@@ -4,8 +4,15 @@ $:.unshift File.join File.dirname(__FILE__), '../lib'
|
|
4
4
|
|
5
5
|
require "wod"
|
6
6
|
|
7
|
-
args =
|
8
|
-
|
7
|
+
args = []
|
8
|
+
options = []
|
9
|
+
|
10
|
+
ARGV.each do |a|
|
11
|
+
a =~ /^-/ ? options << a : args << a
|
12
|
+
end
|
13
|
+
|
9
14
|
command = args.shift.strip rescue 'help'
|
10
15
|
|
16
|
+
ARGV.clear
|
17
|
+
|
11
18
|
Wod::Command.run command, args
|
data/lib/wod.rb
CHANGED
data/lib/wod/client.rb
CHANGED
@@ -31,13 +31,14 @@ module Wod
|
|
31
31
|
class Client
|
32
32
|
include Wod::Helpers
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
def self.last_page
|
35
|
+
@@last_page
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
@
|
40
|
-
@
|
38
|
+
attr_reader :collect_login_deets, :collect_team_selection
|
39
|
+
def initialize options
|
40
|
+
@collect_login_deets = options[:collect_login_deets]
|
41
|
+
@collect_team_selection = options[:collect_team_selection]
|
41
42
|
end
|
42
43
|
|
43
44
|
def cookies_file
|
@@ -55,23 +56,25 @@ module Wod
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def login_at page
|
58
|
-
puts "Creating session"
|
59
|
-
|
60
59
|
login_page = page.page.links.find { |l| l.text == 'Log in'}.click
|
61
60
|
|
61
|
+
username, password = collect_login_deets.call
|
62
|
+
|
62
63
|
f = login_page.form("appleConnectForm")
|
63
|
-
f.theAccountName =
|
64
|
-
f.theAccountPW =
|
64
|
+
f.theAccountName = username
|
65
|
+
f.theAccountPW = password
|
65
66
|
f.submit
|
66
67
|
end
|
67
68
|
|
68
69
|
def select_team_at page
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
select_list.value = self.team
|
70
|
+
f = page.form "saveTeamSelection"
|
71
|
+
select_list = f.field('memberDisplayId')
|
72
|
+
teams = select_list.options.map(&:text)
|
73
73
|
|
74
|
-
|
74
|
+
selected_team = collect_team_selection.call(teams)
|
75
|
+
select_list.option_with(:text => selected_team).select
|
76
|
+
|
77
|
+
f.click_button f.button_with(:value => /continue/i)
|
75
78
|
end
|
76
79
|
|
77
80
|
def login_and_reopen url
|
@@ -88,7 +91,6 @@ module Wod
|
|
88
91
|
end
|
89
92
|
|
90
93
|
raise InvalidCredentials unless page.logged_in?
|
91
|
-
raise NoTeamSelected.new(page.search("select[name='memberDisplayId'] option").map{|o| {:name => o.text, :value => o[:value]} }) if page.team_selection_page?
|
92
94
|
agent.cookie_jar.save_as cookies_file
|
93
95
|
page
|
94
96
|
end
|
@@ -96,7 +98,7 @@ module Wod
|
|
96
98
|
def get url
|
97
99
|
page = DevCenterPage.new agent.get(url)
|
98
100
|
page = login_and_reopen(url) unless page.logged_in?
|
99
|
-
page
|
101
|
+
@@last_page = page
|
100
102
|
end
|
101
103
|
|
102
104
|
def logged_in?
|
data/lib/wod/command.rb
CHANGED
@@ -23,9 +23,14 @@ module Wod
|
|
23
23
|
else
|
24
24
|
error "Authentication failure"
|
25
25
|
end
|
26
|
-
rescue
|
27
|
-
|
28
|
-
|
26
|
+
rescue Exception => e
|
27
|
+
File.open(last_page_file, 'w') do |f|
|
28
|
+
f.chmod(0600)
|
29
|
+
f.puts Client.last_page.page.send(:html_body)
|
30
|
+
end
|
31
|
+
puts "Error: Last page saved to #{last_page_file}"
|
32
|
+
|
33
|
+
raise e
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
data/lib/wod/commands/auth.rb
CHANGED
@@ -5,7 +5,8 @@ module Wod::Command
|
|
5
5
|
attr_accessor :credentials
|
6
6
|
|
7
7
|
def client
|
8
|
-
@client = Wod::Client.new
|
8
|
+
@client = Wod::Client.new :collect_login_deets => lambda { [user, password] },
|
9
|
+
:collect_team_selection => lambda { |team_names| team || collect_team_selection(team_names) }
|
9
10
|
end
|
10
11
|
|
11
12
|
# just a stub; will raise if not authenticated
|
@@ -90,19 +91,22 @@ module Wod::Command
|
|
90
91
|
puts "Authentication failed."
|
91
92
|
return if retry_login?
|
92
93
|
exit 1
|
93
|
-
rescue ::Wod::NoTeamSelected => e
|
94
|
-
teams = e.teams
|
95
|
-
puts "This account belongs to the following teams:"
|
96
|
-
puts teams.map.with_index{|t, i| "#{i+1}. #{t[:name]}"}.join("\n")
|
97
|
-
STDOUT << "Select team [1]: "
|
98
|
-
selection = gets.strip
|
99
|
-
selection = "1" if selection.empty? || selection.to_i == 0
|
100
|
-
client.team = @credentials[2] = teams[selection.to_i-1][:value]
|
101
|
-
write_credentials
|
102
|
-
# check
|
103
94
|
end
|
104
95
|
end
|
105
96
|
|
97
|
+
def collect_team_selection team_names
|
98
|
+
puts "This account belongs to the following teams:"
|
99
|
+
team_names.each.with_index do |team, i|
|
100
|
+
puts "#{i+1}. #{team}"
|
101
|
+
end
|
102
|
+
print "Select team (1): "
|
103
|
+
selection = ask
|
104
|
+
selection = "1" if selection.empty? || selection.to_i == 0
|
105
|
+
@credentials[2] = team_names[selection.to_i-1]
|
106
|
+
write_credentials
|
107
|
+
@credentials[2]
|
108
|
+
end
|
109
|
+
|
106
110
|
def retry_login?
|
107
111
|
@login_attempts ||= 0
|
108
112
|
@login_attempts += 1
|
@@ -111,10 +115,10 @@ module Wod::Command
|
|
111
115
|
|
112
116
|
def write_credentials
|
113
117
|
FileUtils.mkdir_p(File.dirname(credentials_file))
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
+
File.open(credentials_file, 'w') do |f|
|
119
|
+
f.chmod(0600)
|
120
|
+
f.puts self.credentials
|
121
|
+
end
|
118
122
|
set_credentials_permissions
|
119
123
|
end
|
120
124
|
|
data/lib/wod/helpers.rb
CHANGED
data/lib/wod/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: wod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dave Newman
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-02 00:00:00 +11:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|