Skip to content

Commit

Permalink
Merge pull request #888 from airtai/dev
Browse files Browse the repository at this point in the history
4 PRs
  • Loading branch information
kumaranvpl authored Aug 19, 2024
2 parents b99b4b7 + 1336646 commit 5b22b1b
Show file tree
Hide file tree
Showing 9 changed files with 601 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh

- name: Log in to the Container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
args: []#[--ignore-words=.codespell-whitelist.txt]
exclude: |
(?x)^(
docs/overrides/home.html
google_ads/language_codes.csv
)$
- repo: local
Expand Down
74 changes: 67 additions & 7 deletions captn/google_ads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pydantic import BaseModel
from requests import get as requests_get
from requests import post as requests_post

BASE_URL = environ.get("CAPTN_BACKEND_URL", "http://localhost:9000")
ALREADY_AUTHENTICATED = "User is already authenticated"
Expand Down Expand Up @@ -291,20 +292,18 @@ def check_for_client_approval(
return NOT_APPROVED


def google_ads_create_update(
def _check_for_approval_and_get_login_url(
user_id: int,
conv_id: int,
ad: BaseModel,
model: BaseModel,
recommended_modifications_and_answer_list: List[
Tuple[Dict[str, Any], Optional[str]]
],
login_customer_id: Optional[str] = None,
endpoint: str = "/update-ad-group-ad",
already_checked_clients_approval: bool = False,
) -> Union[Dict[str, Any], str]:
already_checked_clients_approval: bool,
) -> Optional[Dict[str, str]]:
if not already_checked_clients_approval:
error_msg = check_for_client_approval(
modification_function_parameters=ad.model_dump(),
modification_function_parameters=model.model_dump(),
recommended_modifications_and_answer_list=recommended_modifications_and_answer_list,
)
if error_msg:
Expand All @@ -314,6 +313,30 @@ def google_ads_create_update(
if not login_url_response.get("login_url") == ALREADY_AUTHENTICATED:
return login_url_response

return None


def google_ads_create_update(
user_id: int,
conv_id: int,
ad: BaseModel,
recommended_modifications_and_answer_list: List[
Tuple[Dict[str, Any], Optional[str]]
],
login_customer_id: Optional[str] = None,
endpoint: str = "/update-ad-group-ad",
already_checked_clients_approval: bool = False,
) -> Union[Dict[str, Any], str]:
login_url_response = _check_for_approval_and_get_login_url(
user_id=user_id,
conv_id=conv_id,
model=ad,
recommended_modifications_and_answer_list=recommended_modifications_and_answer_list,
already_checked_clients_approval=already_checked_clients_approval,
)
if login_url_response:
return login_url_response

params: Dict[str, Any] = ad.model_dump()
params["user_id"] = user_id
params["login_customer_id"] = login_customer_id
Expand All @@ -324,3 +347,40 @@ def google_ads_create_update(

response_dict: Union[Dict[str, Any], str] = response.json()
return response_dict


def google_ads_create_assets(
user_id: int,
conv_id: int,
model: BaseModel,
recommended_modifications_and_answer_list: List[
Tuple[Dict[str, Any], Optional[str]]
],
endpoint: str,
already_checked_clients_approval: bool = False,
) -> Union[Dict[str, Any], str]:
login_url_response = _check_for_approval_and_get_login_url(
user_id=user_id,
conv_id=conv_id,
model=model,
recommended_modifications_and_answer_list=recommended_modifications_and_answer_list,
already_checked_clients_approval=already_checked_clients_approval,
)
if login_url_response:
return login_url_response

params = {
"user_id": user_id,
}

body = model.model_dump()

response = requests_post(
f"{BASE_URL}{endpoint}", json=body, params=params, timeout=60
)

if not response.ok:
raise ValueError(response.content)

response_dict: Union[Dict[str, Any], str] = response.json()
return response_dict
Loading

0 comments on commit 5b22b1b

Please sign in to comment.