aboutsummaryrefslogtreecommitdiff
path: root/internal/integration/pinboard/post.go
blob: 46cbf7e8767b2cc26f83075fdfc7e61070a3cc53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package pinboard // import "miniflux.app/v2/internal/integration/pinboard"

import (
	"encoding/xml"
	"net/url"
	"strings"
	"time"
)

// Post a Pinboard bookmark.  "inspiration" from https://github.com/drags/pinboard/blob/master/posts.go#L32-L42
type Post struct {
	XMLName     xml.Name  `xml:"post"`
	Url         string    `xml:"href,attr"`
	Description string    `xml:"description,attr"`
	Tags        string    `xml:"tag,attr"`
	Extended    string    `xml:"extended,attr"`
	Date        time.Time `xml:"time,attr"`
	Shared      string    `xml:"shared,attr"`
	Toread      string    `xml:"toread,attr"`
}

// Posts A result of a Pinboard API call
type posts struct {
	XMLName xml.Name `xml:"posts"`
	Posts   []Post   `xml:"post"`
}

func NewPost(url string, description string) *Post {
	return &Post{
		Url:         url,
		Description: description,
		Date:        time.Now(),
		Toread:      "no",
	}
}

func (p *Post) addTag(tag string) {
	if !strings.Contains(p.Tags, tag) {
		p.Tags += " " + tag
	}
}

func (p *Post) SetToread() {
	p.Toread = "yes"
}

func (p *Post) AddValues(values url.Values) {
	values.Add("url", p.Url)
	values.Add("description", p.Description)
	values.Add("tags", p.Tags)
	if p.Toread != "" {
		values.Add("toread", p.Toread)
	}
	if p.Shared != "" {
		values.Add("shared", p.Shared)
	}
	values.Add("dt", p.Date.Format(time.RFC3339))
	values.Add("extended", p.Extended)
}