Skip to content

Commit

Permalink
change axios header type
Browse files Browse the repository at this point in the history
  • Loading branch information
CalumW1 committed Aug 29, 2024
1 parent b9b413c commit 1b6e12d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
8 changes: 6 additions & 2 deletions src/methods/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import axios, { AxiosRequestHeaders, Method } from 'axios';
import axios, { Method, RawAxiosRequestHeaders } from 'axios';

export const ApiClient = async (url: string, header: AxiosRequestHeaders, method: Method): Promise<any> => {
export const ApiClient = async (
url: string,
header: RawAxiosRequestHeaders,
method: Method
): Promise<any> => {
try {
const response = await axios({
url: url,
Expand Down
15 changes: 5 additions & 10 deletions src/methods/getOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
UBI_GETSTATS,
RANKED_UBI_SPACEIDS,
} from '../constants';
import { AxiosHeaders, AxiosRequestHeaders, RawAxiosRequestHeaders } from 'axios';

export interface GameModes {
ranked: Operators;
Expand Down Expand Up @@ -72,11 +73,11 @@ export const GetOperator = async (
var token = await CheckToken();
var expiration = await GetExperation();

const headers = {
const header = {
'Content-Type': 'application/json',
Authorization: `ubi_v1 t=${token}`,
'Ubi-SessionId': UBI_RANKED_SESSIONID,
'Ubi-AppId': UBI_DATADEV_APPID,
'Content-Type': 'application/json',
expiration: expiration,
};

Expand All @@ -90,16 +91,10 @@ export const GetOperator = async (

// https://prod.datadev.ubisoft.com/v1/users/488cd0dd-b8e0-4718-a9da-2767ea44c399/playerstats?spaceId=05bfb3f7-6c21-4c42-be1f-97a33fb5cf66&view=current&aggregation=operators&gameMode=all,ranked,casual,unranked&platformGroup=CONSOLE&teamRole=attacker,defender&seasons=Y9S2
// https://prod.datadev.ubisoft.com/v1/users/488cd0dd-b8e0-4718-a9da-2767ea44c399/playerstats?spaceId=05bfb3f7-6c21-4c42-be1f-97a33fb5cf66&view=current&aggregation=operators&gameMode=ranked,casual&platformGroup=CONSOLE&teamRole=defender,attacker&seasons=Y9S2
console.log(URI);

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

const operators: GameModes = await ExtractOperators(
await data.json(),
userId,
gameMode,
platformChange
);
const operators: GameModes = await ExtractOperators(await data, userId, gameMode, platformChange);

return operators;
};
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getServerStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const GetServerStatus = async (platform: string): Promise<ServerStatus> =

const response = await ApiClient(URI, headers, 'GET');

const data = await response.json();
const data = await response;

const serverStatus: ServerStatus = {
MDM: data[0].MDM,
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getUserByUserId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const GetUserByUserId = async (userId: string): Promise<User[] | []> => {

const response = await ApiClient(URI, headers, 'GET');

const data = (await response.json()) as Profiles;
const data = (await response) as Profiles;

data.profiles = data.profiles.map(profile => ({
...profile,
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getUserByUsername.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const GetUserByUsername = async (username: string, platform: string): Pro

const response = await ApiClient(URI, headers, 'GET');

const data = (await response.json()) as Profiles;
const data = (await response) as Profiles;

data.profiles = data.profiles.map(profile => ({
...profile,
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getUserProgression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export const GetUserProgression = async (userId: string): Promise<Progression> =

const response = await ApiClient(URI, headers, 'GET');

return (await response.json()) as Progression;
return (await response) as Progression;
};
2 changes: 1 addition & 1 deletion src/methods/getUserRank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const GetUserRank = async (userId: string, platform: string): Promise<Use

const response = await ApiClient(URI, headers, 'GET');

const result: UserRank = await extractValues(await response.json());
const result: UserRank = await extractValues(await response);

return result;
};
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getUserStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const GetUserStats = async (
const response = await ApiClient(URI, headers, 'GET');

const usersStats: UserStats = await BuildUserStats(
await response.json(),
await response,
user,
platformTransformation,
platform
Expand Down

0 comments on commit 1b6e12d

Please sign in to comment.