Skip to content

Commit

Permalink
Merge pull request #1 from toggl/update-deps
Browse files Browse the repository at this point in the history
Add modules support, add changes from pipes-api
  • Loading branch information
Anton Kucherov authored Mar 31, 2020
2 parents 741ed5d + 033ee74 commit 29f6e4a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# IntelliJ
.idea/
out/
45 changes: 28 additions & 17 deletions basecamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"time"
)

const (
Expand All @@ -16,7 +17,8 @@ const (

type (
Client struct {
AccessToken string
AccessToken string
ModifiedSince *time.Time
}

Account struct {
Expand All @@ -34,27 +36,30 @@ type (
}

Project struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Archived bool `json:"archived"`
Starred bool `json:"starred"`
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Archived bool `json:"archived"`
Starred bool `json:"starred"`
UpdatedAt time.Time `json:"updated_at"`
}

Todo struct {
Id int `json:"id"`
Content string `json:"content"`
DueAt string `json:"due_at"`
Id int `json:"id"`
Content string `json:"content"`
DueAt string `json:"due_at"`
UpdatedAt time.Time `json:"updated_at"`
}

TodoList struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Completed bool `json:"completed"`
CompletedCount int `json:"completed_count"`
RemainingCount int `json:"remaining_count"`
ProjectId int `json:"project_id"`
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Completed bool `json:"completed"`
CompletedCount int `json:"completed_count"`
RemainingCount int `json:"remaining_count"`
ProjectId int `json:"project_id"`
UpdatedAt time.Time `json:"updated_at"`

Bucket struct {
Id int `json:"id"`
Expand Down Expand Up @@ -183,6 +188,9 @@ func (c *Client) get(url string) ([]byte, error) {
}
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Authorization", "Bearer "+c.AccessToken)
if c.ModifiedSince != nil {
req.Header.Set("If-Modified-Since", c.ModifiedSince.Format(http.TimeFormat))
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
Expand All @@ -193,7 +201,10 @@ func (c *Client) get(url string) ([]byte, error) {
if err != nil {
return nil, err
}
if 200 != resp.StatusCode {
if http.StatusNotModified == resp.StatusCode {
return []byte("null"), nil
}
if http.StatusOK != resp.StatusCode {
return b, fmt.Errorf("%s failed with status code %d", url, resp.StatusCode)
}
return b, nil
Expand Down
3 changes: 2 additions & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"../"
"log"
"os"

"github.com/toggl/go-basecamp"
)

func main() {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/toggl/go-basecamp

go 1.14

0 comments on commit 29f6e4a

Please sign in to comment.