Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - News APIs #32

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const X_PLATFORM_APPID = '99f58b32-1fe6-4efc-942f-143ce779fac2';

export const UBI_REGIONID_MARKETPLACE = 'WW';

export const NEWS_AUTH_TOKEN = '3u0FfSBUaTSew-2NVfAOSYWevVQHWtY9q3VM8Xx9Lto';

export const UBI_SANDBOXES = [
{ id: 'uplay', value: 'OSBOR_PC_LNCH_A' },
{ id: 'psn', value: 'OSBOR_PS4_LNCH_A' },
Expand Down Expand Up @@ -58,6 +60,8 @@ export const UBI_DATADEV_URI = 'https://prod.datadev.ubisoft.com/v1';
export const UBI_MARKETPLACE_URI =
'https://public-ubiservices.ubi.com/v1/profiles/me/uplay/graphql';

export const UBI_NEWS_URI = 'https://nimbus.ubisoft.com/api/v1/items';

export const UBI_GETUSERBYUSERNAME_URI = (userName: string, platform: string) =>
`/profiles?namesOnPlatform=${userName}&platformType=${platform}`;

Expand Down Expand Up @@ -99,6 +103,21 @@ export const UBI_GETSTATS = (
) =>
`/users/${userId}/playerstats?spaceId=${spaceId}&view=${view}&aggregation=${aggregation}&gameMode=${gameMode}&platformGroup=${platform}&teamRole=${teamRole}&seasons=${seasons}`;

export const UBI_GETNEWS = (
categoriesFilter: string,
mediaFilter: string,
placementFilter: string,
locale: string,
fallbackLocale: string,
limit: number,
skip: number,
startIndex: number
) =>
`?categoriesFilter=${categoriesFilter}&mediaFilter=${mediaFilter}&placementFilter=${placementFilter}&locale=${locale}&fallbackLocale=${fallbackLocale}&limit=${limit}&skip=${skip}&startIndex=${startIndex}&tags=BR-rainbow-six%20GA-siege`;

export const UBI_GETNEWSBYID = (id: string, locale: string, fallbackLocale: string) =>
`/${id}?entryId=${id}&locale=${locale}&fallbackLocale=${fallbackLocale}&tags=BR-rainbow-six%20GA-siege`;

export const AvatarURI = (userId: string, size: number) =>
`https://avatars.ubisoft.com/${userId}/default_${
size === 500 ? 'tall' : `${size}_${size}`
Expand Down
29 changes: 29 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { getItemDetails } from './methods/getItemDetails';
import { AdvancedSearch } from './methods/advancedSearchMarketplace';
import { GetTransactionsPending } from './methods/getPendingTransactions';
import { GetTransactionHistroy } from './methods/getTransactionHistory';
import { GetNews } from './methods/getNews';
import { News } from './interfaces/news';
import { GetNewsById } from './methods/getNewsById';

export class R6StatAPI {
public async login(email: string, password: string): Promise<string> {
Expand Down Expand Up @@ -101,4 +104,30 @@ export class R6StatAPI {
public async GetTransactionHistory(profileId: string, limit: number): Promise<Transactions> {
return await GetTransactionHistroy(profileId, limit);
}

public async GetNews(
categoriesFilter: string,
mediaFilter: string,
placementFilter: string,
locale: string,
fallbackLocale: string,
limit: number,
skip: number,
startIndex: number
): Promise<News> {
return await GetNews(
categoriesFilter,
mediaFilter,
placementFilter,
locale,
fallbackLocale,
limit,
skip,
startIndex
);
}

public async GetNewsById(id: string, locale: string, fallbackLocale: string): Promise<News> {
return await GetNewsById(id, locale, fallbackLocale);
}
}
52 changes: 52 additions & 0 deletions src/interfaces/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export interface News {
total: number;
tags: string[];
mediaFilter?: string;
categoriesFilter?: string;
placementFilter?: string[];
limit?: number;
startIndex?: number;
skip?: number;
items: NewsItems[];
}

export interface NewsItems {
id: string;
type: string;
tag: string;
categories: string[];
placement: string;
date: string;
title: string;
abstract: string;
content: string;
trackingPageValue: string;
readTime: number;
author: string;
thumbnail?: Thumbnail;
button?: Button;
index?: number;
prevNode?: Node;
nextNode?: Node;
}

export interface Thumbnail {
url: string;
description: string;
}

export interface Button {
commonTransalationId: string;
buttonType: string;
buttonUrl: string;
trackingCategoryValue: string;
trackingValue: string;
}

export interface Node {
buttonType: string;
trackingLocation: string;
trackingCategoryValue: string;
trackingValue: string;
buttonUrl: string;
}
79 changes: 79 additions & 0 deletions src/methods/getNews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { NEWS_AUTH_TOKEN, UBI_GETNEWS, UBI_NEWS_URI } from '../constants';
import { Button, News, NewsItems, Node, Thumbnail } from '../interfaces/news';
import { ApiClient } from './apiClient';

export const GetNews = async (
categoriesFilter: string,
mediaFilter: string,
placementFilter: string,
locale: string,
fallbackLocale: string,
limit: number,
skip: number,
startIndex: number
): Promise<News> => {
const header = {
Authorization: NEWS_AUTH_TOKEN,
};

const URI =
UBI_NEWS_URI +
UBI_GETNEWS(
categoriesFilter,
mediaFilter,
placementFilter,
locale,
fallbackLocale,
limit,
skip,
startIndex
);

const data = await ApiClient(URI, header, 'GET');

return await BuildNews(data);
};

const BuildNews = async (data: any): Promise<News> => {
const news: News = {
total: data.total,
tags: data.tags as string[],
mediaFilter: data.mediaFilter,
categoriesFilter: data.categoriesFilter,
placementFilter: data.placementFilter as string[],
limit: data.limit,
startIndex: data.startIndex,
skip: data.skip,
items: await BuildNewsItems(data.items),
};
return news;
};

const BuildNewsItems = async (newsItems: any): Promise<NewsItems[]> => {
const news: NewsItems[] = [];

newsItems.forEach(async (item: any) => {
const newsItem: NewsItems = {
id: item.id,
type: item.type,
tag: item.tag,
categories: item.categories as string[],
placement: item.placement,
date: item.date,
title: item.title,
abstract: item.abstract,
content: item.content,
trackingPageValue: item.trackingPageValue,
readTime: item.readTime,
author: item.authors,
thumbnail: (item?.thumbnail as Thumbnail) ?? {},
button: (item?.button as Button) ?? {},
index: item?.index ?? 0,
prevNode: (item?.prevNode as Node) ?? {},
nextNode: (item?.nextNode as Node) ?? {},
};
news.push(newsItem);
});

return news;
};
63 changes: 63 additions & 0 deletions src/methods/getNewsById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { NEWS_AUTH_TOKEN, UBI_GETNEWSBYID, UBI_NEWS_URI } from '../constants';
import { Button, News, NewsItems, Thumbnail, Node } from '../interfaces/news';
import { ApiClient } from './apiClient';

export const GetNewsById = async (
id: string,
locale: string,
fallbackLocale: string
): Promise<News> => {
const header = {
Authorization: NEWS_AUTH_TOKEN,
};

const URI = UBI_NEWS_URI + UBI_GETNEWSBYID(id, locale, fallbackLocale);

const data = await ApiClient(URI, header, 'GET');

return await BuildNews(data);
};

const BuildNews = async (data: any): Promise<News> => {
const news: News = {
total: data.total,
tags: data.tags as string[],
mediaFilter: data.mediaFilter,
categoriesFilter: data.categoriesFilter,
placementFilter: data.placementFilter as string[],
limit: data.limit,
startIndex: data.startIndex,
skip: data.skip,
items: await BuildNewsItems(data.items),
};
return news;
};

const BuildNewsItems = async (newsItems: any): Promise<NewsItems[]> => {
const news: NewsItems[] = [];

newsItems.forEach(async (item: any) => {
const newsItem: NewsItems = {
id: item.id,
type: item.type,
tag: item.tag,
categories: item.categories as string[],
placement: item.placement,
date: item.date,
title: item.title,
abstract: item.abstract,
content: item.content,
trackingPageValue: item.trackingPageValue,
readTime: item.readTime,
author: item.authors,
thumbnail: (item?.thumbnail as Thumbnail) ?? {},
button: (item?.button as Button) ?? {},
index: item?.index ?? 0,
prevNode: (item?.prevNode as Node) ?? {},
nextNode: (item?.nextNode as Node) ?? {},
};
news.push(newsItem);
});

return news;
};
Loading