Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.33 KB | None | 0 0
  1. package jira
  2.  
  3. import (
  4.     "encoding/json"
  5.     "net/url"
  6. )
  7.  
  8. const (
  9.     apiName    string = "api"
  10.     apiVersion string = "2"
  11. )
  12.  
  13. type JiraClient struct {
  14.     AuthUser string
  15.     AuthPass string
  16.     Host     url.URL
  17. }
  18.  
  19. func NewClient(user, pass string, jiraHost url.URL) *JiraClient {
  20.     return &JiraClient{
  21.         AuthUser: user,
  22.         AuthPass: pass,
  23.     }
  24. }
  25.  
  26. func (c *JiraClient) Products() ([]JiraProduct, error) {
  27.     args = map[string]string{
  28.         "projectKeys": "BLD",
  29.         "expand", "projects.issuetypes.fields",
  30.     }
  31.  
  32.     fields, err := c.performRequest("GET", "issue/createmeta", args)
  33.     // do whatever transformation to turn fields into []JiraProduct
  34. }
  35.  
  36. func (c *JiraClient) performRequest(method string, endpoint string, args map[string]string) jiraFields {
  37.     url := jiraUrl(endpoint)
  38.  
  39.     q := url.Query()
  40.     for k, v := range args {
  41.         q.Add(k, v)
  42.     }
  43.     url.RawQuery = q.Encode()
  44.  
  45.     resp := jiraRequest(url, method)
  46.  
  47.     // Fill the record with the data from the JSON
  48.     var parsedDoc jiraDoc
  49.  
  50.     // Use json.Decode for reading streams of JSON data
  51.     if err := json.NewDecoder(resp.Body).Decode(&parsedDoc); err != nil {
  52.         return nil, err
  53.     }
  54.  
  55.     project := parsedDoc.Projects[0]   // Only requested one project, use the first one
  56.     issueType := project.IssueTypes[0] // Should be "Task", but probably doesn't matter
  57.     fields := issueType.Fields
  58.     return fields
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement