Sha256: d190f41b2408a87983846b5e65246b10e5fad3e6a8474415c5ac600495dfe59f

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 KB

Contents

# Monkey Patch Commander::UI to alias password to avoid conflicts
module Commander::UI
  alias :pw :password
end

class String
  include Term::ANSIColor
end

module Cupertino
  module ProvisioningPortal
    module Helpers
      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+/)
                  team_id = radio.value
                  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

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

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cupertino-1.0.2 ./lib/cupertino/provisioning_portal/helpers.rb
cupertino-1.0.1 ./lib/cupertino/provisioning_portal/helpers.rb
cupertino-1.0.0 ./lib/cupertino/provisioning_portal/helpers.rb
cupertino-0.9.7 ./lib/cupertino/provisioning_portal/helpers.rb
cupertino-0.9.5 ./lib/cupertino/provisioning_portal/helpers.rb
cupertino-0.9.3 ./lib/cupertino/provisioning_portal/helpers.rb