java中的关键跟踪器电子邮件集成钩子

时间:2012-08-17 22:16:09

标签: java google-app-engine pivotaltracker

我们有一个简单的要求,当电子邮件发送到我们的组织ID时,能够在PivotalTracker中创建一个故事,比如说bugs@my-org.com

我可以找到几个或基于ruby的包装器,但我可以在我们的GAE应用程序上运行java。如果存在任何此类解决方案,是否有任何建议?

有一些api提到 代码为curl的https://www.pivotaltracker.com/help/api?version=v3#add_story

curl -H "X-TrackerToken: $TOKEN" -X POST -H "Content-type: application/xml" \
    -d "<story><story_type>feature</story_type><name>Fire torpedoes</name><requested_by>James Kirk</requested_by></story>" \
    http://www.pivotaltracker.com/services/v3/projects/$PROJECT_ID/stories

不确定我们是如何在java中做到的?

1 个答案:

答案 0 :(得分:1)

你需要做两件事:

    GAE中的
  1. Receive email

  2. 通过URLFetch发出POST请求:

    String pivotalUrl = "http://www.pivotaltracker.com/services/v3/projects/"+projectID+"/stories"
    
    String body = "<story><story_type>feature</story_type><name>Story name</name><requested_by>James Kirk</requested_by></story>"
    
    URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest request =  new HTTPRequest(pivotalUrl, HTTPMethod.POST, FetchOptions.Builder.withDeadline(30));
    request.addHeader(new HTTPHeader("X-TrackerToken","putTokenHere"));
    request.addHeader(new HTTPHeader("Content-type","application/xml"));
    
    HTTPResponse response = fetchService.fetch(request);
    if (response.getResponseCode() != 200) {
        // something went wrong
    }