-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement endpoints for creating and updating sheet (#30)
* wip * Refactoring * Fix tests * Refactoring * Add tests for create-sheet endpoint * Initial update-sheet implementation * Asyncify part of update-sheet endpoint * wip * Update tests * Refactoring wip * Refactoring * Implement get-all-sheet-titles endpoint * Update tests
- Loading branch information
1 parent
95d393d
commit f3d8368
Showing
6 changed files
with
641 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from .oauth_settings import ( | ||
get_google_oauth_url, | ||
get_token_request_data, | ||
oauth2_settings, | ||
) | ||
from .service import ( | ||
build_service, | ||
create_sheet_f, | ||
get_all_sheet_titles_f, | ||
get_files_f, | ||
get_sheet_f, | ||
update_sheet_f, | ||
) | ||
|
||
__all__ = [ | ||
"build_service", | ||
"create_sheet_f", | ||
"get_all_sheet_titles_f", | ||
"get_files_f", | ||
"get_google_oauth_url", | ||
"get_sheet_f", | ||
"get_token_request_data", | ||
"oauth2_settings", | ||
"update_sheet_f", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import urllib.parse | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
__all__ = ["get_google_oauth_url", "get_token_request_data", "oauth2_settings"] | ||
|
||
|
||
# Load client secret data from the JSON file | ||
with Path("client_secret.json").open() as secret_file: | ||
client_secret_data = json.load(secret_file) | ||
|
||
# OAuth2 configuration | ||
oauth2_settings = { | ||
"auth_uri": client_secret_data["web"]["auth_uri"], | ||
"tokenUrl": client_secret_data["web"]["token_uri"], | ||
"clientId": client_secret_data["web"]["client_id"], | ||
"clientSecret": client_secret_data["web"]["client_secret"], | ||
"redirectUri": client_secret_data["web"]["redirect_uris"][0], | ||
} | ||
|
||
|
||
def get_google_oauth_url(user_id: int) -> str: | ||
google_oauth_url = ( | ||
f"{oauth2_settings['auth_uri']}?client_id={oauth2_settings['clientId']}" | ||
f"&redirect_uri={oauth2_settings['redirectUri']}&response_type=code" | ||
f"&scope={urllib.parse.quote_plus('email https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive.metadata.readonly')}" | ||
f"&access_type=offline&prompt=consent&state={user_id}" | ||
) | ||
return google_oauth_url | ||
|
||
|
||
def get_token_request_data(code: str) -> Dict[str, Any]: | ||
return { | ||
"code": code, | ||
"client_id": oauth2_settings["clientId"], | ||
"client_secret": oauth2_settings["clientSecret"], | ||
"redirect_uri": oauth2_settings["redirectUri"], | ||
"grant_type": "authorization_code", | ||
} |
Oops, something went wrong.