【问题标题】:How To Use Groovy HTTPBuilder To Get Stories from AgileZen?如何使用 Groovy HTTPBuilder 从 AgileZen 获取故事?
【发布时间】:2011-06-17 14:27:33
【问题描述】:

我想使用他们的 REST API 从 Agile Zen 中提取故事。

我读到了:

另外,我得到了这个工作:http://groovy.codehaus.org/HTTP+Builder

如何将上述内容结合起来以让 Groovy 客户端代码访问 AgileZen 故事?

【问题讨论】:

    标签: api rest groovy integration agile


    【解决方案1】:

    这是一个代码示例,它使一个 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 重命名为 stories 也不错。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 2012-02-04
    • 2016-06-08
    • 2013-11-26
    • 1970-01-01
    • 2015-11-10
    相关资源
    最近更新 更多