lib/wod/client.rb in wod-0.0.2 vs lib/wod/client.rb in wod-0.0.3
- old
+ new
@@ -29,17 +29,18 @@
class Client
include Wod::Helpers
- attr_reader :name
- attr_accessor :team
+ def self.last_page
+ @@last_page
+ end
- def initialize username, password, team
- @username = username
- @password = password
- @team = team
+ attr_reader :collect_login_deets, :collect_team_selection
+ def initialize options
+ @collect_login_deets = options[:collect_login_deets]
+ @collect_team_selection = options[:collect_team_selection]
end
def cookies_file
"#{home_directory}/.wod/cookie_jar"
end
@@ -53,27 +54,29 @@
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
+ username, password = collect_login_deets.call
+
f = login_page.form("appleConnectForm")
- f.theAccountName = @username
- f.theAccountPW = @password
+ 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
+ f = page.form "saveTeamSelection"
+ select_list = f.field('memberDisplayId')
+ teams = select_list.options.map(&:text)
- DevCenterPage.new f.click_button f.button_with(:value => /continue/i)
+ selected_team = collect_team_selection.call(teams)
+ select_list.option_with(:text => selected_team).select
+
+ 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")
@@ -86,18 +89,17 @@
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
page = DevCenterPage.new agent.get(url)
page = login_and_reopen(url) unless page.logged_in?
- page
+ @@last_page = page
end
def logged_in?
page = get "https://developer.apple.com/devcenter/ios/index.action"
page.logged_in? && !page.team_selection_page?
\ No newline at end of file