Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
activate and sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
Accurate0 committed Jul 11, 2023
1 parent f6d7a20 commit cd0662b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "libmaccas"
version = "0.41.0"
version = "0.43.0"
edition = "2021"
license = "MIT"
description = "McDonald's API Client"
Expand Down
34 changes: 29 additions & 5 deletions src/api.rs
@@ -1,9 +1,9 @@
use crate::types::request::{ActivationRequest, RegistrationRequest};
use crate::types::request::{ActivateAndSignInRequest, ActivationRequest, RegistrationRequest};
use crate::types::response::{
ActivationResponse, CatalogResponse, ClientResponse, CustomerPointResponse,
LoginRefreshResponse, LoginResponse, OfferDealStackResponse, OfferDetailsResponse,
OfferResponse, RegistrationResponse, RestaurantLocationResponse, RestaurantResponse,
TokenResponse,
ActivateAndSignInResponse, ActivationResponse, CatalogResponse, ClientResponse,
CustomerPointResponse, LoginRefreshResponse, LoginResponse, OfferDealStackResponse,
OfferDetailsResponse, OfferResponse, RegistrationResponse, RestaurantLocationResponse,
RestaurantResponse, TokenResponse,
};
use crate::ClientResult;
use anyhow::Context;
Expand Down Expand Up @@ -177,6 +177,30 @@ impl ApiClient {
ClientResponse::from_response(response).await
}

// PUT https://ap-prod.api.mcd.com/exp/v1/customer/activateandsignin
#[instrument(skip(sensor_data))]
pub async fn activate_and_signin<A>(
&self,
request: &ActivateAndSignInRequest,
sensor_data: &A,
) -> ClientResult<ClientResponse<ActivateAndSignInResponse>>
where
A: Display + ?Sized + Debug,
{
let token = self.login_token.as_ref().context("no login token set")?;

let request = self
.get_default_request("exp/v1/customer/activateandsignin", Method::PUT)
.header("x-acf-sensor-data", sensor_data.to_string())
.bearer_auth(token)
.json(&request);

let response = request.send().await?;
tracing::debug!("raw response: {:?}", response);

ClientResponse::from_response(response).await
}

// POST https://ap-prod.api.mcd.com/exp/v1/customer/login
#[instrument(skip(sensor_data))]
pub async fn customer_login<A, B, C, D>(
Expand Down
21 changes: 21 additions & 0 deletions src/types/request.rs
@@ -1,6 +1,27 @@
use serde_derive::Deserialize;
use serde_derive::Serialize;

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivateAndSignInRequest {
pub activation_link: String,
pub client_info: ClientInfo,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientInfo {
pub device: ActivationDevice,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivationDevice {
pub device_unique_id: String,
pub os: String,
pub os_version: String,
}

#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegistrationRequest {
Expand Down
14 changes: 14 additions & 0 deletions src/types/response.rs
Expand Up @@ -36,6 +36,20 @@ where
}
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivateAndSignInResponse {
pub status: Status,
pub response: AccessTokenResponse,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub access_token: String,
pub refresh_token: String,
}

#[derive(serde::Deserialize, std::fmt::Debug)]
pub struct Token {
pub token: String,
Expand Down

0 comments on commit cd0662b

Please sign in to comment.