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.
 
 
 

329 lines
9.9 KiB

  1. // Package groupsmigration provides access to the Groups Migration API.
  2. //
  3. // See https://developers.google.com/google-apps/groups-migration/
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/groupsmigration/v1"
  8. // ...
  9. // groupsmigrationService, err := groupsmigration.New(oauthHttpClient)
  10. package groupsmigration // import "google.golang.org/api/groupsmigration/v1"
  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 = "groupsmigration:v1"
  41. const apiName = "groupsmigration"
  42. const apiVersion = "v1"
  43. const basePath = "https://www.googleapis.com/groups/v1/groups/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // Manage messages in groups on your domain
  47. AppsGroupsMigrationScope = "https://www.googleapis.com/auth/apps.groups.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.Archive = NewArchiveService(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. Archive *ArchiveService
  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 NewArchiveService(s *Service) *ArchiveService {
  70. rs := &ArchiveService{s: s}
  71. return rs
  72. }
  73. type ArchiveService struct {
  74. s *Service
  75. }
  76. // Groups: JSON response template for groups migration API.
  77. type Groups struct {
  78. // Kind: The kind of insert resource this is.
  79. Kind string `json:"kind,omitempty"`
  80. // ResponseCode: The status of the insert request.
  81. ResponseCode string `json:"responseCode,omitempty"`
  82. // ServerResponse contains the HTTP response code and headers from the
  83. // server.
  84. googleapi.ServerResponse `json:"-"`
  85. // ForceSendFields is a list of field names (e.g. "Kind") to
  86. // unconditionally include in API requests. By default, fields with
  87. // empty values are omitted from API requests. However, any non-pointer,
  88. // non-interface field appearing in ForceSendFields will be sent to the
  89. // server regardless of whether the field is empty or not. This may be
  90. // used to include empty fields in Patch requests.
  91. ForceSendFields []string `json:"-"`
  92. // NullFields is a list of field names (e.g. "Kind") to include in API
  93. // requests with the JSON null value. By default, fields with empty
  94. // values are omitted from API requests. However, any field with an
  95. // empty value appearing in NullFields will be sent to the server as
  96. // null. It is an error if a field in this list has a non-empty value.
  97. // This may be used to include null fields in Patch requests.
  98. NullFields []string `json:"-"`
  99. }
  100. func (s *Groups) MarshalJSON() ([]byte, error) {
  101. type NoMethod Groups
  102. raw := NoMethod(*s)
  103. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  104. }
  105. // method id "groupsmigration.archive.insert":
  106. type ArchiveInsertCall struct {
  107. s *Service
  108. groupId string
  109. urlParams_ gensupport.URLParams
  110. mediaInfo_ *gensupport.MediaInfo
  111. ctx_ context.Context
  112. header_ http.Header
  113. }
  114. // Insert: Inserts a new mail into the archive of the Google group.
  115. func (r *ArchiveService) Insert(groupId string) *ArchiveInsertCall {
  116. c := &ArchiveInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  117. c.groupId = groupId
  118. return c
  119. }
  120. // Media specifies the media to upload in one or more chunks. The chunk
  121. // size may be controlled by supplying a MediaOption generated by
  122. // googleapi.ChunkSize. The chunk size defaults to
  123. // googleapi.DefaultUploadChunkSize.The Content-Type header used in the
  124. // upload request will be determined by sniffing the contents of r,
  125. // unless a MediaOption generated by googleapi.ContentType is
  126. // supplied.
  127. // At most one of Media and ResumableMedia may be set.
  128. func (c *ArchiveInsertCall) Media(r io.Reader, options ...googleapi.MediaOption) *ArchiveInsertCall {
  129. c.mediaInfo_ = gensupport.NewInfoFromMedia(r, options)
  130. return c
  131. }
  132. // ResumableMedia specifies the media to upload in chunks and can be
  133. // canceled with ctx.
  134. //
  135. // Deprecated: use Media instead.
  136. //
  137. // At most one of Media and ResumableMedia may be set. mediaType
  138. // identifies the MIME media type of the upload, such as "image/png". If
  139. // mediaType is "", it will be auto-detected. The provided ctx will
  140. // supersede any context previously provided to the Context method.
  141. func (c *ArchiveInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *ArchiveInsertCall {
  142. c.ctx_ = ctx
  143. c.mediaInfo_ = gensupport.NewInfoFromResumableMedia(r, size, mediaType)
  144. return c
  145. }
  146. // ProgressUpdater provides a callback function that will be called
  147. // after every chunk. It should be a low-latency function in order to
  148. // not slow down the upload operation. This should only be called when
  149. // using ResumableMedia (as opposed to Media).
  150. func (c *ArchiveInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *ArchiveInsertCall {
  151. c.mediaInfo_.SetProgressUpdater(pu)
  152. return c
  153. }
  154. // Fields allows partial responses to be retrieved. See
  155. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  156. // for more information.
  157. func (c *ArchiveInsertCall) Fields(s ...googleapi.Field) *ArchiveInsertCall {
  158. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  159. return c
  160. }
  161. // Context sets the context to be used in this call's Do method. Any
  162. // pending HTTP request will be aborted if the provided context is
  163. // canceled.
  164. // This context will supersede any context previously provided to the
  165. // ResumableMedia method.
  166. func (c *ArchiveInsertCall) Context(ctx context.Context) *ArchiveInsertCall {
  167. c.ctx_ = ctx
  168. return c
  169. }
  170. // Header returns an http.Header that can be modified by the caller to
  171. // add HTTP headers to the request.
  172. func (c *ArchiveInsertCall) Header() http.Header {
  173. if c.header_ == nil {
  174. c.header_ = make(http.Header)
  175. }
  176. return c.header_
  177. }
  178. func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
  179. reqHeaders := make(http.Header)
  180. for k, v := range c.header_ {
  181. reqHeaders[k] = v
  182. }
  183. reqHeaders.Set("User-Agent", c.s.userAgent())
  184. var body io.Reader = nil
  185. c.urlParams_.Set("alt", alt)
  186. urls := googleapi.ResolveRelative(c.s.BasePath, "{groupId}/archive")
  187. if c.mediaInfo_ != nil {
  188. urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
  189. c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())
  190. }
  191. if body == nil {
  192. body = new(bytes.Buffer)
  193. reqHeaders.Set("Content-Type", "application/json")
  194. }
  195. body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)
  196. defer cleanup()
  197. urls += "?" + c.urlParams_.Encode()
  198. req, _ := http.NewRequest("POST", urls, body)
  199. req.Header = reqHeaders
  200. gensupport.SetGetBody(req, getBody)
  201. googleapi.Expand(req.URL, map[string]string{
  202. "groupId": c.groupId,
  203. })
  204. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  205. }
  206. // Do executes the "groupsmigration.archive.insert" call.
  207. // Exactly one of *Groups or error will be non-nil. Any non-2xx status
  208. // code is an error. Response headers are in either
  209. // *Groups.ServerResponse.Header or (if a response was returned at all)
  210. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  211. // check whether the returned error was because http.StatusNotModified
  212. // was returned.
  213. func (c *ArchiveInsertCall) Do(opts ...googleapi.CallOption) (*Groups, error) {
  214. gensupport.SetOptions(c.urlParams_, opts...)
  215. res, err := c.doRequest("json")
  216. if res != nil && res.StatusCode == http.StatusNotModified {
  217. if res.Body != nil {
  218. res.Body.Close()
  219. }
  220. return nil, &googleapi.Error{
  221. Code: res.StatusCode,
  222. Header: res.Header,
  223. }
  224. }
  225. if err != nil {
  226. return nil, err
  227. }
  228. defer googleapi.CloseBody(res)
  229. if err := googleapi.CheckResponse(res); err != nil {
  230. return nil, err
  231. }
  232. rx := c.mediaInfo_.ResumableUpload(res.Header.Get("Location"))
  233. if rx != nil {
  234. rx.Client = c.s.client
  235. rx.UserAgent = c.s.userAgent()
  236. ctx := c.ctx_
  237. if ctx == nil {
  238. ctx = context.TODO()
  239. }
  240. res, err = rx.Upload(ctx)
  241. if err != nil {
  242. return nil, err
  243. }
  244. defer res.Body.Close()
  245. if err := googleapi.CheckResponse(res); err != nil {
  246. return nil, err
  247. }
  248. }
  249. ret := &Groups{
  250. ServerResponse: googleapi.ServerResponse{
  251. Header: res.Header,
  252. HTTPStatusCode: res.StatusCode,
  253. },
  254. }
  255. target := &ret
  256. if err := gensupport.DecodeResponse(target, res); err != nil {
  257. return nil, err
  258. }
  259. return ret, nil
  260. // {
  261. // "description": "Inserts a new mail into the archive of the Google group.",
  262. // "httpMethod": "POST",
  263. // "id": "groupsmigration.archive.insert",
  264. // "mediaUpload": {
  265. // "accept": [
  266. // "message/rfc822"
  267. // ],
  268. // "maxSize": "16MB",
  269. // "protocols": {
  270. // "resumable": {
  271. // "multipart": true,
  272. // "path": "/resumable/upload/groups/v1/groups/{groupId}/archive"
  273. // },
  274. // "simple": {
  275. // "multipart": true,
  276. // "path": "/upload/groups/v1/groups/{groupId}/archive"
  277. // }
  278. // }
  279. // },
  280. // "parameterOrder": [
  281. // "groupId"
  282. // ],
  283. // "parameters": {
  284. // "groupId": {
  285. // "description": "The group ID",
  286. // "location": "path",
  287. // "required": true,
  288. // "type": "string"
  289. // }
  290. // },
  291. // "path": "{groupId}/archive",
  292. // "response": {
  293. // "$ref": "Groups"
  294. // },
  295. // "scopes": [
  296. // "https://www.googleapis.com/auth/apps.groups.migration"
  297. // ],
  298. // "supportsMediaUpload": true
  299. // }
  300. }