Skip to content

Commit 002711a

Browse files
PierrickVouletpierrick
andauthored
feat: add create and set up space code samples (#1810)
Co-authored-by: pierrick <[email protected]>
1 parent 69277e9 commit 002711a

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2024 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# It may require modifications to work in your environment.
17+
18+
# To install the latest published package dependency, execute the following:
19+
# python3 -m pip install google-apps-chat
20+
21+
# [START chat_create_space_user_cred]
22+
from authentication_utils import create_client_with_user_credentials
23+
from google.apps import chat_v1 as google_chat
24+
25+
SCOPES = ["https://www.googleapis.com/auth/chat.spaces.create"]
26+
27+
def create_space_with_user_cred():
28+
# Create a client
29+
client = create_client_with_user_credentials(SCOPES)
30+
31+
# Initialize request argument(s)
32+
request = google_chat.CreateSpaceRequest(
33+
space = {
34+
"space_type": 'SPACE',
35+
# Replace DISPLAY_NAME here.
36+
"display_name": 'DISPLAY_NAME'
37+
}
38+
)
39+
40+
# Make the request
41+
response = client.create_space(request)
42+
43+
# Handle the response
44+
print(response)
45+
46+
create_space_with_user_cred()
47+
48+
# [END chat_create_space_user_cred]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2024 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# It may require modifications to work in your environment.
17+
18+
# To install the latest published package dependency, execute the following:
19+
# python3 -m pip install google-apps-chat
20+
21+
# [START chat_set_up_space_user_cred]
22+
from authentication_utils import create_client_with_user_credentials
23+
from google.apps import chat_v1 as google_chat
24+
25+
SCOPES = ["https://www.googleapis.com/auth/chat.spaces.create"]
26+
27+
def set_up_space_with_user_cred():
28+
# Create a client
29+
client = create_client_with_user_credentials(SCOPES)
30+
31+
# Initialize request argument(s)
32+
request = google_chat.SetUpSpaceRequest(
33+
space = {
34+
"space_type": 'SPACE',
35+
# Replace DISPLAY_NAME here.
36+
"display_name": 'DISPLAY_NAME'
37+
},
38+
memberships = [{
39+
"member": {
40+
# Replace USER_NAME here.
41+
"name": 'users/USER_NAME',
42+
"type_": 'HUMAN'
43+
}
44+
}]
45+
)
46+
47+
# Make the request
48+
response = client.set_up_space(request)
49+
50+
# Handle the response
51+
print(response)
52+
53+
set_up_space_with_user_cred()
54+
55+
# [END chat_set_up_space_user_cred]

0 commit comments

Comments
 (0)