def devices
if !@thedevices
authurl="https://auth.apple.com/authenticate?service=DockStatus&realm=primary-me&formID=loginForm&username=#{@username}&password=#{@password}&returnURL=aHR0cHM6Ly9zZWN1cmUubWUuY29tL3dvL1dlYk9iamVjdHMvRG9ja1N0YXR1cy53b2Evd2EvdHJhbXBvbGluZT9kZXN0aW5hdGlvblVybD0vYWNjb3VudA%3D%3D"
page = @agent.get(authurl)
@isc = @agent.cookie_jar.cookies(URI.parse("https://secure.me.com")).select { |c| c.name == 'isc-secure.me.com' }[0].value
devicesurl = "https://secure.me.com/wo/WebObjects/DeviceMgmt.woa/?lang=en"
@agent.pre_connect_hooks << lambda { |params|
params[:request]['X-Mobileme-Version'] = '1.0'
params[:request]['X-Mobileme-Isc'] = @isc
params[:request]['X-Requested-With'] = 'XMLHttpRequest'
params[:request]['Accept'] = 'text/javascript, text/html, application/xml, text/xml, */*'
}
page = @agent.post(devicesurl)
@thedevices = page.content.match(/tDeviceMgmt.deviceIdMap\['[0-9+]'\] = '([^']+)'/).captures
end
return @thedevices
end