lib/omudid/portal_agent.rb in omudid-1.0.6 vs lib/omudid/portal_agent.rb in omudid-1.0.7

- old
+ new

@@ -1,11 +1,56 @@ +require 'keychain' + module OneMoreUDID class PortalAgent attr_accessor :agent + attr_accessor :username, :password - def get_teams(username, password) + def login(username, password) + if username != nil and password != nil + self.username, self.password = username, password + return + end + + accounts = Keychain.generic_password_items.select { |item| item.label == "omudid" } + username = password = nil + if accounts and accounts.count > 0 + choice = choose 'Select an account to use:', *accounts.collect{ |account| account.account }.push('New account').push('Delete account') + case choice + when "New account" + puts + when "Delete account" + puts + to_delete = choose 'Select an account to delete:', *accounts.collect{ |account| account.account }.push('ALL') + case to_delete + when "ALL" + accounts.each{ |account| account.delete } + else + account = Keychain.generic_password_items.find { |item| item.label == "omudid" and item.account == to_delete }.delete + end + abort + else + account = Keychain.generic_password_items.find { |item| item.label == "omudid" and item.account == choice } + username = account.account + password = account.password + end + end + if username == nil + username = ask 'Apple Username:' + password = pw 'Apple Password:' + puts + if agree 'Do you want to save these login details? (yes/no)' + Keychain.add_generic_password('omudid', username, password) rescue say_error 'Credentials not saved, email already stored in keychain.' + end + end + + self.username, self.password = username, password + return username, password + end + + def get_teams agent = Cupertino::ProvisioningPortal::Agent.new agent.instance_eval do def get(uri, parameters = [], referer = nil, headers = {}) uri = ::File.join("https://#{Cupertino::HOSTNAME}", uri) unless /^https?/ === uri @@ -31,12 +76,12 @@ raise UnsuccessfulAuthenticationError end end - agent.username = username - agent.password = password + agent.username = self.username + agent.password = self.password agent.get('https://developer.apple.com/account/selectTeam.action') teams = agent.page.form_with(:name => 'saveTeamSelection').radiobuttons @@ -48,11 +93,11 @@ end formatted_teams end - def setup_cupertino(username, password, team_name = '') + def setup_cupertino(team_name = '') agent = Cupertino::ProvisioningPortal::Agent.new agent.instance_eval do def get(uri, parameters = [], referer = nil, headers = {}) uri = ::File.join("https://#{Cupertino::HOSTNAME}", uri) unless /^https?/ === uri @@ -105,11 +150,11 @@ @team end end - agent.username = username - agent.password = password + agent.username = self.username + agent.password = self.password agent.instance_variable_set(:@teamName, team_name) @agent = agent self \ No newline at end of file