Skip to content

Commit

Permalink
Merge pull request #8 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.4.0
  • Loading branch information
andyone authored May 7, 2018
2 parents 51ff151 + e2fcf3c commit 029de21
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
34 changes: 28 additions & 6 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type Timestamp struct {
time.Time
}

// ContainerID is container ID
type ContainerID string

// EmptyParameters is empty parameters
type EmptyParameters struct {
// nothing
Expand Down Expand Up @@ -250,7 +253,7 @@ type Version struct {

// Extensions contains info about content extensions
type Extensions struct {
Position string `json:"position"` // Page
Position int `json:"position"` // Page
MediaType string `json:"mediaType"` // Attachment
FileSize int `json:"fileSize"` // Attachment
Comment string `json:"comment"` // Attachment
Expand Down Expand Up @@ -301,11 +304,11 @@ type Publishers struct {

// Container contains basic container info
type Container struct {
ID string `json:"id"`
Key string `json:"key"` // Space
Name string `json:"name"` // Space
Title string `json:"title"` // Page or blogpost
Links *Links `json:"_links"`
CID ContainerID `json:"id"`
Key string `json:"key"` // Space
Name string `json:"name"` // Space
Title string `json:"title"` // Page or blogpost
Links *Links `json:"_links"`
}

// LABELS //////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -588,6 +591,11 @@ MAINLOOP:
return result
}

// ID return container ID
func (c *Container) ID() string {
return string(c.CID)
}

// ////////////////////////////////////////////////////////////////////////////////// //

// UnmarshalJSON is custom Date format unmarshaler
Expand All @@ -599,6 +607,20 @@ func (d *Date) UnmarshalJSON(b []byte) error {
return err
}

// UnmarshalJSON is custom container ID unmarshaler
func (c *ContainerID) UnmarshalJSON(b []byte) error {
switch {
case len(b) == 0:
// nop
case b[0] == '"':
*c = ContainerID(strings.Replace(string(b), "\"", "", -1))
default:
*c = ContainerID(string(b))
}

return nil
}

// UnmarshalJSON is custom Timestamp format unmarshaler
func (d *Timestamp) UnmarshalJSON(b []byte) error {
ts, err := strconv.ParseInt(string(b), 10, 64)
Expand Down
2 changes: 1 addition & 1 deletion confluence.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ func (api *API) acquireRequest(method, uri string, params Parameters) *fasthttp.
}

// Set auth header
req.Header.Set("Authorization", "Basic "+api.basicAuth)
req.Header.Add("Authorization", "Basic "+api.basicAuth)

return req
}
Expand Down
2 changes: 1 addition & 1 deletion confluence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *ConfluenceSuite) TestParamsEncoding(c *C) {
Expand: []string{"test1,test2"},
}

c.Assert(p.ToQuery(), Equals, "expand=test1,test2")
c.Assert(p.ToQuery(), Equals, `expand=test1%2Ctest2`)

p = SpaceParameters{
SpaceKey: []string{"TS1", "TS2", "TS3"},
Expand Down
12 changes: 9 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package confluence

import (
"fmt"
"net/url"
"reflect"
"strings"
"time"
Expand All @@ -30,7 +31,7 @@ func paramsToQuery(params interface{}) string {
switch value.Type().String() {
case "string":
if value.String() != "" {
result += field.Tag.Get("query") + "=" + value.String() + "&"
result += field.Tag.Get("query") + "=" + esc(value.String()) + "&"
}

case "int":
Expand Down Expand Up @@ -77,9 +78,9 @@ func formatSlice(tag string, s reflect.Value) string {
v := s.Index(i)

if unwrap {
result += name + "=" + v.String() + "&"
result += name + "=" + esc(v.String()) + "&"
} else {
result += v.String() + ","
result += esc(v.String()) + ","
}
}

Expand All @@ -94,3 +95,8 @@ func parseSliceTag(tag string) (string, bool) {

return tag[:strings.Index(tag, ",")], true
}

// esc escapes the string so it can be safely placed inside a URL query
func esc(s string) string {
return url.QueryEscape(s)
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
NAME = "Go-Confluence"

// VERSION is package version
VERSION = "1.3.0"
VERSION = "1.4.0"
)

// ////////////////////////////////////////////////////////////////////////////////// //

0 comments on commit 029de21

Please sign in to comment.