Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions humanitix/actions/checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@
Humanitix Check In / Check Out actions - Manage ticket check-in status for events.
"""

from autohive_integrations_sdk import ActionHandler, ActionResult, ExecutionContext
from autohive_integrations_sdk import ActionHandler, ActionResult, ActionError, ExecutionContext
from typing import Dict, Any

from humanitix import humanitix
from helpers import get_api_headers, build_url, build_error_result


async def _toggle_check(inputs: Dict[str, Any], context: ExecutionContext, action: str) -> ActionResult:
event_id = inputs["event_id"]
ticket_id = inputs["ticket_id"]
override_location = inputs.get("override_location")

headers = get_api_headers(context)
headers["Content-Type"] = "application/json"

params = {"overrideLocation": override_location} if override_location else None
url = build_url(f"events/{event_id}/tickets/{ticket_id}/{action}", params)

response = await context.fetch(url, method="POST", headers=headers)

if error := build_error_result(response):
return error

return ActionResult(
data={
"result": True,
"scanningMessages": response.get("scanningMessages", []) if isinstance(response, dict) else [],
}
)
from helpers import get_api_headers, build_url


@humanitix.action("check_in")
Expand All @@ -44,7 +20,33 @@ class CheckInAction(ActionHandler):
"""

async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
return await _toggle_check(inputs, context, "check-in")
event_id = inputs["event_id"]
ticket_id = inputs["ticket_id"]
override_location = inputs.get("override_location")

headers = get_api_headers(context)
headers["Content-Type"] = "application/json"

params = {"overrideLocation": override_location} if override_location else None
url = build_url(f"events/{event_id}/tickets/{ticket_id}/check-in", params)

response = await context.fetch(url, method="POST", headers=headers)

if response.status >= 400:
data = response.data or {}
msg = (
data.get("message", f"HTTP {response.status}") if isinstance(data, dict) else f"HTTP {response.status}"
)
return ActionError(message=msg)

data = response.data or {}
return ActionResult(
data={
"result": True,
"scanningMessages": data.get("scanningMessages", []) if isinstance(data, dict) else [],
},
cost_usd=0.0,
)


@humanitix.action("check_out")
Expand All @@ -58,4 +60,30 @@ class CheckOutAction(ActionHandler):
"""

async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
return await _toggle_check(inputs, context, "check-out")
event_id = inputs["event_id"]
ticket_id = inputs["ticket_id"]
override_location = inputs.get("override_location")

headers = get_api_headers(context)
headers["Content-Type"] = "application/json"

params = {"overrideLocation": override_location} if override_location else None
url = build_url(f"events/{event_id}/tickets/{ticket_id}/check-out", params)

response = await context.fetch(url, method="POST", headers=headers)

if response.status >= 400:
data = response.data or {}
msg = (
data.get("message", f"HTTP {response.status}") if isinstance(data, dict) else f"HTTP {response.status}"
)
return ActionError(message=msg)

data = response.data or {}
return ActionResult(
data={
"result": True,
"scanningMessages": data.get("scanningMessages", []) if isinstance(data, dict) else [],
},
cost_usd=0.0,
)
6 changes: 3 additions & 3 deletions humanitix/actions/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, Any

from humanitix import humanitix
from helpers import get_api_headers, build_url, build_error_result, build_paginated_result, fetch_single_resource
from helpers import get_api_headers, build_url, build_action_error, build_paginated_result, fetch_single_resource


@humanitix.action("get_events")
Expand Down Expand Up @@ -51,7 +51,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):

response = await context.fetch(url, method="GET", headers=get_api_headers(context))

if error := build_error_result(response):
if error := build_action_error(response):
return error

return build_paginated_result(response, "events", page, page_size)
return build_paginated_result(response.data, "events", page, page_size)
6 changes: 3 additions & 3 deletions humanitix/actions/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, Any

from humanitix import humanitix
from helpers import get_api_headers, build_url, build_error_result, build_paginated_result, fetch_single_resource
from helpers import get_api_headers, build_url, build_action_error, build_paginated_result, fetch_single_resource


@humanitix.action("get_orders")
Expand Down Expand Up @@ -56,7 +56,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):

response = await context.fetch(url, method="GET", headers=get_api_headers(context))

if error := build_error_result(response):
if error := build_action_error(response):
return error

return build_paginated_result(response, "orders", page, page_size)
return build_paginated_result(response.data, "orders", page, page_size)
6 changes: 3 additions & 3 deletions humanitix/actions/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, Any

from humanitix import humanitix
from helpers import get_api_headers, build_url, build_error_result, build_paginated_result, fetch_single_resource
from helpers import get_api_headers, build_url, build_action_error, build_paginated_result, fetch_single_resource


@humanitix.action("get_tags")
Expand Down Expand Up @@ -42,7 +42,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):

response = await context.fetch(url, method="GET", headers=get_api_headers(context))

if error := build_error_result(response):
if error := build_action_error(response):
return error

return build_paginated_result(response, "tags", page, page_size)
return build_paginated_result(response.data, "tags", page, page_size)
6 changes: 3 additions & 3 deletions humanitix/actions/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, Any

from humanitix import humanitix
from helpers import get_api_headers, build_url, build_paginated_result, build_error_result, fetch_single_resource
from helpers import get_api_headers, build_url, build_paginated_result, build_action_error, fetch_single_resource


@humanitix.action("get_tickets")
Expand Down Expand Up @@ -59,6 +59,6 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):

response = await context.fetch(url, method="GET", headers=get_api_headers(context))

if error := build_error_result(response):
if error := build_action_error(response):
return error
return build_paginated_result(response, "tickets", page, page_size)
return build_paginated_result(response.data, "tickets", page, page_size)
Loading
Loading