Spaces:
Sleeping
Sleeping
File size: 7,982 Bytes
ef78361 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | """Reports & Action Items API methods for ChainShiftClient.
Mixin class extracted from api_client.py.
Methods access self._get, self._post, self._patch, self._delete, self.base_url from the parent class.
"""
class ReportsApiMixin:
"""Reports (HTML, data) and Action Items APIs."""
# ========================================================================
# Reports API (HTML Report Generation)
# ========================================================================
def get_report_overview(
self, campaign_id: int, start_date: str | None = None, end_date: str | None = None,
) -> dict:
"""GET /api/v1/reports/{campaign_id}/overview"""
params = {}
if start_date:
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
return self._get(f"/api/v1/reports/{campaign_id}/overview", params or None)
def get_report_visibility(
self, campaign_id: int, start_date: str | None = None, end_date: str | None = None,
) -> dict:
"""GET /api/v1/reports/{campaign_id}/visibility"""
params = {}
if start_date:
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
return self._get(f"/api/v1/reports/{campaign_id}/visibility", params or None)
def get_report_citations(
self, campaign_id: int, start_date: str | None = None,
end_date: str | None = None, limit: int = 30,
) -> dict:
"""GET /api/v1/reports/{campaign_id}/citations"""
params: dict = {"limit": limit}
if start_date:
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
return self._get(f"/api/v1/reports/{campaign_id}/citations", params)
def get_report_citation_trends(
self, campaign_id: int, start_date: str | None = None,
end_date: str | None = None, limit: int = 20,
) -> dict:
"""GET /api/v1/reports/{campaign_id}/citation-trends"""
params: dict = {"limit": limit}
if start_date:
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
return self._get(f"/api/v1/reports/{campaign_id}/citation-trends", params)
def get_report_content_types(
self, campaign_id: int, start_date: str | None = None, end_date: str | None = None,
) -> dict:
"""GET /api/v1/reports/{campaign_id}/content-types"""
params = {}
if start_date:
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
return self._get(f"/api/v1/reports/{campaign_id}/content-types", params or None)
def get_report_sentiment(self, campaign_id: int) -> dict:
"""GET /api/v1/reports/{campaign_id}/sentiment"""
return self._get(f"/api/v1/reports/{campaign_id}/sentiment")
def get_report_homepage_citations(
self, campaign_id: int, start_date: str | None = None,
end_date: str | None = None, homepage_urls: str | None = None,
) -> dict:
"""GET /api/v1/reports/{campaign_id}/homepage-citations"""
params = {}
if start_date:
params["start_date"] = start_date
if end_date:
params["end_date"] = end_date
if homepage_urls:
params["homepage_urls"] = homepage_urls
return self._get(f"/api/v1/reports/{campaign_id}/homepage-citations", params or None)
def generate_html_report(
self,
campaign_id: int,
start_date: str | None = None,
end_date: str | None = None,
features: list[str] | None = None,
enable_insights: bool = False,
output_mode: str = "url",
) -> dict:
"""Generate HTML report. POST /api/v1/reports/{campaign_id}/html"""
body: dict = {"output_mode": output_mode, "enable_insights": enable_insights}
if start_date:
body["start_date"] = start_date
if end_date:
body["end_date"] = end_date
if features:
body["features"] = features
return self._post(f"/api/v1/reports/{campaign_id}/html", body)
def build_html_feature(
self,
campaign_id: int,
feature: str,
start_date: str | None = None,
end_date: str | None = None,
enable_insights: bool = False,
enable_action_items: bool = False,
homepage_urls: list[str] | None = None,
period: str = "1w",
) -> dict:
"""Build a single report feature. POST /api/v1/reports/{campaign_id}/html/build-feature"""
body: dict = {"feature": feature, "enable_insights": enable_insights, "period": period}
if start_date:
body["start_date"] = start_date
if end_date:
body["end_date"] = end_date
if enable_action_items:
body["enable_action_items"] = enable_action_items
if homepage_urls:
body["homepage_urls"] = homepage_urls
return self._post(f"/api/v1/reports/{campaign_id}/html/build-feature", body)
def render_html_report(
self,
campaign_id: int,
features_data: list[dict],
title: str | None = None,
subtitle: str | None = None,
start_date: str | None = None,
end_date: str | None = None,
enable_insights: bool = False,
enable_action_items: bool = False,
output_mode: str = "url",
) -> dict:
"""Assemble and render final HTML report. POST /api/v1/reports/{campaign_id}/html/render"""
body: dict = {
"features_data": features_data,
"output_mode": output_mode,
"enable_insights": enable_insights,
}
if title:
body["title"] = title
if subtitle:
body["subtitle"] = subtitle
if start_date:
body["start_date"] = start_date
if end_date:
body["end_date"] = end_date
if enable_action_items:
body["enable_action_items"] = enable_action_items
return self._post(f"/api/v1/reports/{campaign_id}/html/render", body)
def get_html_report_history(self, campaign_id: int, page: int = 1, page_size: int = 20) -> dict:
"""Get HTML report history. GET /api/v1/reports/{campaign_id}/html/history"""
return self._get(f"/api/v1/reports/{campaign_id}/html/history", {"page": page, "page_size": page_size})
def get_html_report_detail(self, campaign_id: int, report_id: str) -> dict:
"""Get HTML report detail. GET /api/v1/reports/{campaign_id}/html/{report_id}"""
return self._get(f"/api/v1/reports/{campaign_id}/html/{report_id}")
# ========================================================================
# Action Items APIs (ADR-018 Phase 2)
# ========================================================================
def save_action_items(
self,
campaign_id: int,
items: list[dict],
report_id: str | None = None,
) -> dict:
"""Save action items from report. POST /api/v1/action-items"""
body: dict = {"campaign_id": campaign_id, "items": items}
if report_id:
body["report_id"] = report_id
return self._post("/api/v1/action-items", body)
def update_action_item(self, item_id: str, data: dict) -> dict:
"""Update action item. PATCH /api/v1/action-items/{item_id}"""
return self._patch(f"/api/v1/action-items/{item_id}", data)
def delete_action_item(self, item_id: str) -> dict:
"""Delete action item. DELETE /api/v1/action-items/{item_id}"""
return self._delete(f"/api/v1/action-items/{item_id}")
def export_action_item_html(self, item_id: str) -> dict:
"""Export action item as HTML. GET /api/v1/action-items/{item_id}/export/html"""
return self._get(f"/api/v1/action-items/{item_id}/export/html")
|