Client for the pixeldrain API. Used by pixeldrain itself for tranferring data between the web UI and API server. And for rendering JSON responses
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. package pixelapi
  2. import (
  3. "net/url"
  4. "time"
  5. "github.com/gocql/gocql"
  6. )
  7. // Subscription contains information about a user's subscription. When it
  8. // started, when it ends, and what type of subscription it is
  9. type Subscription struct {
  10. ID gocql.UUID `json:"id"`
  11. Used bool `json:"used"`
  12. DurationDays int `json:"duration_days"`
  13. StartTime time.Time `json:"start_date"`
  14. WarningDate time.Time `json:"warning_date"`
  15. EndDate time.Time `json:"end_date"`
  16. SubscriptionType SubscriptionType `json:"subscription_type"`
  17. }
  18. // SubscriptionType contains information about a subscription type. It's not the
  19. // active subscription itself, only the properties of the subscription. Like the
  20. // perks and cost
  21. type SubscriptionType struct {
  22. ID string `json:"id"`
  23. Name string `json:"name"`
  24. Type string `json:"type"`
  25. DisableAdDisplay bool `json:"disable_ad_display"`
  26. DisableAdsOnFiles bool `json:"disable_ads_on_files"`
  27. FileSizeLimit int64 `json:"file_size_limit"`
  28. FileExpiryDays int `json:"file_expiry_days"`
  29. }
  30. // GetSubscriptionID returns the subscription object identified by the given ID
  31. func (p *PixelAPI) GetSubscriptionID(id string) (resp Subscription, err error) {
  32. return resp, p.jsonRequest("GET", p.apiEndpoint+"/subscription/"+url.PathEscape(id), &resp)
  33. }
  34. // PostSubscriptionLink links a subscription to the logged in user account. Use
  35. // Login() before calling this function to select the account to use. This
  36. // action cannot be undone.
  37. func (p *PixelAPI) PostSubscriptionLink(id string) (err error) {
  38. return p.jsonRequest("POST", p.apiEndpoint+"/subscription/"+url.PathEscape(id)+"/link", nil)
  39. }