Class: Wod::Client

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/wod/client.rb

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_deetsObject (readonly)

Returns the value of attribute collect_login_deets.



39
40
41
# File 'lib/wod/client.rb', line 39

def 
  @collect_login_deets
end

#collect_team_selectionObject (readonly)

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_pageObject



35
36
37
# File 'lib/wod/client.rb', line 35

def self.last_page
  @@last_page
end

Instance Method Details

#agentObject



55
56
57
# File 'lib/wod/client.rb', line 55

def agent
  @agent ||= create_agent
end

#cookies_fileObject



45
46
47
# File 'lib/wod/client.rb', line 45

def cookies_file
  "#{home_directory}/.wod/cookie_jar"
end

#create_agentObject



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 = (url) unless page.logged_in?
  @@last_page = page
end

#logged_in?Boolean

Returns:

  • (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

Raises:



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  url
  page = DevCenterPage.new agent.get("https://developer.apple.com/devcenter/ios/index.action")

  unless page.logged_in?
     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  page
   = page.page.links.find { |l| l.text == 'Log in'}.click

  username, password = .call

  f = .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