-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1e1762
commit 84fbbcf
Showing
2 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,113 @@ | ||
TAIGO Examples | ||
TAIGO Examples & Demo Cases | ||
----- | ||
|
||
![alt text](../assets/banner_627x300.png "TAIGO Banner") | ||
|
||
# TODO: Add Examples | ||
# Introduction | ||
Each section in this document is a use case snippet. These snippets are useless as-is, because they are taken our from a grater context. | ||
|
||
Make sure you always import the required packages and you always put these snippets into the right context. | ||
|
||
There is no proper error handling implemented in these snippets, each error panics the application. Make sure you always implement proper error handling. | ||
|
||
# Create Client & Authenticate | ||
```go | ||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
taiga "github.com/theriverman/taigo" | ||
) | ||
|
||
func main() { | ||
// Create client | ||
client := taiga.Client{ | ||
BaseURL: "https://api.taiga.io", | ||
HTTPClient: &http.Client{}, | ||
LoginType: "normal", | ||
} | ||
// Initialise client (authenticates to Taiga) | ||
err := client.Initialise() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Authenticate (get/set Token) | ||
client.AuthByCredentials(&taiga.Credentials{ | ||
Type: "normal", | ||
Username: "admin", | ||
Password: "123123", | ||
}) | ||
} | ||
|
||
``` | ||
|
||
# Get Self (User) /users/me | ||
```go | ||
me, err := client.User.Me() | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println("Me: (ID, Username, FullName)", me.ID, me.Username, me.FullName) | ||
``` | ||
|
||
# Get a Project | ||
```go | ||
// Get Project | ||
slug := "my-sassy-project-1" | ||
fmt.Printf("\nGetting Project (slug=%s)..\n", slug) | ||
project, err := client.Project.GetBySlug(slug) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("\nProject name: %s \n", project.Name) | ||
|
||
``` | ||
|
||
# Get Project Severities | ||
In this scenario observe that we're accessing the `ProjectDETAIL` meta field. | ||
```go | ||
fmt.Printf("\nProject Severities:\n") | ||
for _, severity := range project.ProjectDETAIL.Severities { | ||
fmt.Printf(" * ID=%d Name=%s\n", severity.ID, severity.Name) | ||
} | ||
``` | ||
|
||
# Get (Project) Epic Custom Attributes | ||
A total of 3 epic custom attributes are returned. See it limited by the for-loop. | ||
```go | ||
fmt.Println("\nGetting all (Project) Epics Custom Attributes and printing the first 3 to the console:") | ||
fmt.Printf("Project Epic Custom Attributes:\n") | ||
for _, epicCA := range project.ProjectDETAIL.EpicCustomAttributes { | ||
fmt.Printf(" * ID=%d Name=%s ProjectID=%d\n", epicCA.ID, epicCA.Name, epicCA.ProjectID) | ||
} | ||
``` | ||
|
||
# Get Epics | ||
A total of 3 epics are returned. See it limited by the for-loop. | ||
```go | ||
fmt.Println("\nGetting all Epics and printing the first 3 to the console:") | ||
epics, err := client.Epic.List(nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for i := 0; i < 3; i++ { | ||
epic := epics[i] | ||
fmt.Printf(" * epics[%d] :: ID=%d | Subject=%s\n", i, epic.ID, epic.Subject) | ||
// Access ModifiedDate via meta because that's not available through the generic `Epic` | ||
meta := *epic.EpicDetailLIST | ||
fmt.Printf(" * meta :: ModifiedDate = %s\n\n", meta[i].ModifiedDate.Format("2006-01-02 15:04:05")) | ||
} | ||
``` | ||
|
||
# Get Epic by ID | ||
```go | ||
epicID := 123456 | ||
fmt.Println("Getting an Epic by ID:", epicID) | ||
epic, err := client.Epic.Get(epicID) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(" * epic.EpicDetailGET.ID", epic.EpicDetailGET.ID) | ||
fmt.Printf(" * epic.Subject = %s\n\n", epic.Subject) | ||
``` |