Class: PEM::DeveloperCenter
- Inherits:
-
Object
- Object
- PEM::DeveloperCenter
- Includes:
- Capybara::DSL
- Defined in:
- lib/pem/developer_center.rb
Defined Under Namespace
Classes: DeveloperCenterGeneralError, DeveloperCenterLoginError
Constant Summary collapse
- DEVELOPER_CENTER_URL =
"https://developer.apple.com/devcenter/ios/index.action"
- APP_IDS_URL =
"https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action"
- PRODUCTION_SSL_CERTIFICATE_TITLE =
Strings
"Production SSL Certificate"
Instance Method Summary collapse
- #app_status(app_identifier) ⇒ Object
-
#fetch_cer_file(app_identifier) ⇒ Object
This method will enable push for the given app and download the cer file in any case, no matter if it existed before or not.
-
#initialize ⇒ DeveloperCenter
constructor
A new instance of DeveloperCenter.
-
#login(user = nil, password = nil) ⇒ bool
Loggs in a user with the given login data on the Dev Center Frontend.
Constructor Details
#initialize ⇒ DeveloperCenter
Returns a new instance of DeveloperCenter.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pem/developer_center.rb', line 26 def initialize FileUtils.mkdir_p TMP_FOLDER DependencyChecker.check_dependencies Capybara.run_server = false Capybara.default_driver = :poltergeist Capybara.javascript_driver = :poltergeist Capybara.current_driver = :poltergeist Capybara.app_host = DEVELOPER_CENTER_URL # Since Apple has some SSL errors, we have to configure the client properly: # https://github.com/ariya/phantomjs/issues/11239 Capybara.register_driver :poltergeist do |a| conf = ['--debug=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1'] Capybara::Poltergeist::Driver.new(a, { phantomjs_options: conf, phantomjs_logger: File.open("#{TMP_FOLDER}/poltergeist_log.txt", "a"), js_errors: false }) end self.login end |
Instance Method Details
#app_status(app_identifier) ⇒ Object
101 102 103 |
# File 'lib/pem/developer_center.rb', line 101 def app_status(app_identifier) # TODO end |
#fetch_cer_file(app_identifier) ⇒ Object
This method will enable push for the given app and download the cer file in any case, no matter if it existed before or not
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/pem/developer_center.rb', line 108 def fetch_cer_file(app_identifier) begin open_app_page(app_identifier) click_on "Edit" wait_for_elements(".item-details") # just to finish loading push_value = first(:css, '#pushEnabled').value if push_value == "on" Helper.log.info "Push for app '#{app_identifier}' is enabled" else Helper.log.warn "Push for app '#{app_identifier}' is disabled. This has to change." first(:css, '#pushEnabled').click end sleep 1 # Example code # <div class="appCertificates"> # <h3>Apple Push Notification service SSL Certificates</h3> # <p>To configure push notifications for this iOS App ID, a Client SSL Certificate that allows your notification server to connect to the Apple Push Notification Service is required. Each iOS App ID requires its own Client SSL Certificate. Manage and generate your certificates below.</p> # <div class="title" data-hires-status="replaced">Development SSL Certificate</div> # <div class="createCertificate"> # <p>Create certificate to use for this App ID.</p> # <a class="button small navLink development enabled" href="/account/ios/certificate/certificateRequest.action?appIdId=...&types=..."><span>Create Certificate...</span></a> # </div> # <div class="title" data-hires-status="replaced">Production SSL Certificate</div> # <div class="certificate"> # <dl> # <dt>Name:</dt> # <dd>Apple Production iOS Push Services: net.sunapps.151</dd> # <dt>Type:</dt> # <dd>APNs Production iOS</dd> # <dt>Expires:</dt> # <dd>Nov 14, 2015</dd> # </dl> # <a class="button small revoke-button" href="https://developer.apple.com/services-account/QH65B2/account/ios/certificate/revokeCertificate.action?content-type=application/x-www-form-urlencoded&accept=application/json&requestId=....;userLocale=en_US&teamId=...&certificateId=...&type=...."><span>Revoke</span></a> # <a class="button small download-button" href="/account/ios/certificate/certificateContentDownload.action?displayId=....&type=..."><span>Download</span></a> # </div> # <div class="createCertificate"> # <p>Create an additional certificate to use for this App ID.</p> # <a class="button small navLink distribution enabled" href="/account/ios/certificate/certificateRequest.action?appIdId=...&types=..."><span>Create Certificate...</span></a> # </div> # </div> def wait_for_elements(".formContent") certificates_block = first('.appCertificates') = nil production_section = false certificates_block.all(:xpath, "./div").each do |div| if production_section # We're now in the second part, we only care about production certificates if ( = div.first(".download-button")) return end end production_section = true if div.text == PRODUCTION_SSL_CERTIFICATE_TITLE end nil end = if not Helper.log.warn "Push for app '#{app_identifier}' is enabled, but there is no production certificate yet." create_push_for_app(app_identifier) = raise "Could not find download button for Production SSL Certificate. Check out: '#{current_url}'" unless end Helper.log.info "Going to download the latest profile" # It is enabled, now just download it # Taken from http://stackoverflow.com/a/17111206/445598 sleep 2 host = Capybara.current_session.current_host url = ['href'] url = [host, url].join('') myacinfo = page.driver.['myacinfo'].value # some magic Apple, which is required for the profile download data = open(url, {'Cookie' => "myacinfo=#{myacinfo}"}).read raise "Something went wrong when downloading the certificate" unless data path = "#{TMP_FOLDER}/aps_production_#{app_identifier}.cer" File.write(path, data) Helper.log.info "Successfully downloaded latest .cer file." return path rescue Exception => ex error_occured(ex) end end |
#login(user = nil, password = nil) ⇒ bool
Loggs in a user with the given login data on the Dev Center Frontend. You don’t need to pass a username and password. It will Automatically be fetched using the Deliver::PasswordManager. This method will also automatically be called when triggering other actions like #open_app_page
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pem/developer_center.rb', line 62 def login(user = nil, password = nil) begin Helper.log.info "Login into iOS Developer Center" user ||= Deliver::PasswordManager.shared_manager.username password ||= Deliver::PasswordManager.shared_manager.password result = visit DEVELOPER_CENTER_URL raise "Could not open Developer Center" unless result['status'] == 'success' wait_for_elements(".button.blue").first.click (wait_for_elements('#accountpassword') rescue nil) # when the user is already logged in, this will raise an exception if page.has_content?"My Apps" # Already logged in return true end fill_in "accountname", with: user fill_in "accountpassword", with: password begin all(".button.large.blue.signin-button").first.click wait_for_elements('#aprerelease') rescue Exception => ex Helper.log.debug ex raise DeveloperCenterLoginError.new("Error logging in user #{user} with the given password. Make sure you entered them correctly.") end Helper.log.info "Login successful" true rescue Exception => ex error_occured(ex) end end |