Module: Cupertino::ProvisioningPortal::Helpers

Defined in:
lib/cupertino/provisioning_portal/helpers.rb

Instance Method Summary collapse

Instance Method Details

#agentObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cupertino/provisioning_portal/helpers.rb', line 13

def agent
  unless @agent
    @agent = Cupertino::ProvisioningPortal::Agent.new

    @agent.instance_eval do
      def username
        @username ||= ask "Username:"
      end

      def password
        @password ||= pw "Password:"
      end

      def team_id
        unless @team_id
          teams = []
          page.form_with(:name => 'saveTeamSelection').radiobuttons.each do |radio|
            name = page.search(".label-primary[for=\"#{radio.dom_id}\"]").first.text.strip
            programs = page.search(".label-secondary[for=\"#{radio.dom_id}\"]").first.text.strip.split(/\,\s+/)
            teams << Team.new(name, programs, radio.value)
          end

          unless team = teams.detect{|t| t.name == @team || t.identifier == @team}
            team = choose("Select a team:", *teams)
          end

          @team_id = team.identifier
        end

        @team_id
      end
    end
  end

  @agent
end

#pluralize(n, singular, plural = nil) ⇒ Object



50
51
52
# File 'lib/cupertino/provisioning_portal/helpers.rb', line 50

def pluralize(n, singular, plural = nil)
  n.to_i == 1 ? "1 #{singular}" : "#{n} #{plural || singular + 's'}"
end

#tryObject



54
55
56
57
58
59
60
61
62
# File 'lib/cupertino/provisioning_portal/helpers.rb', line 54

def try
  return unless block_given?

  begin
    yield
  rescue UnsuccessfulAuthenticationError
    say_error "Could not authenticate with Apple Developer Center. Check that your username & password are correct, and that your membership is valid and all pending Terms of Service & agreements are accepted. If this problem continues, try logging into https://developer.apple.com/membercenter/ from a browser to see what's going on." and abort
  end
end