2010-12-03 92 views
2

這是一個CURL示例,這是我用來嘗試實現文件自動上傳的示例。AppleScript cURL文件上傳幫助

curl http://testflightapp.com/api/builds.json 
    -F [email protected] 
    -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' 

我已經提出,要求提供「票據」,該文件一個AppleScript和是否通知:

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 

在哪裏我似乎有問題,是與該文件的位置。我不確定,但我認爲它的格式爲:而不是/路徑。

在此先感謝您的任何建議。

回答

3

爲了獲取表單/Users/you/file代替的Macintosh HD:Users:you:file經典的Mac風格路徑的POSIX路徑,可以使用POSIX path ofset pathToIPA to POSIX path of pathToIPA。不過,按照重要性排序,還有其他一些事情需要解決。

  1. 使用quoted form of用於任何用戶輸入到shell。否則,如果用戶寫入It's good.,則shell將看到文字'。更糟糕的是,有人可能會寫; rm -rf ~,然後你會被洗淨。

  2. 對於每個變量,您都不需要property;他們真的是常量。

  3. 你不符合你的命名。很高興看到these_varstheseVarsTheseVars,而不是全部三個。儘管如此,還是一個很小的問題一個類似的小問題是,你可以刪除一些額外的變量,雖然這又是一個風格點。

  4. 我不知道你的意思是有的,但是之後return UploadResponse,你有更多的代碼。該代碼不會運行,因爲您剛剛返回。確保你只留下這些代碼路徑之一!

您需要做#1;其他三件事絕對是可選的。即使如此,這是我如何重寫代碼:

property api_token : "SECRET" 
property team_token : "SECRET" 

set whats_new to text returned of ¬ 
    (display dialog "What's new in this version?" default answer "") 
set path_to_IPA to POSIX path of (choose file with prompt "Select IPA") 
set notify_answer to button returned of ¬ 
    (display dialog "Notify testers?" buttons {"No", "Yes"} default button 2) 
if notify_answer is equal to "No" then 
    set notify to "False" 
else if notify_answer is equal to "Yes" then 
    set notify to "True" 
else 
    error "\"Notify testers\" check failed." 
end if 

upload_IPA(api_token, team_token, notify, whats_new, path_to_IPA) 

on upload_IPA(api_token, team_token, notify, whats_new, path_to_IPA) 
    set test_flight_API_upload_script to "/usr/bin/curl" & ¬ 
     " http://testflightapp.com/api/builds.json" & ¬ 
     " -F " & "file=" & quoted form of path_to_IPA & ¬ 
     " -F " & "api_token=" & quoted form of api_token & ¬ 
     " -F " & "team_token=" & quoted form of team_token & ¬ 
     " -F " & "notes=" & quoted form of whats_new & ¬ 
     " -F " & "notify=" & quoted form of notify 

    set upload_response to do shell script test_flight_API_upload_script 
    return upload_response 
    -- Delete the above line or this if 
    if upload_response contains "Status: 200 OK" then 
     return "Success!" 
    else 
     return "Failure!" 
    end if 
end upload_IPA 
+1

感謝您的所有信息和修訂腳本。它似乎最初工作,但沒有上傳。我最終看到的結果是整個腳本,現在看起來是正確的。這次我沒有被退回任何錯誤。它是否過早停止?再次感謝你的幫助。 – runmad 2010-12-05 18:52:24