Api 如何使用Groovy HTTPBuilder从AgileZen获取故事?

Api 如何使用Groovy HTTPBuilder从AgileZen获取故事?,api,rest,groovy,integration,agile,Api,Rest,Groovy,Integration,Agile,我想使用他们的RESTAPI从AgileZen中获取故事 我读到: 此外,我还做到了这一点: 为了让Groovy客户端代码访问AgileZen stories,如何将上述内容结合起来?下面是代码示例,它使id为1的一个故事显示在id为16854的特定项目中: import groovyx.net.http.HTTPBuilder import static groovyx.net.http.Method.GET import static groovyx.net.http.ContentType

我想使用他们的RESTAPI从AgileZen中获取故事

我读到:

此外,我还做到了这一点:


为了让Groovy客户端代码访问AgileZen stories,如何将上述内容结合起来?

下面是代码示例,它使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的项目执行此操作的后续问题可能很快就会出现。

有用的提示:uri.path=/api/v1/project/${project_ID}/stories和json.totalItems可获取总故事数。将json重命名为故事也很好。