/*
* Zernio API
*
* API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api Versioning and deprecation: all endpoints are versioned in the URL path (current version: /v1). Breaking changes only ship in a new path version; existing versions keep working. Deprecated operations are marked 'deprecated: true' in this spec and announced in the changelog (https://zernio.com/changelog) before removal. Errors: every 4xx/5xx response is application/json with a machine-readable 'code' and a human-readable 'error' message (see the ErrorResponse schema).
*
* The version of the OpenAPI document: 1.53.1
* Contact: support@zernio.com
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`search_ad_library`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchAdLibraryError {
Status400(models::ErrorResponse),
Status401(models::InlineObject1),
Status403(),
Status404(models::ErrorResponse),
Status409(models::ErrorResponse),
Status501(),
Status503(),
UnknownValue(serde_json::Value),
}
/// Competitor and market research over the public ad archives. Meta's Ad Library (`GET /ads_archive`) is searched with Zernio's own developer access, so `platform=meta` needs no connected account at all. LinkedIn's Ad Library (`GET /rest/adLibrary`) runs on a connected `linkedin` / `linkedinads` account, passed as `accountId`. Passing a Meta account as `accountId` also selects Meta. Rows are returned in the platform's raw shape under `data`; `paging.after` is an opaque cursor on both (`null` when exhausted). **Meta coverage.** Political and social-issue ads are searchable worldwide. Every other ad is in the archive only if it was delivered to the EU or UK within the last year, so a US-only commercial advertiser is invisible. Spend, impressions and demographics are political-only fields and are left out of the default projection; request them via `fields`. All customers share Zernio's Meta quota, so a `429` means back off for a minute. **LinkedIn coverage.** Ads served after June 1 2023, worldwide, kept for a year after their last impression. EU-delivered ads carry impression ranges and the disclosed targeting facets. Pages are capped at 25 ads (`limit` > 25 is a 400); `after` is the next offset. Which params apply: `q`, `countries`, `limit`, `after` on both; `pageIds`, `adType`, `status`, `platforms`, `mediaType`, `languages`, `searchType`, `fields`, `since`, `until` are Meta-only; `advertiser` is LinkedIn-only. Passing a param the account's platform does not support is a 400 naming the param.
pub async fn search_ad_library(
configuration: &configuration::Configuration,
platform: Option<&str>,
account_id: Option<&str>,
q: Option<&str>,
page_ids: Option<&str>,
advertiser: Option<&str>,
countries: Option<&str>,
ad_type: Option<&str>,
status: Option<&str>,
platforms: Option<&str>,
media_type: Option<&str>,
languages: Option<&str>,
since: Option<String>,
until: Option<String>,
search_type: Option<&str>,
fields: Option<&str>,
limit: Option<i32>,
after: Option<&str>,
) -> Result<models::SearchAdLibrary200Response, Error<SearchAdLibraryError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_platform = platform;
let p_query_account_id = account_id;
let p_query_q = q;
let p_query_page_ids = page_ids;
let p_query_advertiser = advertiser;
let p_query_countries = countries;
let p_query_ad_type = ad_type;
let p_query_status = status;
let p_query_platforms = platforms;
let p_query_media_type = media_type;
let p_query_languages = languages;
let p_query_since = since;
let p_query_until = until;
let p_query_search_type = search_type;
let p_query_fields = fields;
let p_query_limit = limit;
let p_query_after = after;
let uri_str = format!("{}/v1/ads/library", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_q {
req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_ids {
req_builder = req_builder.query(&[("pageIds", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_advertiser {
req_builder = req_builder.query(&[("advertiser", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_countries {
req_builder = req_builder.query(&[("countries", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_ad_type {
req_builder = req_builder.query(&[("adType", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_status {
req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_platforms {
req_builder = req_builder.query(&[("platforms", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_media_type {
req_builder = req_builder.query(&[("mediaType", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_languages {
req_builder = req_builder.query(&[("languages", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_since {
req_builder = req_builder.query(&[("since", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_search_type {
req_builder = req_builder.query(&[("searchType", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_fields {
req_builder = req_builder.query(&[("fields", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_after {
req_builder = req_builder.query(&[("after", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SearchAdLibrary200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SearchAdLibrary200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SearchAdLibraryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}