Class: OneMoreUDID::TestFlightAgent
- Inherits:
-
Mechanize
- Object
- Mechanize
- OneMoreUDID::TestFlightAgent
- Defined in:
- lib/omudid/testflight_agent.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #get(uri, parameters = [], referer = nil, headers = {}) ⇒ Object
- #get_apps ⇒ Object
- #get_builds(app_id) ⇒ Object
- #get_profile_file(profile_name) ⇒ Object
- #login(username, password) ⇒ Object
- #upload(build_id, profile_name) ⇒ Object
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/omudid/testflight_agent.rb', line 6 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/omudid/testflight_agent.rb', line 6 def username @username end |
Instance Method Details
#get(uri, parameters = [], referer = nil, headers = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omudid/testflight_agent.rb', line 52 def get(uri, parameters = [], referer = nil, headers = {}) 3.times do SpinningCursor.start do 'Loading page...' action do super(uri, parameters, referer, headers) end 'Loading page... '+'done'.color(:green) end return page unless page.respond_to?(:body) case page.body when /Login to TestFlight and FlightPath/ login! and next else return page end end raise UnsuccessfulAuthenticationError end |
#get_apps ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/omudid/testflight_agent.rb', line 75 def get_apps get('https://testflightapp.com/dashboard/applications/') apps = page.search('tr.goapp') regex = /([0-9]+)/ apps.collect { |app| [(app['id'].match regex)[1], app.search('h2 small').text.strip] } end |
#get_builds(app_id) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/omudid/testflight_agent.rb', line 83 def get_builds(app_id) get("https://testflightapp.com/dashboard/applications/#{app_id}/builds/") builds = page.search('tr.goversion') regex = /([0-9]+)/ builds.collect { |build| [(build['id'].match regex)[1], build.search('td:first')[0].text] } end |
#get_profile_file(profile_name) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/omudid/testflight_agent.rb', line 104 def get_profile_file(profile_name) Dir.glob(::File.('~') + '/Library/MobileDevice/Provisioning Profiles/*.mobileprovision') do |file| ::File.open(file, "r") do |_file| file_contents = _file.read if String.method_defined?(:encode) #file_contents.encode!('UTF-8', 'UTF-8', :invalid => :replace) file_contents.encode!('UTF-16', 'UTF-8', :invalid => :replace, :replace => '') file_contents.encode!('UTF-8', 'UTF-16') end matches = /<key>Name<\/key>\s+<string>([^<]+)<\/string>/.match file_contents if matches[1] == profile_name return _file end end end end |
#login(username, password) ⇒ Object
8 9 10 11 12 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 49 50 |
# File 'lib/omudid/testflight_agent.rb', line 8 def login(username, password) if username != nil and password != nil self.username, self.password = username, password return end accounts = Keychain.generic_password_items.select { |item| item.label == "testflight" } username = password = nil if accounts and accounts.count > 0 choice = choose 'Select an account to use:', *accounts.collect{ |account| account.account }.push('New account').push('Delete account') case choice when "New account" puts when "Delete account" puts to_delete = choose 'Select an account to delete:', *accounts.collect{ |account| account.account }.push('ALL') case to_delete when "ALL" accounts.each{ |account| account.delete } else account = Keychain.generic_password_items.find { |item| item.label == "testflight" and item.account == to_delete }.delete end abort else account = Keychain.generic_password_items.find { |item| item.label == "testflight" and item.account == choice } username = account.account password = account.password puts end end if username == nil username = ask 'Testflight Username:' password = pw 'Testflight Password:' puts if agree 'Do you want to save these login details? (yes/no)' Keychain.add_generic_password('testflight', username, password) rescue say_error 'Credentials not saved, email already stored in keychain.' end puts end self.username, self.password = username, password return username, password end |
#upload(build_id, profile_name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/omudid/testflight_agent.rb', line 91 def upload(build_id, profile_name) get("https://testflightapp.com/dashboard/builds/update/#{build_id}/") profile_file = get_profile_file(profile_name) form = page.form_with(:id => 'provision-form') upload = form.file_uploads.first upload.file_name = profile_file.path form.submit say_ok 'Submitted '+profile_file.path+"\n"+'Share link: '+page.link_with(:dom_class => 'bitly').text end |