Skip to content

Commit

Permalink
Test getProfile()
Browse files Browse the repository at this point in the history
  • Loading branch information
NigelBreslaw committed Feb 16, 2024
1 parent 41aefff commit 210a46e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion native_gg/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AuthUI from "./src/authentication/AuthUI.tsx";
import { clientID } from "./src/constants/env.ts";
import AuthService from "./src/authentication/AuthService.ts";
import { authReducer, initialAuthState } from "./src/state/Actions.ts";
import { getItemDefinition, saveItemDefinition } from "./src/backend/api.ts";
import { getItemDefinition, getProfileTest, saveItemDefinition } from "./src/backend/api.ts";
import StorageGG from "./src/storage/StorageGG.ts";

export default function App() {
Expand Down Expand Up @@ -72,7 +72,10 @@ export default function App() {
<Button title="Logout" onPress={() => AuthService.logoutCurrentUser()} />
<View style={styles.spacer} />
<Button title="Download Item Definition" onPress={() => saveItemDefinition()} />
<View style={styles.spacer} />
<Button title="Get saved Item Definition" onPress={() => getItemDefinition()} />
<View style={styles.spacer} />
<Button title="getProfile()" onPress={() => getProfileTest()} />
<StatusBar style="auto" />
</View>
);
Expand Down
10 changes: 10 additions & 0 deletions native_gg/src/backend/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getProfile, profileComponents } from "../bungie/BungieApi";
import StorageGG from "../storage/StorageGG";

export function getCustomItemDefinition(language = "en"): Promise<JSON> {
Expand Down Expand Up @@ -40,3 +41,12 @@ export async function getItemDefinition() {
console.log("getItemDefinition) took:", (p2 - p1).toFixed(4), "ms");
console.log(jsonDefinition["236588"]);
}

export async function getProfileTest() {
const p1 = performance.now();
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const jsonDefinition: any = await getProfile(profileComponents);
const p2 = performance.now();
console.log("getItemDefinition) took:", (p2 - p1).toFixed(4), "ms");
console.log(jsonDefinition);
}
6 changes: 3 additions & 3 deletions native_gg/src/bungie/BungieApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AuthService from "../authentication/AuthService";
import { RefreshToken } from "../authentication/Utilities";
import { apiKey } from "../constants/env";

const bungieUrl = "https://www.bungie.net";
Expand All @@ -10,9 +9,10 @@ const screenshotUrl = "https://www.bungie.net/common/destiny2_content/screenshot
export const profileComponents =
"Profiles,ProfileInventories,ProfileCurrencies,ProfileProgression,Characters,CharacterInventories,CharacterLoadouts,CharacterProgressions,CharacterActivities,CharacterEquipment,ItemInstances,ItemObjectives,ItemPerks,ItemStats,ItemSockets,ItemTalentGrids,ItemCommonData,ItemPlugObjectives,ItemReusablePlugs,StringVariables,Records";

export async function getProfile(components: string, authToken: RefreshToken): Promise<JSON> {
export async function getProfile(components: string): Promise<JSON> {
const authToken = await AuthService.getTokenAsync();
const headers = new Headers();
headers.append("Authorization", `Bearer ${authToken.access_token}`);
headers.append("Authorization", `Bearer ${authToken?.access_token}`);
headers.append("X-API-Key", apiKey);

const requestOptions: RequestInit = {
Expand Down

0 comments on commit 210a46e

Please sign in to comment.