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.
 
 
 

388 lines
12 KiB

  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Code generated file. DO NOT EDIT.
  5. // Package groupsmigration provides access to the Groups Migration API.
  6. //
  7. // For product documentation, see: https://developers.google.com/google-apps/groups-migration/
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/groupsmigration/v1"
  14. // ...
  15. // ctx := context.Background()
  16. // groupsmigrationService, err := groupsmigration.NewService(ctx)
  17. //
  18. // In this example, Google Application Default Credentials are used for authentication.
  19. //
  20. // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
  21. //
  22. // Other authentication options
  23. //
  24. // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
  25. //
  26. // groupsmigrationService, err := groupsmigration.NewService(ctx, option.WithAPIKey("AIza..."))
  27. //
  28. // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
  29. //
  30. // config := &oauth2.Config{...}
  31. // // ...
  32. // token, err := config.Exchange(ctx, ...)
  33. // groupsmigrationService, err := groupsmigration.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
  34. //
  35. // See https://godoc.org/google.golang.org/api/option/ for details on options.
  36. package groupsmigration // import "google.golang.org/api/groupsmigration/v1"
  37. import (
  38. "bytes"
  39. "context"
  40. "encoding/json"
  41. "errors"
  42. "fmt"
  43. "io"
  44. "net/http"
  45. "net/url"
  46. "strconv"
  47. "strings"
  48. gensupport "google.golang.org/api/gensupport"
  49. googleapi "google.golang.org/api/googleapi"
  50. option "google.golang.org/api/option"
  51. htransport "google.golang.org/api/transport/http"
  52. )
  53. // Always reference these packages, just in case the auto-generated code
  54. // below doesn't.
  55. var _ = bytes.NewBuffer
  56. var _ = strconv.Itoa
  57. var _ = fmt.Sprintf
  58. var _ = json.NewDecoder
  59. var _ = io.Copy
  60. var _ = url.Parse
  61. var _ = gensupport.MarshalJSON
  62. var _ = googleapi.Version
  63. var _ = errors.New
  64. var _ = strings.Replace
  65. var _ = context.Canceled
  66. const apiId = "groupsmigration:v1"
  67. const apiName = "groupsmigration"
  68. const apiVersion = "v1"
  69. const basePath = "https://www.googleapis.com/groups/v1/groups/"
  70. // OAuth2 scopes used by this API.
  71. const (
  72. // Manage messages in groups on your domain
  73. AppsGroupsMigrationScope = "https://www.googleapis.com/auth/apps.groups.migration"
  74. )
  75. // NewService creates a new Service.
  76. func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
  77. scopesOption := option.WithScopes(
  78. "https://www.googleapis.com/auth/apps.groups.migration",
  79. )
  80. // NOTE: prepend, so we don't override user-specified scopes.
  81. opts = append([]option.ClientOption{scopesOption}, opts...)
  82. client, endpoint, err := htransport.NewClient(ctx, opts...)
  83. if err != nil {
  84. return nil, err
  85. }
  86. s, err := New(client)
  87. if err != nil {
  88. return nil, err
  89. }
  90. if endpoint != "" {
  91. s.BasePath = endpoint
  92. }
  93. return s, nil
  94. }
  95. // New creates a new Service. It uses the provided http.Client for requests.
  96. //
  97. // Deprecated: please use NewService instead.
  98. // To provide a custom HTTP client, use option.WithHTTPClient.
  99. // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
  100. func New(client *http.Client) (*Service, error) {
  101. if client == nil {
  102. return nil, errors.New("client is nil")
  103. }
  104. s := &Service{client: client, BasePath: basePath}
  105. s.Archive = NewArchiveService(s)
  106. return s, nil
  107. }
  108. type Service struct {
  109. client *http.Client
  110. BasePath string // API endpoint base URL
  111. UserAgent string // optional additional User-Agent fragment
  112. Archive *ArchiveService
  113. }
  114. func (s *Service) userAgent() string {
  115. if s.UserAgent == "" {
  116. return googleapi.UserAgent
  117. }
  118. return googleapi.UserAgent + " " + s.UserAgent
  119. }
  120. func NewArchiveService(s *Service) *ArchiveService {
  121. rs := &ArchiveService{s: s}
  122. return rs
  123. }
  124. type ArchiveService struct {
  125. s *Service
  126. }
  127. // Groups: JSON response template for groups migration API.
  128. type Groups struct {
  129. // Kind: The kind of insert resource this is.
  130. Kind string `json:"kind,omitempty"`
  131. // ResponseCode: The status of the insert request.
  132. ResponseCode string `json:"responseCode,omitempty"`
  133. // ServerResponse contains the HTTP response code and headers from the
  134. // server.
  135. googleapi.ServerResponse `json:"-"`
  136. // ForceSendFields is a list of field names (e.g. "Kind") to
  137. // unconditionally include in API requests. By default, fields with
  138. // empty values are omitted from API requests. However, any non-pointer,
  139. // non-interface field appearing in ForceSendFields will be sent to the
  140. // server regardless of whether the field is empty or not. This may be
  141. // used to include empty fields in Patch requests.
  142. ForceSendFields []string `json:"-"`
  143. // NullFields is a list of field names (e.g. "Kind") to include in API
  144. // requests with the JSON null value. By default, fields with empty
  145. // values are omitted from API requests. However, any field with an
  146. // empty value appearing in NullFields will be sent to the server as
  147. // null. It is an error if a field in this list has a non-empty value.
  148. // This may be used to include null fields in Patch requests.
  149. NullFields []string `json:"-"`
  150. }
  151. func (s *Groups) MarshalJSON() ([]byte, error) {
  152. type NoMethod Groups
  153. raw := NoMethod(*s)
  154. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  155. }
  156. // method id "groupsmigration.archive.insert":
  157. type ArchiveInsertCall struct {
  158. s *Service
  159. groupId string
  160. urlParams_ gensupport.URLParams
  161. mediaInfo_ *gensupport.MediaInfo
  162. ctx_ context.Context
  163. header_ http.Header
  164. }
  165. // Insert: Inserts a new mail into the archive of the Google group.
  166. func (r *ArchiveService) Insert(groupId string) *ArchiveInsertCall {
  167. c := &ArchiveInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  168. c.groupId = groupId
  169. return c
  170. }
  171. // Media specifies the media to upload in one or more chunks. The chunk
  172. // size may be controlled by supplying a MediaOption generated by
  173. // googleapi.ChunkSize. The chunk size defaults to
  174. // googleapi.DefaultUploadChunkSize.The Content-Type header used in the
  175. // upload request will be determined by sniffing the contents of r,
  176. // unless a MediaOption generated by googleapi.ContentType is
  177. // supplied.
  178. // At most one of Media and ResumableMedia may be set.
  179. func (c *ArchiveInsertCall) Media(r io.Reader, options ...googleapi.MediaOption) *ArchiveInsertCall {
  180. c.mediaInfo_ = gensupport.NewInfoFromMedia(r, options)
  181. return c
  182. }
  183. // ResumableMedia specifies the media to upload in chunks and can be
  184. // canceled with ctx.
  185. //
  186. // Deprecated: use Media instead.
  187. //
  188. // At most one of Media and ResumableMedia may be set. mediaType
  189. // identifies the MIME media type of the upload, such as "image/png". If
  190. // mediaType is "", it will be auto-detected. The provided ctx will
  191. // supersede any context previously provided to the Context method.
  192. func (c *ArchiveInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *ArchiveInsertCall {
  193. c.ctx_ = ctx
  194. c.mediaInfo_ = gensupport.NewInfoFromResumableMedia(r, size, mediaType)
  195. return c
  196. }
  197. // ProgressUpdater provides a callback function that will be called
  198. // after every chunk. It should be a low-latency function in order to
  199. // not slow down the upload operation. This should only be called when
  200. // using ResumableMedia (as opposed to Media).
  201. func (c *ArchiveInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *ArchiveInsertCall {
  202. c.mediaInfo_.SetProgressUpdater(pu)
  203. return c
  204. }
  205. // Fields allows partial responses to be retrieved. See
  206. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  207. // for more information.
  208. func (c *ArchiveInsertCall) Fields(s ...googleapi.Field) *ArchiveInsertCall {
  209. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  210. return c
  211. }
  212. // Context sets the context to be used in this call's Do method. Any
  213. // pending HTTP request will be aborted if the provided context is
  214. // canceled.
  215. // This context will supersede any context previously provided to the
  216. // ResumableMedia method.
  217. func (c *ArchiveInsertCall) Context(ctx context.Context) *ArchiveInsertCall {
  218. c.ctx_ = ctx
  219. return c
  220. }
  221. // Header returns an http.Header that can be modified by the caller to
  222. // add HTTP headers to the request.
  223. func (c *ArchiveInsertCall) Header() http.Header {
  224. if c.header_ == nil {
  225. c.header_ = make(http.Header)
  226. }
  227. return c.header_
  228. }
  229. func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
  230. reqHeaders := make(http.Header)
  231. for k, v := range c.header_ {
  232. reqHeaders[k] = v
  233. }
  234. reqHeaders.Set("User-Agent", c.s.userAgent())
  235. var body io.Reader = nil
  236. c.urlParams_.Set("alt", alt)
  237. c.urlParams_.Set("prettyPrint", "false")
  238. urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
  239. if c.mediaInfo_ != nil {
  240. urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
  241. c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())
  242. }
  243. if body == nil {
  244. body = new(bytes.Buffer)
  245. reqHeaders.Set("Content-Type", "application/json")
  246. }
  247. body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)
  248. defer cleanup()
  249. urls += "?" + c.urlParams_.Encode()
  250. req, err := http.NewRequest("POST", urls, body)
  251. if err != nil {
  252. return nil, err
  253. }
  254. req.Header = reqHeaders
  255. req.GetBody = getBody
  256. googleapi.Expand(req.URL, map[string]string{
  257. "groupId": c.groupId,
  258. })
  259. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  260. }
  261. // Do executes the "groupsmigration.archive.insert" call.
  262. // Exactly one of *Groups or error will be non-nil. Any non-2xx status
  263. // code is an error. Response headers are in either
  264. // *Groups.ServerResponse.Header or (if a response was returned at all)
  265. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  266. // check whether the returned error was because http.StatusNotModified
  267. // was returned.
  268. func (c *ArchiveInsertCall) Do(opts ...googleapi.CallOption) (*Groups, error) {
  269. gensupport.SetOptions(c.urlParams_, opts...)
  270. res, err := c.doRequest("json")
  271. if res != nil && res.StatusCode == http.StatusNotModified {
  272. if res.Body != nil {
  273. res.Body.Close()
  274. }
  275. return nil, &googleapi.Error{
  276. Code: res.StatusCode,
  277. Header: res.Header,
  278. }
  279. }
  280. if err != nil {
  281. return nil, err
  282. }
  283. defer googleapi.CloseBody(res)
  284. if err := googleapi.CheckResponse(res); err != nil {
  285. return nil, err
  286. }
  287. rx := c.mediaInfo_.ResumableUpload(res.Header.Get("Location"))
  288. if rx != nil {
  289. rx.Client = c.s.client
  290. rx.UserAgent = c.s.userAgent()
  291. ctx := c.ctx_
  292. if ctx == nil {
  293. ctx = context.TODO()
  294. }
  295. res, err = rx.Upload(ctx)
  296. if err != nil {
  297. return nil, err
  298. }
  299. defer res.Body.Close()
  300. if err := googleapi.CheckResponse(res); err != nil {
  301. return nil, err
  302. }
  303. }
  304. ret := &Groups{
  305. ServerResponse: googleapi.ServerResponse{
  306. Header: res.Header,
  307. HTTPStatusCode: res.StatusCode,
  308. },
  309. }
  310. target := &ret
  311. if err := gensupport.DecodeResponse(target, res); err != nil {
  312. return nil, err
  313. }
  314. return ret, nil
  315. // {
  316. // "description": "Inserts a new mail into the archive of the Google group.",
  317. // "httpMethod": "POST",
  318. // "id": "groupsmigration.archive.insert",
  319. // "mediaUpload": {
  320. // "accept": [
  321. // "message/rfc822"
  322. // ],
  323. // "maxSize": "25MB",
  324. // "protocols": {
  325. // "resumable": {
  326. // "multipart": true,
  327. // "path": "/resumable/upload/groups/v1/groups/{groupId}/archive"
  328. // },
  329. // "simple": {
  330. // "multipart": true,
  331. // "path": "/upload/groups/v1/groups/{groupId}/archive"
  332. // }
  333. // }
  334. // },
  335. // "parameterOrder": [
  336. // "groupId"
  337. // ],
  338. // "parameters": {
  339. // "groupId": {
  340. // "description": "The group ID",
  341. // "location": "path",
  342. // "required": true,
  343. // "type": "string"
  344. // }
  345. // },
  346. // "path": "{groupId}/archive",
  347. // "response": {
  348. // "$ref": "Groups"
  349. // },
  350. // "scopes": [
  351. // "https://www.googleapis.com/auth/apps.groups.migration"
  352. // ],
  353. // "supportsMediaUpload": true
  354. // }
  355. }