Skip to content

Commit

Permalink
chore: enhance advertising.advertisingId API (#331)
Browse files Browse the repository at this point in the history
* fix: scope is not an optional param
  • Loading branch information
maggie98choy authored Dec 12, 2023
1 parent 2284143 commit b94284b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 11 deletions.
71 changes: 65 additions & 6 deletions core/main/src/firebolt/handlers/advertising_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,47 @@ pub struct SetSkipRestrictionRequest {
pub value: SkipRestriction,
}

#[derive(Debug, Deserialize, Clone)]
pub struct AdvertisingIdRPCRequest {
pub options: Option<ScopeOption>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct ScopeOption {
pub scope: Option<Scope>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Scope {
#[serde(rename = "type")]
pub _type: ScopeType,
pub id: String,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum ScopeType {
Browse,
Content,
}

impl ScopeType {
pub fn as_string(&self) -> &'static str {
match self {
ScopeType::Browse => "browse",
ScopeType::Content => "content",
}
}
}

#[rpc(server)]
pub trait Advertising {
#[method(name = "advertising.advertisingId")]
async fn advertising_id(&self, ctx: CallContext) -> RpcResult<AdvertisingId>;
async fn advertising_id(
&self,
ctx: CallContext,
request: AdvertisingIdRPCRequest,
) -> RpcResult<AdvertisingId>;
#[method(name = "advertising.appBundleId")]
fn app_bundle_id(&self, ctx: CallContext) -> RpcResult<String>;
#[method(name = "advertising.config")]
Expand Down Expand Up @@ -212,13 +249,30 @@ impl AdvertisingServer for AdvertisingImpl {
.map_err(|err| err.into())
}

async fn advertising_id(&self, ctx: CallContext) -> RpcResult<AdvertisingId> {
async fn advertising_id(
&self,
ctx: CallContext,
request: AdvertisingIdRPCRequest,
) -> RpcResult<AdvertisingId> {
if let Some(session) = self.state.session_state.get_account_session() {
let mut scope_option_map = HashMap::new();
if let Some(scope_opt) = &request.options {
if let Some(scope) = &scope_opt.scope {
scope_option_map
.insert("type".to_string(), scope._type.as_string().to_string());
scope_option_map.insert("id".to_string(), scope.id.to_string());
}
}
let payload = AdvertisingRequest::GetAdIdObject(AdIdRequestParams {
privacy_data: privacy_rpc::get_allow_app_content_ad_targeting_settings(&self.state)
.await,
privacy_data: privacy_rpc::get_allow_app_content_ad_targeting_settings(
&self.state,
request.options.as_ref(),
&ctx.app_id,
)
.await,
app_id: ctx.app_id.to_owned(),
dist_session: session,
scope: scope_option_map,
});
let resp = self.state.get_client().send_extn_request(payload).await;

Expand Down Expand Up @@ -277,8 +331,12 @@ impl AdvertisingServer for AdvertisingImpl {
.unwrap_or(false);

let payload = AdvertisingRequest::GetAdInitObject(AdInitObjectRequestParams {
privacy_data: privacy_rpc::get_allow_app_content_ad_targeting_settings(&self.state)
.await,
privacy_data: privacy_rpc::get_allow_app_content_ad_targeting_settings(
&self.state,
None,
&app_id,
)
.await,
environment: config.options.environment.to_string(),
durable_app_id: app_id,
app_version: "".to_string(),
Expand All @@ -288,6 +346,7 @@ impl AdvertisingServer for AdvertisingImpl {
authentication_entity: config.options.authentication_entity.unwrap_or_default(),
dist_session: session
.ok_or_else(|| Error::Custom(String::from("no session available")))?,
scope: HashMap::new(),
});

match self.state.get_client().send_extn_request(payload).await {
Expand Down
13 changes: 10 additions & 3 deletions core/main/src/firebolt/handlers/parameters_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ pub struct ParametersImpl {
impl ParametersServer for ParametersImpl {
async fn initialization(&self, ctx: CallContext) -> RpcResult<AppInitParameters> {
let (app_resp_tx, app_resp_rx) = oneshot::channel::<AppResponse>();
let app_request = AppRequest::new(AppMethod::GetLaunchRequest(ctx.app_id), app_resp_tx);
let privacy_data =
privacy_rpc::get_allow_app_content_ad_targeting_settings(&self.platform_state).await;
let app_request = AppRequest::new(
AppMethod::GetLaunchRequest(ctx.app_id.to_owned()),
app_resp_tx,
);
let privacy_data = privacy_rpc::get_allow_app_content_ad_targeting_settings(
&self.platform_state,
None,
&ctx.app_id.to_string(),
)
.await;

let _ = self
.platform_state
Expand Down
22 changes: 20 additions & 2 deletions core/main/src/firebolt/handlers/privacy_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use ripple_sdk::{

use std::collections::HashMap;

use super::advertising_rpc::ScopeOption;
use super::capabilities_rpc::is_granted;

pub const US_PRIVACY_KEY: &str = "us_privacy";
Expand Down Expand Up @@ -274,9 +275,26 @@ pub trait Privacy {

pub async fn get_allow_app_content_ad_targeting_settings(
platform_state: &PlatformState,
scope_option: Option<&ScopeOption>,
caller_app: &String,
) -> HashMap<String, String> {
let data = StorageProperty::AllowAppContentAdTargeting.as_data();

let mut data = StorageProperty::AllowAppContentAdTargeting.as_data();
if let Some(scope_opt) = scope_option {
if let Some(scope) = &scope_opt.scope {
let primary_app = platform_state
.get_device_manifest()
.applications
.defaults
.main;
if primary_app == *caller_app.to_string() {
if scope._type.as_string() == "browse" {
data = StorageProperty::AllowPrimaryBrowseAdTargeting.as_data();
} else if scope._type.as_string() == "content" {
data = StorageProperty::AllowPrimaryContentAdTargeting.as_data();
}
}
}
}
match StorageManager::get_bool_from_namespace(
platform_state,
data.namespace.to_string(),
Expand Down
2 changes: 2 additions & 0 deletions core/sdk/src/api/firebolt/fb_advertising.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct AdInitObjectRequestParams {
pub coppa: bool,
pub authentication_entity: String,
pub dist_session: AccountSession,
pub scope: HashMap<String, String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -69,6 +70,7 @@ pub struct AdIdRequestParams {
pub privacy_data: HashMap<String, String>,
pub app_id: String,
pub dist_session: AccountSession,
pub scope: HashMap<String, String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down

0 comments on commit b94284b

Please sign in to comment.