admin-gen.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // Package admin provides access to the Email Migration API v2.
  2. //
  3. // See https://developers.google.com/admin-sdk/email-migration/v2/
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/admin/email_migration/v2"
  8. // ...
  9. // adminService, err := admin.New(oauthHttpClient)
  10. package admin // import "google.golang.org/api/admin/email_migration/v2"
  11. import (
  12. "bytes"
  13. "encoding/json"
  14. "errors"
  15. "fmt"
  16. context "golang.org/x/net/context"
  17. ctxhttp "golang.org/x/net/context/ctxhttp"
  18. gensupport "google.golang.org/api/gensupport"
  19. googleapi "google.golang.org/api/googleapi"
  20. "io"
  21. "net/http"
  22. "net/url"
  23. "strconv"
  24. "strings"
  25. )
  26. // Always reference these packages, just in case the auto-generated code
  27. // below doesn't.
  28. var _ = bytes.NewBuffer
  29. var _ = strconv.Itoa
  30. var _ = fmt.Sprintf
  31. var _ = json.NewDecoder
  32. var _ = io.Copy
  33. var _ = url.Parse
  34. var _ = gensupport.MarshalJSON
  35. var _ = googleapi.Version
  36. var _ = errors.New
  37. var _ = strings.Replace
  38. var _ = context.Canceled
  39. var _ = ctxhttp.Do
  40. const apiId = "admin:email_migration_v2"
  41. const apiName = "admin"
  42. const apiVersion = "email_migration_v2"
  43. const basePath = "https://www.googleapis.com/email/v2/users/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // Manage email messages of users on your domain
  47. EmailMigrationScope = "https://www.googleapis.com/auth/email.migration"
  48. )
  49. func New(client *http.Client) (*Service, error) {
  50. if client == nil {
  51. return nil, errors.New("client is nil")
  52. }
  53. s := &Service{client: client, BasePath: basePath}
  54. s.Mail = NewMailService(s)
  55. return s, nil
  56. }
  57. type Service struct {
  58. client *http.Client
  59. BasePath string // API endpoint base URL
  60. UserAgent string // optional additional User-Agent fragment
  61. Mail *MailService
  62. }
  63. func (s *Service) userAgent() string {
  64. if s.UserAgent == "" {
  65. return googleapi.UserAgent
  66. }
  67. return googleapi.UserAgent + " " + s.UserAgent
  68. }
  69. func NewMailService(s *Service) *MailService {
  70. rs := &MailService{s: s}
  71. return rs
  72. }
  73. type MailService struct {
  74. s *Service
  75. }
  76. // MailItem: JSON template for MailItem object in Email Migration API.
  77. type MailItem struct {
  78. // IsDeleted: Boolean indicating if the mail is deleted (used in Vault)
  79. IsDeleted bool `json:"isDeleted,omitempty"`
  80. // IsDraft: Boolean indicating if the mail is draft
  81. IsDraft bool `json:"isDraft,omitempty"`
  82. // IsInbox: Boolean indicating if the mail is in inbox
  83. IsInbox bool `json:"isInbox,omitempty"`
  84. // IsSent: Boolean indicating if the mail is in 'sent mails'
  85. IsSent bool `json:"isSent,omitempty"`
  86. // IsStarred: Boolean indicating if the mail is starred
  87. IsStarred bool `json:"isStarred,omitempty"`
  88. // IsTrash: Boolean indicating if the mail is in trash
  89. IsTrash bool `json:"isTrash,omitempty"`
  90. // IsUnread: Boolean indicating if the mail is unread
  91. IsUnread bool `json:"isUnread,omitempty"`
  92. // Kind: Kind of resource this is.
  93. Kind string `json:"kind,omitempty"`
  94. // Labels: List of labels (strings)
  95. Labels []string `json:"labels,omitempty"`
  96. // ForceSendFields is a list of field names (e.g. "IsDeleted") to
  97. // unconditionally include in API requests. By default, fields with
  98. // empty values are omitted from API requests. However, any non-pointer,
  99. // non-interface field appearing in ForceSendFields will be sent to the
  100. // server regardless of whether the field is empty or not. This may be
  101. // used to include empty fields in Patch requests.
  102. ForceSendFields []string `json:"-"`
  103. }
  104. func (s *MailItem) MarshalJSON() ([]byte, error) {
  105. type noMethod MailItem
  106. raw := noMethod(*s)
  107. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  108. }
  109. // method id "emailMigration.mail.insert":
  110. type MailInsertCall struct {
  111. s *Service
  112. userKey string
  113. mailitem *MailItem
  114. urlParams_ gensupport.URLParams
  115. media_ io.Reader
  116. resumableBuffer_ *gensupport.ResumableBuffer
  117. mediaType_ string
  118. mediaSize_ int64 // mediaSize, if known. Used only for calls to progressUpdater_.
  119. progressUpdater_ googleapi.ProgressUpdater
  120. ctx_ context.Context
  121. }
  122. // Insert: Insert Mail into Google's Gmail backends
  123. func (r *MailService) Insert(userKey string, mailitem *MailItem) *MailInsertCall {
  124. c := &MailInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  125. c.userKey = userKey
  126. c.mailitem = mailitem
  127. return c
  128. }
  129. // Media specifies the media to upload in one or more chunks. The chunk
  130. // size may be controlled by supplying a MediaOption generated by
  131. // googleapi.ChunkSize. The chunk size defaults to
  132. // googleapi.DefaultUploadChunkSize.
  133. // At most one of Media and ResumableMedia may be set.
  134. func (c *MailInsertCall) Media(r io.Reader, options ...googleapi.MediaOption) *MailInsertCall {
  135. opts := googleapi.ProcessMediaOptions(options)
  136. chunkSize := opts.ChunkSize
  137. r, c.mediaType_ = gensupport.DetermineContentType(r, opts.ContentType)
  138. c.media_, c.resumableBuffer_ = gensupport.PrepareUpload(r, chunkSize)
  139. return c
  140. }
  141. // ResumableMedia specifies the media to upload in chunks and can be
  142. // canceled with ctx.
  143. //
  144. // Deprecated: use Media instead.
  145. //
  146. // At most one of Media and ResumableMedia may be set. mediaType
  147. // identifies the MIME media type of the upload, such as "image/png". If
  148. // mediaType is "", it will be auto-detected. The provided ctx will
  149. // supersede any context previously provided to the Context method.
  150. func (c *MailInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *MailInsertCall {
  151. c.ctx_ = ctx
  152. rdr := gensupport.ReaderAtToReader(r, size)
  153. rdr, c.mediaType_ = gensupport.DetermineContentType(rdr, mediaType)
  154. c.resumableBuffer_ = gensupport.NewResumableBuffer(rdr, googleapi.DefaultUploadChunkSize)
  155. c.media_ = nil
  156. c.mediaSize_ = size
  157. return c
  158. }
  159. // ProgressUpdater provides a callback function that will be called
  160. // after every chunk. It should be a low-latency function in order to
  161. // not slow down the upload operation. This should only be called when
  162. // using ResumableMedia (as opposed to Media).
  163. func (c *MailInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *MailInsertCall {
  164. c.progressUpdater_ = pu
  165. return c
  166. }
  167. // Fields allows partial responses to be retrieved. See
  168. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  169. // for more information.
  170. func (c *MailInsertCall) Fields(s ...googleapi.Field) *MailInsertCall {
  171. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  172. return c
  173. }
  174. // Context sets the context to be used in this call's Do method. Any
  175. // pending HTTP request will be aborted if the provided context is
  176. // canceled.
  177. // This context will supersede any context previously provided to the
  178. // ResumableMedia method.
  179. func (c *MailInsertCall) Context(ctx context.Context) *MailInsertCall {
  180. c.ctx_ = ctx
  181. return c
  182. }
  183. func (c *MailInsertCall) doRequest(alt string) (*http.Response, error) {
  184. var body io.Reader = nil
  185. body, err := googleapi.WithoutDataWrapper.JSONReader(c.mailitem)
  186. if err != nil {
  187. return nil, err
  188. }
  189. ctype := "application/json"
  190. c.urlParams_.Set("alt", alt)
  191. urls := googleapi.ResolveRelative(c.s.BasePath, "{userKey}/mail")
  192. if c.media_ != nil || c.resumableBuffer_ != nil {
  193. urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
  194. protocol := "multipart"
  195. if c.resumableBuffer_ != nil {
  196. protocol = "resumable"
  197. }
  198. c.urlParams_.Set("uploadType", protocol)
  199. }
  200. urls += "?" + c.urlParams_.Encode()
  201. if c.media_ != nil {
  202. var combined io.ReadCloser
  203. combined, ctype = gensupport.CombineBodyMedia(body, ctype, c.media_, c.mediaType_)
  204. defer combined.Close()
  205. body = combined
  206. }
  207. req, _ := http.NewRequest("POST", urls, body)
  208. googleapi.Expand(req.URL, map[string]string{
  209. "userKey": c.userKey,
  210. })
  211. if c.resumableBuffer_ != nil {
  212. req.Header.Set("X-Upload-Content-Type", c.mediaType_)
  213. }
  214. req.Header.Set("Content-Type", ctype)
  215. req.Header.Set("User-Agent", c.s.userAgent())
  216. if c.ctx_ != nil {
  217. return ctxhttp.Do(c.ctx_, c.s.client, req)
  218. }
  219. return c.s.client.Do(req)
  220. }
  221. // Do executes the "emailMigration.mail.insert" call.
  222. func (c *MailInsertCall) Do(opts ...googleapi.CallOption) error {
  223. gensupport.SetOptions(c.urlParams_, opts...)
  224. res, err := gensupport.Retry(c.ctx_, func() (*http.Response, error) {
  225. return c.doRequest("json")
  226. }, gensupport.DefaultBackoffStrategy())
  227. if err != nil {
  228. return err
  229. }
  230. defer googleapi.CloseBody(res)
  231. if err := googleapi.CheckResponse(res); err != nil {
  232. return err
  233. }
  234. if c.resumableBuffer_ != nil {
  235. loc := res.Header.Get("Location")
  236. rx := &gensupport.ResumableUpload{
  237. Client: c.s.client,
  238. UserAgent: c.s.userAgent(),
  239. URI: loc,
  240. Media: c.resumableBuffer_,
  241. MediaType: c.mediaType_,
  242. Callback: func(curr int64) {
  243. if c.progressUpdater_ != nil {
  244. c.progressUpdater_(curr, c.mediaSize_)
  245. }
  246. },
  247. }
  248. ctx := c.ctx_
  249. if ctx == nil {
  250. ctx = context.TODO()
  251. }
  252. res, err = rx.Upload(ctx)
  253. if err != nil {
  254. return err
  255. }
  256. defer res.Body.Close()
  257. if err := googleapi.CheckResponse(res); err != nil {
  258. return err
  259. }
  260. }
  261. return nil
  262. // {
  263. // "description": "Insert Mail into Google's Gmail backends",
  264. // "httpMethod": "POST",
  265. // "id": "emailMigration.mail.insert",
  266. // "mediaUpload": {
  267. // "accept": [
  268. // "message/rfc822"
  269. // ],
  270. // "maxSize": "35MB",
  271. // "protocols": {
  272. // "resumable": {
  273. // "multipart": true,
  274. // "path": "/resumable/upload/email/v2/users/{userKey}/mail"
  275. // },
  276. // "simple": {
  277. // "multipart": true,
  278. // "path": "/upload/email/v2/users/{userKey}/mail"
  279. // }
  280. // }
  281. // },
  282. // "parameterOrder": [
  283. // "userKey"
  284. // ],
  285. // "parameters": {
  286. // "userKey": {
  287. // "description": "The email or immutable id of the user",
  288. // "location": "path",
  289. // "required": true,
  290. // "type": "string"
  291. // }
  292. // },
  293. // "path": "{userKey}/mail",
  294. // "request": {
  295. // "$ref": "MailItem"
  296. // },
  297. // "scopes": [
  298. // "https://www.googleapis.com/auth/email.migration"
  299. // ],
  300. // "supportsMediaUpload": true
  301. // }
  302. }