Sha256: e5b948b0d9198d3017993d8674b47844cbe5dd9d09b7a91cc488843cf9e6fac5

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 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
              teams = []
              page.form_with(:name => 'saveTeamSelection').radiobuttons.each do |radio|
                name = page.search("label[for=\"#{radio.dom_id}\"]").first.text.strip
                teams << [name, radio.value]
              end

              name = choose "Select a team:", *teams.collect(&:first)
              @team ||= teams.detect{|e| e.first == name}.last
            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

1 entries across 1 versions & 1 rubygems

Version Path
cupertino-0.9.0 ./lib/cupertino/provisioning_portal/helpers.rb