github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/backend/premiumizeme/api/types.go (about)

     1  // Package api contains definitions for using the premiumize.me API
     2  package api
     3  
     4  import "fmt"
     5  
     6  // Response is returned by all messages and embedded in the
     7  // structures below
     8  type Response struct {
     9  	Message string `json:"message,omitempty"`
    10  	Status  string `json:"status"`
    11  }
    12  
    13  // Error statisfies the error interface
    14  func (e *Response) Error() string {
    15  	return fmt.Sprintf("%s: %s", e.Status, e.Message)
    16  }
    17  
    18  // AsErr checks the status and returns an err if bad or nil if good
    19  func (e *Response) AsErr() error {
    20  	if e.Status != "success" {
    21  		return e
    22  	}
    23  	return nil
    24  }
    25  
    26  // Item Types
    27  const (
    28  	ItemTypeFolder = "folder"
    29  	ItemTypeFile   = "file"
    30  )
    31  
    32  // Item refers to a file or folder
    33  type Item struct {
    34  	Breadcrumbs     []Breadcrumb `json:"breadcrumbs"`
    35  	CreatedAt       int64        `json:"created_at,omitempty"`
    36  	ID              string       `json:"id"`
    37  	Link            string       `json:"link,omitempty"`
    38  	Name            string       `json:"name"`
    39  	Size            int64        `json:"size,omitempty"`
    40  	StreamLink      string       `json:"stream_link,omitempty"`
    41  	Type            string       `json:"type"`
    42  	TranscodeStatus string       `json:"transcode_status"`
    43  	IP              string       `json:"ip"`
    44  	MimeType        string       `json:"mime_type"`
    45  }
    46  
    47  // Breadcrumb is part the breadcrumb trail for a file or folder.  It
    48  // is returned as part of folder/list if required
    49  type Breadcrumb struct {
    50  	ID       string `json:"id,omitempty"`
    51  	Name     string `json:"name,omitempty"`
    52  	ParentID string `json:"parent_id,omitempty"`
    53  }
    54  
    55  // FolderListResponse is the response to folder/list
    56  type FolderListResponse struct {
    57  	Response
    58  	Content  []Item `json:"content"`
    59  	Name     string `json:"name,omitempty"`
    60  	ParentID string `json:"parent_id,omitempty"`
    61  }
    62  
    63  // FolderCreateResponse is the response to folder/create
    64  type FolderCreateResponse struct {
    65  	Response
    66  	ID string `json:"id,omitempty"`
    67  }
    68  
    69  // FolderUploadinfoResponse is the response to folder/uploadinfo
    70  type FolderUploadinfoResponse struct {
    71  	Response
    72  	Token string `json:"token,omitempty"`
    73  	URL   string `json:"url,omitempty"`
    74  }
    75  
    76  // AccountInfoResponse is the response to account/info
    77  type AccountInfoResponse struct {
    78  	Response
    79  	CustomerID   string  `json:"customer_id,omitempty"`
    80  	LimitUsed    float64 `json:"limit_used,omitempty"` // fraction 0..1 of download traffic limit
    81  	PremiumUntil int64   `json:"premium_until,omitempty"`
    82  	SpaceUsed    float64 `json:"space_used,omitempty"`
    83  }