wod 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/wod.rb +6 -0
- data/lib/wod/client.rb +37 -10
- data/lib/wod/command.rb +3 -1
- data/lib/wod/commands/auth.rb +21 -4
- data/lib/wod/commands/help.rb +3 -0
- data/lib/wod/commands/version.rb +1 -1
- data/lib/wod/version.rb +1 -1
- metadata +2 -1
data/CHANGELOG
ADDED
data/lib/wod.rb
CHANGED
data/lib/wod/client.rb
CHANGED
@@ -14,6 +14,10 @@ module Wod
|
|
14
14
|
(page.title =~ /sign in/i) == nil && (page.search("span").find {|s| s.text == "Log in"}) == nil
|
15
15
|
end
|
16
16
|
|
17
|
+
def team_selection_page?
|
18
|
+
(page.title =~ /select.*team/i)
|
19
|
+
end
|
20
|
+
|
17
21
|
def search arg
|
18
22
|
@page.search arg
|
19
23
|
end
|
@@ -22,15 +26,18 @@ module Wod
|
|
22
26
|
@page.form arg
|
23
27
|
end
|
24
28
|
end
|
29
|
+
|
25
30
|
|
26
31
|
class Client
|
27
32
|
include Wod::Helpers
|
28
33
|
|
29
34
|
attr_reader :name
|
35
|
+
attr_accessor :team
|
30
36
|
|
31
|
-
def initialize username, password
|
37
|
+
def initialize username, password, team
|
32
38
|
@username = username
|
33
39
|
@password = password
|
40
|
+
@team = team
|
34
41
|
end
|
35
42
|
|
36
43
|
def cookies_file
|
@@ -47,21 +54,41 @@ module Wod
|
|
47
54
|
@agent ||= create_agent
|
48
55
|
end
|
49
56
|
|
57
|
+
def login_at page
|
58
|
+
puts "Creating session"
|
59
|
+
|
60
|
+
login_page = page.page.links.find { |l| l.text == 'Log in'}.click
|
61
|
+
|
62
|
+
f = login_page.form("appleConnectForm")
|
63
|
+
f.theAccountName = @username
|
64
|
+
f.theAccountPW = @password
|
65
|
+
f.submit
|
66
|
+
end
|
67
|
+
|
68
|
+
def select_team_at page
|
69
|
+
raise NoTeamSelected.new(page.search("select[name='memberDisplayId'] option").map{|o| {:name => o.text, :value => o[:value]} }) unless self.team
|
70
|
+
f = page.page.form("saveTeamSelection")
|
71
|
+
select_list = f.fields.first
|
72
|
+
select_list.value = self.team
|
73
|
+
|
74
|
+
DevCenterPage.new f.click_button f.button_with(:value => /continue/i)
|
75
|
+
end
|
76
|
+
|
50
77
|
def login_and_reopen url
|
51
78
|
page = DevCenterPage.new agent.get("https://developer.apple.com/devcenter/ios/index.action")
|
52
79
|
|
53
80
|
unless page.logged_in?
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
81
|
+
login_at page
|
82
|
+
page = DevCenterPage.new agent.get url
|
83
|
+
end
|
84
|
+
|
85
|
+
if page.team_selection_page?
|
86
|
+
select_team_at page
|
87
|
+
page = DevCenterPage.new agent.get url
|
61
88
|
end
|
62
89
|
|
63
|
-
page = DevCenterPage.new agent.get url
|
64
90
|
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?
|
65
92
|
agent.cookie_jar.save_as cookies_file
|
66
93
|
page
|
67
94
|
end
|
@@ -74,7 +101,7 @@ module Wod
|
|
74
101
|
|
75
102
|
def logged_in?
|
76
103
|
page = get "https://developer.apple.com/devcenter/ios/index.action"
|
77
|
-
page.logged_in?
|
104
|
+
page.logged_in? && !page.team_selection_page?
|
78
105
|
end
|
79
106
|
|
80
107
|
end
|
data/lib/wod/command.rb
CHANGED
data/lib/wod/commands/auth.rb
CHANGED
@@ -5,7 +5,7 @@ module Wod::Command
|
|
5
5
|
attr_accessor :credentials
|
6
6
|
|
7
7
|
def client
|
8
|
-
@client = Wod::Client.new(user, password)
|
8
|
+
@client = Wod::Client.new(user, password, team)
|
9
9
|
end
|
10
10
|
|
11
11
|
# just a stub; will raise if not authenticated
|
@@ -18,13 +18,20 @@ module Wod::Command
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def user
|
21
|
-
|
22
|
-
@credentials[0]
|
21
|
+
credential 0
|
23
22
|
end
|
24
23
|
|
25
24
|
def password
|
25
|
+
credential 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def team
|
29
|
+
credential 2
|
30
|
+
end
|
31
|
+
|
32
|
+
def credential index
|
26
33
|
get_credentials
|
27
|
-
@credentials[
|
34
|
+
@credentials && @credentials.size > index ? @credentials[index] : nil
|
28
35
|
end
|
29
36
|
|
30
37
|
def credentials_file
|
@@ -83,6 +90,16 @@ module Wod::Command
|
|
83
90
|
puts "Authentication failed."
|
84
91
|
return if retry_login?
|
85
92
|
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
|
86
103
|
end
|
87
104
|
end
|
88
105
|
|
data/lib/wod/commands/help.rb
CHANGED
data/lib/wod/commands/version.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.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dave Newman
|
@@ -35,6 +35,7 @@ extra_rdoc_files: []
|
|
35
35
|
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
|
+
- CHANGELOG
|
38
39
|
- Gemfile
|
39
40
|
- README.md
|
40
41
|
- Rakefile
|