[英]How To Use Groovy HTTPBuilder To Get Stories from AgileZen?
我想使用他們的REST API從Agile Zen中提取故事。
我讀:
另外,我也可以使用它: http : //groovy.codehaus.org/HTTP+Builder
一個人如何結合以上內容以獲得Groovy客戶端代碼來訪問AgileZen故事?
這是使一個ID為1的故事出現在ID為16854的特定項目中的代碼示例:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.JSON
public class StoryGetter {
public static void main(String[] args) {
new StoryGetter().getStories()
}
void getStories() {
// http://agilezen.com/project/16854/story/4
// /api/v1/project/16854/story/2
def http = new HTTPBuilder( 'http://agilezen.com' )
http.request( GET, JSON ) {
uri.path = '/api/v1/project/16854/story/1'
headers.'X-Zen-ApiKey' = 'PUT YOUR OWN API KEY HERE'
response.success = { resp, json ->
println "json size is " + json.size()
println json.toString()
}
}
}
}
由於我不應該共享我的API密鑰,因此我不得不在本文中放置一個偽造的API密鑰。
(順便說一句,這沒有使用SSL。關於啟用SSL的項目執行此操作的后續問題可能很快就會出現。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.