lib/wod/client.rb in wod-0.0.1 vs lib/wod/client.rb in wod-0.0.2
- old
+ new
@@ -12,27 +12,34 @@
def logged_in?
(page.title =~ /sign in/i) == nil && (page.search("span").find {|s| s.text == "Log in"}) == nil
end
+ def team_selection_page?
+ (page.title =~ /select.*team/i)
+ end
+
def search arg
@page.search arg
end
def form arg
@page.form arg
end
end
+
class Client
include Wod::Helpers
attr_reader :name
+ attr_accessor :team
- def initialize username, password
+ def initialize username, password, team
@username = username
@password = password
+ @team = team
end
def cookies_file
"#{home_directory}/.wod/cookie_jar"
end
@@ -45,25 +52,45 @@
def agent
@agent ||= create_agent
end
+ def login_at page
+ puts "Creating session"
+
+ login_page = page.page.links.find { |l| l.text == 'Log in'}.click
+
+ f = login_page.form("appleConnectForm")
+ f.theAccountName = @username
+ f.theAccountPW = @password
+ f.submit
+ end
+
+ def select_team_at page
+ raise NoTeamSelected.new(page.search("select[name='memberDisplayId'] option").map{|o| {:name => o.text, :value => o[:value]} }) unless self.team
+ f = page.page.form("saveTeamSelection")
+ select_list = f.fields.first
+ select_list.value = self.team
+
+ DevCenterPage.new f.click_button f.button_with(:value => /continue/i)
+ end
+
def login_and_reopen url
page = DevCenterPage.new agent.get("https://developer.apple.com/devcenter/ios/index.action")
unless page.logged_in?
- puts "Creating session"
- login_page = page.page.links.find { |l| l.text == 'Log in'}.click
-
- f = login_page.form("appleConnectForm")
- f.theAccountName = @username
- f.theAccountPW = @password
- f.submit
+ login_at page
+ page = DevCenterPage.new agent.get url
end
- page = DevCenterPage.new agent.get url
+ if page.team_selection_page?
+ select_team_at page
+ page = DevCenterPage.new agent.get url
+ end
+
raise InvalidCredentials unless page.logged_in?
+ raise NoTeamSelected.new(page.search("select[name='memberDisplayId'] option").map{|o| {:name => o.text, :value => o[:value]} }) if page.team_selection_page?
agent.cookie_jar.save_as cookies_file
page
end
def get url
@@ -72,10 +99,10 @@
page
end
def logged_in?
page = get "https://developer.apple.com/devcenter/ios/index.action"
- page.logged_in?
+ page.logged_in? && !page.team_selection_page?
end
end
end
\ No newline at end of file