1 | <?php
|
---|
2 | /*
|
---|
3 | * Copyright 2014 Google Inc.
|
---|
4 | *
|
---|
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
---|
6 | * use this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at
|
---|
8 | *
|
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | *
|
---|
11 | * Unless required by applicable law or agreed to in writing, software
|
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
---|
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
---|
14 | * License for the specific language governing permissions and limitations under
|
---|
15 | * the License.
|
---|
16 | */
|
---|
17 |
|
---|
18 | namespace Google\Service\CloudSupport\Resource;
|
---|
19 |
|
---|
20 | use Google\Service\CloudSupport\Attachment;
|
---|
21 | use Google\Service\CloudSupport\CreateAttachmentRequest;
|
---|
22 | use Google\Service\CloudSupport\Media as MediaModel;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * The "media" collection of methods.
|
---|
26 | * Typical usage is:
|
---|
27 | * <code>
|
---|
28 | * $cloudsupportService = new Google\Service\CloudSupport(...);
|
---|
29 | * $media = $cloudsupportService->media;
|
---|
30 | * </code>
|
---|
31 | */
|
---|
32 | class Media extends \Google\Service\Resource
|
---|
33 | {
|
---|
34 | /**
|
---|
35 | * Download a file attached to a case. Note: HTTP requests must append
|
---|
36 | * "?alt=media" to the URL. EXAMPLES: cURL: ```shell name="projects/some-
|
---|
37 | * project/cases/43594844/attachments/0674M00000WijAnZAJ" curl \ --header
|
---|
38 | * "Authorization: Bearer $(gcloud auth print-access-token)" \
|
---|
39 | * "https://cloudsupport.googleapis.com/v2/$name:download?alt=media" ``` Python:
|
---|
40 | * ```python import googleapiclient.discovery api_version = "v2"
|
---|
41 | * supportApiService = googleapiclient.discovery.build(
|
---|
42 | * serviceName="cloudsupport", version=api_version, discoveryServiceUrl=f"https:
|
---|
43 | * //cloudsupport.googleapis.com/$discovery/rest?version={api_version}", )
|
---|
44 | * request = supportApiService.media().download( name="projects/some-
|
---|
45 | * project/cases/43595344/attachments/0684M00000Pw6pHQAR" ) request.uri =
|
---|
46 | * request.uri.split("?")[0] + "?alt=media" print(request.execute()) ```
|
---|
47 | * (media.download)
|
---|
48 | *
|
---|
49 | * @param string $name The name of the file attachment to download.
|
---|
50 | * @param array $optParams Optional parameters.
|
---|
51 | * @return MediaModel
|
---|
52 | * @throws \Google\Service\Exception
|
---|
53 | */
|
---|
54 | public function download($name, $optParams = [])
|
---|
55 | {
|
---|
56 | $params = ['name' => $name];
|
---|
57 | $params = array_merge($params, $optParams);
|
---|
58 | return $this->call('download', [$params], MediaModel::class);
|
---|
59 | }
|
---|
60 | /**
|
---|
61 | * Create a file attachment on a case or Cloud resource. The attachment must
|
---|
62 | * have the following fields set: `filename`. EXAMPLES: cURL: ```shell echo
|
---|
63 | * "This text is in a file I'm uploading using CSAPI." \ > "./example_file.txt"
|
---|
64 | * case="projects/some-project/cases/43594844" curl \ --header "Authorization:
|
---|
65 | * Bearer $(gcloud auth print-access-token)" \ --data-binary
|
---|
66 | * @"./example_file.txt" \ "https://cloudsupport.googleapis.com/upload/v2beta/$c
|
---|
67 | * ase/attachments?attachment.filename=uploaded_via_curl.txt" ``` Python:
|
---|
68 | * ```python import googleapiclient.discovery api_version = "v2"
|
---|
69 | * supportApiService = googleapiclient.discovery.build(
|
---|
70 | * serviceName="cloudsupport", version=api_version, discoveryServiceUrl=f"https:
|
---|
71 | * //cloudsupport.googleapis.com/$discovery/rest?version={api_version}", )
|
---|
72 | * file_path = "./example_file.txt" with open(file_path, "w") as file:
|
---|
73 | * file.write( "This text is inside a file I'm going to upload using the Cloud
|
---|
74 | * Support API.", ) request = supportApiService.media().upload(
|
---|
75 | * parent="projects/some-project/cases/43595344", media_body=file_path )
|
---|
76 | * request.uri = request.uri.split("?")[0] +
|
---|
77 | * "?attachment.filename=uploaded_via_python.txt" print(request.execute()) ```
|
---|
78 | * (media.upload)
|
---|
79 | *
|
---|
80 | * @param string $parent Required. The name of the case or Cloud resource to
|
---|
81 | * which the attachment should be attached.
|
---|
82 | * @param CreateAttachmentRequest $postBody
|
---|
83 | * @param array $optParams Optional parameters.
|
---|
84 | * @return Attachment
|
---|
85 | * @throws \Google\Service\Exception
|
---|
86 | */
|
---|
87 | public function upload($parent, CreateAttachmentRequest $postBody, $optParams = [])
|
---|
88 | {
|
---|
89 | $params = ['parent' => $parent, 'postBody' => $postBody];
|
---|
90 | $params = array_merge($params, $optParams);
|
---|
91 | return $this->call('upload', [$params], Attachment::class);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | // Adding a class alias for backwards compatibility with the previous class name.
|
---|
96 | class_alias(Media::class, 'Google_Service_CloudSupport_Resource_Media');
|
---|