github.com/artpar/rclone@v1.67.3/backend/zoho/api/types.go (about)

     1  // Package api provides types used by the Zoho API.
     2  package api
     3  
     4  import (
     5  	"strconv"
     6  	"time"
     7  )
     8  
     9  // Time represents date and time information for Zoho
    10  // Zoho uses milliseconds since unix epoch (Java currentTimeMillis)
    11  type Time time.Time
    12  
    13  // UnmarshalJSON turns JSON into a Time
    14  func (t *Time) UnmarshalJSON(data []byte) error {
    15  	millis, err := strconv.ParseInt(string(data), 10, 64)
    16  	if err != nil {
    17  		return err
    18  	}
    19  	*t = Time(time.Unix(0, millis*int64(time.Millisecond)))
    20  	return nil
    21  }
    22  
    23  // User is a Zoho user we are only interested in the ZUID here
    24  type User struct {
    25  	FirstName   string `json:"First_Name"`
    26  	Email       string `json:"Email"`
    27  	LastName    string `json:"Last_Name"`
    28  	DisplayName string `json:"Display_Name"`
    29  	ZUID        int64  `json:"ZUID"`
    30  }
    31  
    32  // TeamWorkspace represents a Zoho Team or workspace
    33  // It's actually a VERY large json object that differs between
    34  // Team and Workspace but we are only interested in some fields
    35  // that both of them have so we can use the same struct for both
    36  type TeamWorkspace struct {
    37  	ID         string `json:"id"`
    38  	Attributes struct {
    39  		Name    string `json:"name"`
    40  		Created Time   `json:"created_time_in_millisecond"`
    41  		IsPart  bool   `json:"is_partof"`
    42  	} `json:"attributes"`
    43  }
    44  
    45  // TeamWorkspaceResponse is the response by the list teams api
    46  type TeamWorkspaceResponse struct {
    47  	TeamWorkspace []TeamWorkspace `json:"data"`
    48  }
    49  
    50  // Item is may represent a file or a folder in Zoho Workdrive
    51  type Item struct {
    52  	ID         string `json:"id"`
    53  	Attributes struct {
    54  		Name         string `json:"name"`
    55  		Type         string `json:"type"`
    56  		IsFolder     bool   `json:"is_folder"`
    57  		CreatedTime  Time   `json:"created_time_in_millisecond"`
    58  		ModifiedTime Time   `json:"modified_time_in_millisecond"`
    59  		UploadedTime Time   `json:"uploaded_time_in_millisecond"`
    60  		StorageInfo  struct {
    61  			Size        int64 `json:"size_in_bytes"`
    62  			FileCount   int64 `json:"files_count"`
    63  			FolderCount int64 `json:"folders_count"`
    64  		} `json:"storage_info"`
    65  	} `json:"attributes"`
    66  }
    67  
    68  // ItemInfo contains a single Zoho Item
    69  type ItemInfo struct {
    70  	Item Item `json:"data"`
    71  }
    72  
    73  // ItemList contains multiple Zoho Items
    74  type ItemList struct {
    75  	Items []Item `json:"data"`
    76  }
    77  
    78  // UploadInfo is a simplified and slightly different version of
    79  // the Item struct only used in the response to uploads
    80  type UploadInfo struct {
    81  	Attributes struct {
    82  		ParentID    string `json:"parent_id"`
    83  		FileName    string `json:"notes.txt"`
    84  		RessourceID string `json:"resource_id"`
    85  	} `json:"attributes"`
    86  }
    87  
    88  // UploadResponse is the response to a file Upload
    89  type UploadResponse struct {
    90  	Uploads []UploadInfo `json:"data"`
    91  }
    92  
    93  // WriteMetadataRequest is is used to write metadata for a
    94  // single item
    95  type WriteMetadataRequest struct {
    96  	Data WriteMetadata `json:"data"`
    97  }
    98  
    99  // WriteMultiMetadataRequest can be used to write metadata for
   100  // multiple items at once but we don't use it that way
   101  type WriteMultiMetadataRequest struct {
   102  	Meta []WriteMetadata `json:"data"`
   103  }
   104  
   105  // WriteMetadata is used to write item metadata
   106  type WriteMetadata struct {
   107  	Attributes WriteAttributes `json:"attributes,omitempty"`
   108  	ID         string          `json:"id,omitempty"`
   109  	Type       string          `json:"type"`
   110  }
   111  
   112  // WriteAttributes is used to set various attributes for on items
   113  // this is used for Move, Copy, Delete, Rename
   114  type WriteAttributes struct {
   115  	Name        string `json:"name,omitempty"`
   116  	ParentID    string `json:"parent_id,omitempty"`
   117  	RessourceID string `json:"resource_id,omitempty"`
   118  	Status      string `json:"status,omitempty"`
   119  }