Skip to content

Commit

Permalink
Update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JoShMiQueL committed Jan 10, 2021
1 parent fd8ff25 commit dd12ba5
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 56 deletions.
118 changes: 76 additions & 42 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { News } from './interfaces/News'
import { OwnedGames } from './interfaces/OwnedGames'
import { PlayerAchievements } from './interfaces/PlayerAchievements'
import { PlayerSummaries } from './interfaces/PlayerSummaries'
import { RecentlyPlayedGames } from './interfaces/RecentlyPlayedGames'
import * as RecentlyPlayedGames from './interfaces/RecentlyPlayedGames'
import { ResponseFormat } from './interfaces/ResponseFormat'
import { UserStats } from './interfaces/UserStats'
import * as AppDetails from './interfaces/AppDetails'

export class SteamAPI {
private apiKey: string
Expand All @@ -24,6 +25,38 @@ export class SteamAPI {
this.responseFormat = responseFormat
}

/**
*
* @param appId AppID of the game you want the news of.
*/
async GetAppDetails(appId: number): Promise<AppDetails.AppDetails> {
const url = `https://store.steampowered.com/api/appdetails?appids=${appId}`
let steamApiResponse: AxiosResponse
try {
steamApiResponse = await axios.get(url)
if (steamApiResponse.data[appId].data !== undefined) {
return {
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
success: steamApiResponse.data[appId].success,
data: steamApiResponse.data[appId].data
}
} else {
return {
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
success: steamApiResponse.data[appId].success
}
}
} catch (error) {
console.log(error.response.config.url)
return {
statusCode: error.response.status,
statusText: error.response.statusText
}
}
}

/**
*
* @param appId AppID of the game you want the news of.
Expand All @@ -32,13 +65,13 @@ export class SteamAPI {
*/
async GetNewsForApp(appId: number, count: number = 3, maxlength: number = 300): Promise<News> {
const url = `${this.endPoint}/ISteamNews/GetNewsForApp/v0002/?appid=${appId}&count=${count}&maxlength=${maxlength}&format=${this.responseFormat}`
let response: AxiosResponse<News>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
appnews: response.data.appnews
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.appnews
}
} catch (error) {
return {
Expand All @@ -54,13 +87,13 @@ export class SteamAPI {
*/
async GetGlobalAchievementPercentagesForApp(gameId: number): Promise<GlobalAchievement> {
const url = `${this.endPoint}/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=${gameId}&format=${this.responseFormat}`
let response: AxiosResponse<GlobalAchievement>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
achievementpercentages: response.data.achievementpercentages
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.achievementpercentages.achievements
}
} catch (error) {
return {
Expand All @@ -76,13 +109,13 @@ export class SteamAPI {
*/
async GetPlayerSummaries(...steamIds: bigint[]): Promise<PlayerSummaries> {
const url = `${this.endPoint}/ISteamUser/GetPlayerSummaries/v0002/?key=${this.apiKey}&steamids=${steamIds}&format=${this.responseFormat}`
let response: AxiosResponse<PlayerSummaries>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
response: response.data.response
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.response.players
}
} catch (error) {
return {
Expand All @@ -99,13 +132,13 @@ export class SteamAPI {
*/
async GetFriendList(steamId: bigint, relationship: Friend['relationship'] = 'friend'): Promise<Friends> {
const url = `${this.endPoint}/ISteamUser/GetFriendList/v0001/?key=${this.apiKey}&steamid=${steamId}&relationship=${relationship}&format=${this.responseFormat}`
let response: AxiosResponse<Friends>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
friendslist: response.data.friendslist
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.friendslist.friends
}
} catch (error) {
return {
Expand All @@ -123,13 +156,14 @@ export class SteamAPI {
*/
async GetPlayerAchievements(steamId: bigint, appId: number, language: string = 'us'): Promise<PlayerAchievements> {
const url = `${this.endPoint}/ISteamUserStats/GetPlayerAchievements/v0001/?appid=${appId}&key=${this.apiKey}&steamid=${steamId}&l=${language}&format=${this.responseFormat}`
let response: AxiosResponse<PlayerAchievements>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
delete steamApiResponse.data.playerstats.success
return {
statusCode: response.status,
statusText: response.statusText,
playerstats: response.data.playerstats
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.playerstats
}
} catch (error) {
return {
Expand All @@ -147,13 +181,13 @@ export class SteamAPI {
*/
async GetUserStatsForGame(steamId: bigint, appId: number, language: string = 'us'): Promise<UserStats> {
const url = `${this.endPoint}/ISteamUserStats/GetUserStatsForGame/v0002/?appid=${appId}&key=${this.apiKey}&steamid=${steamId}&l=${language}&format=${this.responseFormat}`
let response: AxiosResponse<UserStats>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
playerstats: response.data.playerstats
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.playerstats
}
} catch (error) {
return {
Expand All @@ -175,13 +209,13 @@ export class SteamAPI {
includeAppInfo === true ? `&include_appinfo=1` : ''
}${includePlayedFreeGames ? `&include_played_free_games=1` : ''}&format=${this.responseFormat}`
appidsFilter ? appidsFilter.forEach((v, i) => (url = `${url}&appids_filter[${i}]=${v}`)) : ''
let response: AxiosResponse<OwnedGames>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
response: response.data.response
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.response
}
} catch (error) {
return {
Expand All @@ -196,17 +230,17 @@ export class SteamAPI {
* @param steamId The SteamID of the account.
* @param count Optionally limit to a certain number of games (the number of games a person has played in the last 2 weeks is typically very small)
*/
async GetRecentlyPlayedGames(steamId: bigint, count?: number): Promise<RecentlyPlayedGames> {
async GetRecentlyPlayedGames(steamId: bigint, count?: number): Promise<RecentlyPlayedGames.RecentlyPlayedGames> {
const url = `${this.endPoint}/IPlayerService/GetRecentlyPlayedGames/v0001/?&key=${this.apiKey}&steamid=${steamId}${count && `&count=${count}`}&format=${
this.responseFormat
}`
let response: AxiosResponse<RecentlyPlayedGames>
let steamApiResponse: AxiosResponse
try {
response = await axios.get(url)
steamApiResponse = await axios.get(url)
return {
statusCode: response.status,
statusText: response.statusText,
response: response.data.response
statusCode: steamApiResponse.status,
statusText: steamApiResponse.statusText,
data: steamApiResponse.data.response
}
} catch (error) {
return {
Expand Down
137 changes: 137 additions & 0 deletions src/interfaces/AppDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
export interface AppDetails {
statusCode: number
statusText: string
success?: boolean
data?: Data
}

export interface Data {
type: string
name: string
steam_appid: number
required_age: number
is_free: boolean
controller_support: string
dlc: number[]
detailed_description: string
about_the_game: string
short_description: string
supported_languages: string
header_image: string
website: string
pc_requirements: Requirements
mac_requirements: Requirements
linux_requirements: Requirements
developers: string[]
publishers: string[]
packages: number[]
package_groups: PackageGroup[]
platforms: Platforms
metacritic: Metacritic
categories: Category[]
genres: Genre[]
screenshots: Screenshot[]
movies: Movie[]
recommendations: Recommendations
achievements: Achievements
release_date: ReleaseDate
support_info: SupportInfo
background: string
content_descriptors: ContentDescriptors
}

interface Achievements {
total: number
highlighted: Highlighted[]
}

interface Highlighted {
name: string
path: string
}

interface Category {
id: number
description: string
}

interface ContentDescriptors {
ids: number[]
notes: string
}

interface Genre {
id: string
description: string
}

interface Requirements {
minimum: string
}

interface Metacritic {
score: number
url: string
}

interface Movie {
id: number
name: string
thumbnail: string
webm: Mp4
mp4: Mp4
highlight: boolean
}

interface Mp4 {
'480': string
max: string
}

interface PackageGroup {
name: string
title: string
description: string
selection_text: string
save_text: string
display_type: number
is_recurring_subscription: string
subs: Sub[]
}

interface Sub {
packageid: number
percent_savings_text: string
percent_savings: number
option_text: string
option_description: string
can_get_free_license: string
is_free_license: boolean
price_in_cents_with_discount: number
}

interface Platforms {
windows: boolean
mac: boolean
linux: boolean
}

interface Recommendations {
total: number
}

interface ReleaseDate {
coming_soon: boolean
date: string
}

interface Screenshot {
id: number
path_thumbnail: string
path_full: string
}

interface SupportInfo {
url: string
email: string
}
2 changes: 1 addition & 1 deletion src/interfaces/Friends.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface Friends {
statusCode: number
statusText: string
friendslist?: Friendslist
data?: Friendslist
}

interface Friendslist {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/GlobalAchievement.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface GlobalAchievement {
statusCode: number
statusText: string
achievementpercentages?: Achievementpercentages
data?: Achievementpercentages
}

interface Achievementpercentages {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/News.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface News {
statusCode: number
statusText: string
appnews?: Appnews
data?: Appnews
}

interface Appnews {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/OwnedGames.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface OwnedGames {
statusCode: number
statusText: string
response?: Response
data?: Response
}

export interface Response {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/PlayerAchievements.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface PlayerAchievements {
statusCode: number
statusText: string
playerstats?: Playerstats
data?: Playerstats
}

export interface Playerstats {
Expand Down
Loading

0 comments on commit dd12ba5

Please sign in to comment.