This is a sample CURL, which is what I am using to try and achieve an automatic upload of a file.
curl http://testflightapp.com/api/builds.json
-F file=@testflightapp.ipa
-F api_token='your_api_token'
-F team_token='your_team_token'
-F notes='This build was uploaded via the upload API'
-F notify=True
-F distribution_lists='Internal, QA'
I have made an AppleScript that asks for “notes”, the file and whether to notify:
property api_token : "SECRET"
property team_token : "SECRET"
property notify : "False"
property pathToIPA : ""
property whats_new : ""
set whats_new_prompt to (display dialog "What's new in this version?" default answer "")
set whats_new to text returned of whats_new_prompt
set pathToIPA to (choose file with prompt "Select IPA")
set pathToIPA to (pathToIPA as text)
set notify_question to display dialog "Notify testers?" buttons {"No", "Yes"} default button 2
set notify_answer to button returned of notify_question
if notify_answer is equal to "No" then
set notify to "False"
end if
if notify_answer is equal to "Yes" then
set notify to "True"
end if
uploadIPA(api_token, team_token, notify, whats_new, pathToIPA)
on uploadIPA(api_token, team_token, notify, whats_new, pathToIPA)
set TestFlightAPIUploadScript to "/usr/bin/curl" & ¬
" http://testflightapp.com/api/builds.json " & ¬
" –F " & "file=" & pathToIPA & ¬
" –F " & "api_token=" & api_token & ¬
" –F " & "team_token=" & team_token & ¬
" –F " & "notes=" & whats_new & ¬
" –F " & "notify=" & notify
set UploadResponse to do shell script TestFlightAPIUploadScript
return UploadResponse
if UploadResponse contains "Status: 200 OK" then
return "Success!"
else
return "Failure!"
end if
end uploadIPA
Where I seem to have problems is with the file location. I am not sure, but I think it’s returning the wrong format with : instead of / for the path.
Thanks in advance for any advice.
To get a POSIX path of the form
/Users/you/fileinstead of the classic Mac style path ofMacintosh HD:Users:you:file, you can usePOSIX path of:set pathToIPA to POSIX path of pathToIPA. However, there are a couple of other things you should fix, in order of importance.Use
quoted form offor any user input which goes to the shell. Otherwise, if the user writesIt's good., the shell will see the literal'. Worse, someone could write; rm -rf ~, and then you’d be hosed.You don’t need a
propertyfor every variable; they’re really for constants.You’re inconsistent with your naming. It’d be nice to just see
these_vars,theseVars, orTheseVars, not all three. A rather minor point, though. A similarly minor point is that you can remove some extra variables, though this is again a style point.I don’t know which you meant to have, but right after
return UploadResponse, you have more code. That code won’t run, because you just returned. Make sure you only leave one of those code paths!You need to do #1; the other three things are definitely optional. Even so, this is how I’d rewrite the code: