github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/box/api/types.go (about) 1 // Package api has type definitions for box 2 // 3 // Converted from the API docs with help from https://mholt.github.io/json-to-go/ 4 package api 5 6 import ( 7 "encoding/json" 8 "fmt" 9 "time" 10 ) 11 12 const ( 13 // 2017-05-03T07:26:10-07:00 14 timeFormat = `"` + time.RFC3339 + `"` 15 ) 16 17 // Time represents represents date and time information for the 18 // box API, by using RFC3339 19 type Time time.Time 20 21 // MarshalJSON turns a Time into JSON (in UTC) 22 func (t *Time) MarshalJSON() (out []byte, err error) { 23 timeString := (*time.Time)(t).Format(timeFormat) 24 return []byte(timeString), nil 25 } 26 27 // UnmarshalJSON turns JSON into a Time 28 func (t *Time) UnmarshalJSON(data []byte) error { 29 newT, err := time.Parse(timeFormat, string(data)) 30 if err != nil { 31 return err 32 } 33 *t = Time(newT) 34 return nil 35 } 36 37 // Error is returned from box when things go wrong 38 type Error struct { 39 Type string `json:"type"` 40 Status int `json:"status"` 41 Code string `json:"code"` 42 ContextInfo json.RawMessage 43 HelpURL string `json:"help_url"` 44 Message string `json:"message"` 45 RequestID string `json:"request_id"` 46 } 47 48 // Error returns a string for the error and satisfies the error interface 49 func (e *Error) Error() string { 50 out := fmt.Sprintf("Error %q (%d)", e.Code, e.Status) 51 if e.Message != "" { 52 out += ": " + e.Message 53 } 54 if e.ContextInfo != nil { 55 out += fmt.Sprintf(" (%+v)", e.ContextInfo) 56 } 57 return out 58 } 59 60 // Check Error satisfies the error interface 61 var _ error = (*Error)(nil) 62 63 // ItemFields are the fields needed for FileInfo 64 var ItemFields = "type,id,sequence_id,etag,sha1,name,size,created_at,modified_at,content_created_at,content_modified_at,item_status,shared_link" 65 66 // Types of things in Item 67 const ( 68 ItemTypeFolder = "folder" 69 ItemTypeFile = "file" 70 ItemStatusActive = "active" 71 ItemStatusTrashed = "trashed" 72 ItemStatusDeleted = "deleted" 73 ) 74 75 // Item describes a folder or a file as returned by Get Folder Items and others 76 type Item struct { 77 Type string `json:"type"` 78 ID string `json:"id"` 79 SequenceID string `json:"sequence_id"` 80 Etag string `json:"etag"` 81 SHA1 string `json:"sha1"` 82 Name string `json:"name"` 83 Size float64 `json:"size"` // box returns this in xEyy format for very large numbers - see #2261 84 CreatedAt Time `json:"created_at"` 85 ModifiedAt Time `json:"modified_at"` 86 ContentCreatedAt Time `json:"content_created_at"` 87 ContentModifiedAt Time `json:"content_modified_at"` 88 ItemStatus string `json:"item_status"` // active, trashed if the file has been moved to the trash, and deleted if the file has been permanently deleted 89 SharedLink struct { 90 URL string `json:"url,omitempty"` 91 Access string `json:"access,omitempty"` 92 } `json:"shared_link"` 93 } 94 95 // ModTime returns the modification time of the item 96 func (i *Item) ModTime() (t time.Time) { 97 t = time.Time(i.ContentModifiedAt) 98 if t.IsZero() { 99 t = time.Time(i.ModifiedAt) 100 } 101 return t 102 } 103 104 // FolderItems is returned from the GetFolderItems call 105 type FolderItems struct { 106 TotalCount int `json:"total_count"` 107 Entries []Item `json:"entries"` 108 Offset int `json:"offset"` 109 Limit int `json:"limit"` 110 Order []struct { 111 By string `json:"by"` 112 Direction string `json:"direction"` 113 } `json:"order"` 114 } 115 116 // Parent defined the ID of the parent directory 117 type Parent struct { 118 ID string `json:"id"` 119 } 120 121 // CreateFolder is the request for Create Folder 122 type CreateFolder struct { 123 Name string `json:"name"` 124 Parent Parent `json:"parent"` 125 } 126 127 // UploadFile is the request for Upload File 128 type UploadFile struct { 129 Name string `json:"name"` 130 Parent Parent `json:"parent"` 131 ContentCreatedAt Time `json:"content_created_at"` 132 ContentModifiedAt Time `json:"content_modified_at"` 133 } 134 135 // UpdateFileModTime is used in Update File Info 136 type UpdateFileModTime struct { 137 ContentModifiedAt Time `json:"content_modified_at"` 138 } 139 140 // UpdateFileMove is the request for Upload File to change name and parent 141 type UpdateFileMove struct { 142 Name string `json:"name"` 143 Parent Parent `json:"parent"` 144 } 145 146 // CopyFile is the request for Copy File 147 type CopyFile struct { 148 Name string `json:"name"` 149 Parent Parent `json:"parent"` 150 } 151 152 // CreateSharedLink is the request for Public Link 153 type CreateSharedLink struct { 154 SharedLink struct { 155 URL string `json:"url,omitempty"` 156 Access string `json:"access,omitempty"` 157 } `json:"shared_link"` 158 } 159 160 // UploadSessionRequest is uses in Create Upload Session 161 type UploadSessionRequest struct { 162 FolderID string `json:"folder_id,omitempty"` // don't pass for update 163 FileSize int64 `json:"file_size"` 164 FileName string `json:"file_name,omitempty"` // optional for update 165 } 166 167 // UploadSessionResponse is returned from Create Upload Session 168 type UploadSessionResponse struct { 169 TotalParts int `json:"total_parts"` 170 PartSize int64 `json:"part_size"` 171 SessionEndpoints struct { 172 ListParts string `json:"list_parts"` 173 Commit string `json:"commit"` 174 UploadPart string `json:"upload_part"` 175 Status string `json:"status"` 176 Abort string `json:"abort"` 177 } `json:"session_endpoints"` 178 SessionExpiresAt Time `json:"session_expires_at"` 179 ID string `json:"id"` 180 Type string `json:"type"` 181 NumPartsProcessed int `json:"num_parts_processed"` 182 } 183 184 // Part defines the return from upload part call which are passed to commit upload also 185 type Part struct { 186 PartID string `json:"part_id"` 187 Offset int64 `json:"offset"` 188 Size int64 `json:"size"` 189 Sha1 string `json:"sha1"` 190 } 191 192 // UploadPartResponse is returned from the upload part call 193 type UploadPartResponse struct { 194 Part Part `json:"part"` 195 } 196 197 // CommitUpload is used in the Commit Upload call 198 type CommitUpload struct { 199 Parts []Part `json:"parts"` 200 Attributes struct { 201 ContentCreatedAt Time `json:"content_created_at"` 202 ContentModifiedAt Time `json:"content_modified_at"` 203 } `json:"attributes"` 204 } 205 206 // ConfigJSON defines the shape of a box config.json 207 type ConfigJSON struct { 208 BoxAppSettings AppSettings `json:"boxAppSettings"` 209 EnterpriseID string `json:"enterpriseID"` 210 } 211 212 // AppSettings defines the shape of the boxAppSettings within box config.json 213 type AppSettings struct { 214 ClientID string `json:"clientID"` 215 ClientSecret string `json:"clientSecret"` 216 AppAuth AppAuth `json:"appAuth"` 217 } 218 219 // AppAuth defines the shape of the appAuth within boxAppSettings in config.json 220 type AppAuth struct { 221 PublicKeyID string `json:"publicKeyID"` 222 PrivateKey string `json:"privateKey"` 223 Passphrase string `json:"passphrase"` 224 } 225 226 // User is returned from /users/me 227 type User struct { 228 Type string `json:"type"` 229 ID string `json:"id"` 230 Name string `json:"name"` 231 Login string `json:"login"` 232 CreatedAt time.Time `json:"created_at"` 233 ModifiedAt time.Time `json:"modified_at"` 234 Language string `json:"language"` 235 Timezone string `json:"timezone"` 236 SpaceAmount int64 `json:"space_amount"` 237 SpaceUsed int64 `json:"space_used"` 238 MaxUploadSize int64 `json:"max_upload_size"` 239 Status string `json:"status"` 240 JobTitle string `json:"job_title"` 241 Phone string `json:"phone"` 242 Address string `json:"address"` 243 AvatarURL string `json:"avatar_url"` 244 }