Class: AppleCertMonitor::AppleDevClient
- Inherits:
-
Thor
- Object
- Thor
- AppleCertMonitor::AppleDevClient
- Defined in:
- lib/apple_cert_monitor/client.rb
Class Method Summary collapse
- .find_60_days_to_expire_items(cellModels, model_type) ⇒ Object
- .find_expired_items(cellModels, model_type) ⇒ Object
- .generate_formatted_table_row(left_margin, s1, s2, s3, max_s1_length, max_s2_length, separator) ⇒ Object
- .pretty_print_table(table_header_1, table_header_2, table_header_3, cellModels) ⇒ Object
- .print_team_footer(team, team_index) ⇒ Object
- .print_team_header(team, team_index) ⇒ Object
- .set_output_file_name(string) ⇒ Object
- .team_header_str(team) ⇒ Object
- .team_star_str(team, team_index) ⇒ Object
- .teams ⇒ Object
- .write_to_file_and_puts_to_console(string) ⇒ Object
Instance Method Summary collapse
Class Method Details
.find_60_days_to_expire_items(cellModels, model_type) ⇒ Object
104 105 106 |
# File 'lib/apple_cert_monitor/client.rb', line 104 def self.find_60_days_to_expire_items(cellModels, model_type) find_items(cellModels, model_type, 0, 60) end |
.find_expired_items(cellModels, model_type) ⇒ Object
100 101 102 |
# File 'lib/apple_cert_monitor/client.rb', line 100 def self.find_expired_items(cellModels, model_type) find_items(cellModels, model_type) end |
.generate_formatted_table_row(left_margin, s1, s2, s3, max_s1_length, max_s2_length, separator) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/apple_cert_monitor/client.rb', line 186 def self.generate_formatted_table_row(left_margin, s1, s2, s3, max_s1_length, max_s2_length, separator) row_text = "" # concatenate index row_text += left_margin + s1.to_s i = 0 while i < (max_s1_length - s1.to_s.length) do row_text += " " i += 1 end row_text += separator # concantenate name row_text += s2 i = 0 while i < (max_s2_length - s2.to_s.length) do row_text += " " i += 1 end row_text += separator # concantenate days row_text += s3 return row_text end |
.pretty_print_table(table_header_1, table_header_2, table_header_3, cellModels) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/apple_cert_monitor/client.rb', line 125 def self.pretty_print_table(table_header_1, table_header_2, table_header_3, cellModels) if !cellModels.is_a?(Array) return end # configure index max length index_max_length = 5 # configure longest name length longest_certificate_name_length = 0 cellModels.each do |cell| if cell.kind_of?(TableCellModel) if cell.name.to_s.length > longest_certificate_name_length longest_certificate_name_length = cell.name.to_s.length end end end # configure underline underline_str = '' underline_index = index_max_length + " | ".length + longest_certificate_name_length + " | ".length + "Days".length while underline_index > 0 underline_str += '-' underline_index -= 1 end # top line table_top_line = "* " + underline_str write_to_file_and_puts_to_console(table_top_line + "\n") # table title table_title = generate_formatted_table_row("* ", table_header_1, table_header_2, table_header_3, index_max_length, longest_certificate_name_length, " | ") write_to_file_and_puts_to_console(table_title + "\n") # table title bottom line table_title_bottom_line = "* " + underline_str write_to_file_and_puts_to_console(table_title_bottom_line + "\n") # table content cellModels.each_with_index do |cell, index| row_text = generate_formatted_table_row("* ", (index + 1).to_s, cell.name.to_s, cell.days_to_now.to_s, index_max_length, longest_certificate_name_length, " | ") write_to_file_and_puts_to_console(row_text + "\n") end # table bottom line table_bottom_line = "* " + underline_str write_to_file_and_puts_to_console(table_bottom_line + "\n") end |
.print_team_footer(team, team_index) ⇒ Object
70 71 72 73 |
# File 'lib/apple_cert_monitor/client.rb', line 70 def self.(team, team_index) AppleDevClient.write_to_file_and_puts_to_console(team_star_str(team, team_index)) AppleDevClient.write_to_file_and_puts_to_console("\n\n") end |
.print_team_header(team, team_index) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/apple_cert_monitor/client.rb', line 58 def self.print_team_header(team, team_index) # configure stars line above stars_str = team_star_str(team, team_index) AppleDevClient.write_to_file_and_puts_to_console(stars_str) AppleDevClient.write_to_file_and_puts_to_console("\n") # configure output string for each team origin_str = team_header_str(team) AppleDevClient.write_to_file_and_puts_to_console(origin_str) AppleDevClient.write_to_file_and_puts_to_console("\n") end |
.set_output_file_name(string) ⇒ Object
108 109 110 |
# File 'lib/apple_cert_monitor/client.rb', line 108 def self.set_output_file_name(string) @@output_file_name = string end |
.team_header_str(team) ⇒ Object
95 96 97 98 |
# File 'lib/apple_cert_monitor/client.rb', line 95 def self.team_header_str(team) origin_str = "* " + "Now deal with team_id(" + team["teamId"] + ") team_name(" + team["name"] + ") team_type(" + team["type"] + ")" return origin_str end |
.team_star_str(team, team_index) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/apple_cert_monitor/client.rb', line 75 def self.team_star_str(team, team_index) # configure output string for each team origin_str = team_header_str(team) # configure stars line above star_index = 0 stars_str = '' while star_index < origin_str.length if star_index == origin_str.length / 2 progress_str = " #{team_index + 1} / #{teams.count} " stars_str += progress_str star_index += progress_str.length else stars_str += "*" star_index += 1 end end return stars_str end |
.teams ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/apple_cert_monitor/client.rb', line 41 def self.teams if Spaceship.client == nil puts "================================================================================================================".green puts "Welcome to this cute tool. With its help, managing complicated Apple Developer Accounts have never been so easy!".green puts "=====================================================================".green puts "First, please enter Apple Developer Account info." puts 'Enter Username:' username = STDIN.gets.strip password = STDIN.getpass("Enter Password:") puts "Now login in, please wait......".green AppleDevClient.login(username, password) end all_teams = Spaceship.client.teams return all_teams end |
.write_to_file_and_puts_to_console(string) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/apple_cert_monitor/client.rb', line 112 def self.write_to_file_and_puts_to_console(string) puts string output_dir = "#{ENV['HOME']}/Downloads/AppleCertMonitorOutput" unless File.directory?(output_dir) FileUtils.mkdir_p(output_dir) end if string.to_s.length > 0 File.open("#{output_dir}/#{@@output_file_name}", 'a') {|f| f << string } end end |
Instance Method Details
#print_all_teams ⇒ Object
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 |
# File 'lib/apple_cert_monitor/client.rb', line 14 def print_all_teams if Spaceship.client == nil puts "================================================================================================================".green puts "Welcome to this cute tool. With its help, managing complicated Apple Developer Accounts have never been so easy!".green puts "=====================================================================".green puts "First, please enter Apple Developer Account info." puts 'Enter Username:' username = STDIN.gets.strip password = STDIN.getpass("Enter Password:") puts "Now login in, please wait......".green AppleDevClient.login(username, password) end all_teams = Spaceship.client.teams if all_teams.count <= 0 puts "No teams available on the Developer Portal" puts "You must accept an invitation to a team for it to be available" puts "To learn more about teams and how to use them visit https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/ManagingYourTeam/ManagingYourTeam.html" raise "Your account is in no teams" else puts "=====================================================================".green puts "Multiple teams found on the " + "Developer Portal" AppleDevClient.pretty_print_teams(all_teams) end end |