pinboard.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Copyright (C) 2017-2018 Marcus Rohrmoser, http://purl.mro.name/ShaarliGo
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. //
  17. package main
  18. import (
  19. "net/url"
  20. "strings"
  21. "time"
  22. )
  23. func yesno(yes bool) string {
  24. if !yes {
  25. return "no"
  26. }
  27. return "yes"
  28. }
  29. // https://pinboard.in/api/#posts_add
  30. // https://api.pinboard.in/v1/posts/add
  31. //
  32. // url url the URL of the item
  33. // description title Title of the item. This field is unfortunately named 'description' for backwards compatibility with the delicious API
  34. // extended text Description of the item. Called 'extended' for backwards compatibility with delicious API
  35. // tags tag List of up to 100 tags
  36. // dt datetime creation time for this bookmark. Defaults to current time. Datestamps more than 10 minutes ahead of server time will be reset to current server time
  37. // replace yes/no Replace any existing bookmark with this URL. Default is yes. If set to no, will throw an error if bookmark exists
  38. // shared yes/no Make bookmark public. Default is "yes" unless user has enabled the "save all bookmarks as private" user setting, in which case default is "no"
  39. // toread yes/no Marks the bookmark as unread. Default is "no"
  40. func pinboardAddUrl(base *url.URL, auth_token string, ur *url.URL, description, extended string, tags []string, dt time.Time) *url.URL {
  41. // _, err := HttpGetBody(&url, timeout)
  42. pars := url.Values{}
  43. pars.Add("url", ur.String())
  44. pars.Add("auth_token", auth_token)
  45. pars.Add("description", description)
  46. pars.Add("extended", extended)
  47. pars.Add("tags", strings.Join(tags, " "))
  48. // pars.Add("replace", yesno(replace))
  49. // pars.Add("shared", yesno(shared))
  50. // pars.Add("toread", yesno(toread))
  51. pars.Add("dt", dt.Format(time.RFC3339))
  52. ret := &(*base)
  53. ret.Path += "/posts/add"
  54. ret.RawQuery = pars.Encode()
  55. return ret
  56. }