Class: Wod::Client
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#ask, #display_formatted, #error, #home_directory, #last_page_file, #wod_directory
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
40
41
42
43
|
# File 'lib/wod/client.rb', line 40
def initialize options
@collect_login_deets = options[:collect_login_deets]
@collect_team_selection = options[:collect_team_selection]
end
|
Instance Attribute Details
#collect_login_deets ⇒ Object
Returns the value of attribute collect_login_deets.
39
40
41
|
# File 'lib/wod/client.rb', line 39
def collect_login_deets
@collect_login_deets
end
|
#collect_team_selection ⇒ Object
Returns the value of attribute collect_team_selection.
39
40
41
|
# File 'lib/wod/client.rb', line 39
def collect_team_selection
@collect_team_selection
end
|
Class Method Details
.last_page ⇒ Object
35
36
37
|
# File 'lib/wod/client.rb', line 35
def self.last_page
@@last_page
end
|
Instance Method Details
#agent ⇒ Object
55
56
57
|
# File 'lib/wod/client.rb', line 55
def agent
@agent ||= create_agent
end
|
#cookies_file ⇒ Object
45
46
47
|
# File 'lib/wod/client.rb', line 45
def cookies_file
"#{home_directory}/.wod/cookie_jar"
end
|
#create_agent ⇒ Object
49
50
51
52
53
|
# File 'lib/wod/client.rb', line 49
def create_agent
agent = Mechanize.new
agent.cookie_jar.load cookies_file if File.exists?(cookies_file)
agent
end
|
#get(url) ⇒ Object
99
100
101
102
103
|
# File 'lib/wod/client.rb', line 99
def get url
page = DevCenterPage.new agent.get(url)
page = login_and_reopen(url) unless page.logged_in?
@@last_page = page
end
|
#logged_in? ⇒ Boolean
105
106
107
108
|
# File 'lib/wod/client.rb', line 105
def logged_in?
page = get "https://developer.apple.com/devcenter/ios/index.action"
page.logged_in? && !page.team_selection_page?
end
|
#login_and_reopen(url) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/wod/client.rb', line 81
def login_and_reopen url
page = DevCenterPage.new agent.get("https://developer.apple.com/devcenter/ios/index.action")
unless page.logged_in?
login_at page
page = DevCenterPage.new agent.get url
end
if page.team_selection_page?
select_team_at page
page = DevCenterPage.new agent.get url
end
raise InvalidCredentials unless page.logged_in?
agent.cookie_jar.save_as cookies_file
page
end
|
#login_at(page) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/wod/client.rb', line 59
def login_at page
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.submit
end
|
#select_team_at(page) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/wod/client.rb', line 70
def select_team_at page
f = page.form "saveTeamSelection"
select_list = f.field('memberDisplayId')
teams = select_list.options.map(&:text)
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
|