Skip to content

Commit

Permalink
Updated graphql query when fetching RewardsActivityFeed. Hopefully sh…
Browse files Browse the repository at this point in the history
…ould address #7
  • Loading branch information
T-Fowl committed Feb 29, 2024
1 parent ed001c8 commit 3722aed
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 36 deletions.
33 changes: 1 addition & 32 deletions api.http
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,7 @@ Origin: https://www.woolworthsrewards.com.au
Referer: https://www.woolworthsrewards.com.au/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

query RewardsActivityFeed {
rtlRewardsActivityFeed(pageToken: "FIRST_PAGE") {
list {
groups {
... on RewardsActivityFeedGroup {
id
title
items {
id
receipt {
receiptId
}
}
}
}
nextPageToken
}
}
}

### List out activities - Manual GraphQL
POST https://apigee-prod.api-wr.com/wx/v1/bff/graphql
Accept: application/json, text/plain, */*
api-version: 2
Authorization: Bearer {{token}}
client_id: {{client_id}}
Content-Type: application/json;charset=UTF-8
Origin: https://www.woolworthsrewards.com.au
Referer: https://www.woolworthsrewards.com.au/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

{"query":"query RewardsActivityFeed { rtlRewardsActivityFeed(pageToken: \"FIRST_PAGE\") { list { groups { ... on RewardsActivityBanner { id iconUrl title message messageCta action { url type } onDismissCoachMark { text anchor } analytics { label } } ...on RewardsActivityFeedGroup { id title items { id displayDate description message displayValue displayValueHandling icon iconUrl transaction { origin amountAsDollars } highlights{ description value } receipt { receiptId } transactionType } } } nextPageToken } } }"}
< ./src/RewardsActivityFeed.graphql

### Fetch receipt details
POST https://api.woolworthsrewards.com.au/wx/v1/rewards/member/ereceipts/transactions/details
Expand Down
60 changes: 60 additions & 0 deletions src/RewardsActivityFeed.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
query RewardsActivityFeed {
rtlRewardsActivityFeed(
pageToken: "FIRST_PAGE"
featureFlags: { activityBreakdown: true }
) {
list {
groups {
... on RewardsActivityBanner {
id
iconUrl
title
message
messageCta
action {
url
type
}
onDismissCoachMark {
text
anchor
}
analytics {
label
}
}
... on RewardsActivityFeedGroup {
id
title
items {
id
displayDate
description
message
displayValue
displayValueHandling
icon
iconUrl
showChevron
activityDetailsId
transaction {
origin
amountAsDollars
}
highlights {
description
value
style
iconUrl
}
receipt(enableOnlineReceipt: true) {
receiptId
}
transactionType
}
}
}
nextPageToken
}
}
}
23 changes: 19 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use thiserror::Error;

use reqwest::blocking::Client;
use reqwest::header::{AUTHORIZATION, CONTENT_TYPE, HeaderMap, USER_AGENT};
use serde_json::json;

use crate::EverydayRewardsError::UnknownError;
use crate::models::{ApiError, ApiResponse, ReceiptDetailsResponse, RewardsActivityFeedResponse, RtlRewardsActivity};
Expand Down Expand Up @@ -67,10 +68,16 @@ impl EverydayRewardsClient {

pub fn rewards_activity_feed(&self, page_token: Option<&str>) -> Result<ValueWithSource<RewardsActivityFeedResponse>, EverydayRewardsError> {
let page_token = page_token.unwrap_or("FIRST_PAGE");
let query = format!(r#"query RewardsActivityFeed {{ rtlRewardsActivityFeed(pageToken: \"{page_token}\") {{ list {{ groups {{ ... on RewardsActivityFeedGroup {{ id title items {{ id receipt {{ receiptId }} }} }} }} nextPageToken }} }} }}"#);

let query = include_str!("RewardsActivityFeed.graphql");
let query = query.replace("FIRST_PAGE", page_token);

let body = json!({
"query": query,
});

let text = self.client.post("https://apigee-prod.api-wr.com/wx/v1/bff/graphql")
.body(format!("{{\"query\":\"{query}\"}}"))
.body(body.to_string())
.header(CONTENT_TYPE, "application/json;charset=UTF-8")
.send()?
.text()?;
Expand All @@ -93,8 +100,12 @@ impl EverydayRewardsClient {
}

pub fn transaction_details(&self, receipt_key: &str) -> Result<ValueWithSource<ReceiptDetailsResponse>, EverydayRewardsError> {
let body = json!({
"receiptKey": receipt_key,
});

let text = self.client.post("https://api.woolworthsrewards.com.au/wx/v1/rewards/member/ereceipts/transactions/details")
.body(format!("{{\"receiptKey\":\"{receipt_key}\"}}"))
.body(body.to_string())
.header(CONTENT_TYPE, "application/json;charset=UTF-8").send()?.text()?;

let response: ApiResponse = serde_json::from_str(text.as_str())?;
Expand All @@ -115,8 +126,12 @@ impl EverydayRewardsClient {
}

pub fn download_receipt<P: AsRef<Path>>(&self, download_url: &str, path: P) -> Result<(), EverydayRewardsError> {
let body = json!({
"downloadUrl": download_url,
});

let request = self.client.post("https://api.woolworthsrewards.com.au/wx/v1/rewards/member/ereceipts/transactions/details/download")
.body(format!("{{\"downloadUrl\":\"{download_url}\"}}"))
.body(body.to_string())
.header(CONTENT_TYPE, "application/json;charset=UTF-8");

let response = request.send()?;
Expand Down

0 comments on commit 3722aed

Please sign in to comment.