post.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package pinboard // import "miniflux.app/v2/internal/integration/pinboard"
  4. import (
  5. "encoding/xml"
  6. "net/url"
  7. "strings"
  8. "time"
  9. )
  10. // Post a Pinboard bookmark. "inspiration" from https://github.com/drags/pinboard/blob/master/posts.go#L32-L42
  11. type Post struct {
  12. XMLName xml.Name `xml:"post"`
  13. Url string `xml:"href,attr"`
  14. Description string `xml:"description,attr"`
  15. Tags string `xml:"tag,attr"`
  16. Extended string `xml:"extended,attr"`
  17. Date time.Time `xml:"time,attr"`
  18. Shared string `xml:"shared,attr"`
  19. Toread string `xml:"toread,attr"`
  20. }
  21. // Posts A result of a Pinboard API call
  22. type posts struct {
  23. XMLName xml.Name `xml:"posts"`
  24. Posts []Post `xml:"post"`
  25. }
  26. func NewPost(url string, description string) *Post {
  27. return &Post{
  28. Url: url,
  29. Description: description,
  30. Date: time.Now(),
  31. Toread: "no",
  32. }
  33. }
  34. func (p *Post) addTag(tag string) {
  35. if !strings.Contains(p.Tags, tag) {
  36. p.Tags += " " + tag
  37. }
  38. }
  39. func (p *Post) SetToread() {
  40. p.Toread = "yes"
  41. }
  42. func (p *Post) AddValues(values url.Values) {
  43. values.Add("url", p.Url)
  44. values.Add("description", p.Description)
  45. values.Add("tags", p.Tags)
  46. if p.Toread != "" {
  47. values.Add("toread", p.Toread)
  48. }
  49. if p.Shared != "" {
  50. values.Add("shared", p.Shared)
  51. }
  52. values.Add("dt", p.Date.Format(time.RFC3339))
  53. values.Add("extended", p.Extended)
  54. }