-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
144 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ChzzkService } from './chzzk.service'; | ||
|
||
@Module({ | ||
providers: [ChzzkService], | ||
exports: [ChzzkService], | ||
}) | ||
export class ChzzkModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import axios from 'axios'; | ||
import { CommonOptionsDto } from './dto/common.dto'; | ||
import { GetChannelByIdParamsDto } from './dto/params.dto'; | ||
import { | ||
ChzzkChannel, | ||
ChzzkGetChannelResponse, | ||
} from './dto/response.interface'; | ||
|
||
@Injectable() | ||
export class ChzzkService { | ||
constructor() {} | ||
|
||
/** | ||
* Get Chzzk Channel Information by Channel ID | ||
* @param params | ||
* @param options | ||
* @returns ChzzkChannel | null | ||
*/ | ||
async getChannelById( | ||
params: GetChannelByIdParamsDto, | ||
options?: CommonOptionsDto, | ||
): Promise<ChzzkChannel> { | ||
const apiUrl = `https://api.chzzk.naver.com/service/v1/channels/${params.channelId}`; | ||
|
||
const response = await axios | ||
.get(apiUrl) | ||
.then((response) => { | ||
if (response.data.content.channelId === null) { | ||
throw new NotFoundException('채널을 찾을 수 없습니다.'); | ||
} | ||
|
||
return response.data as ChzzkGetChannelResponse; | ||
}) | ||
.catch((error) => { | ||
if (options?.throwException) { | ||
throw new NotFoundException('채널을 찾을 수 없습니다.'); | ||
} | ||
|
||
console.log(error); | ||
|
||
return { | ||
content: null, | ||
} as ChzzkGetChannelResponse; | ||
}); | ||
|
||
return response.content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Common options for all requests | ||
*/ | ||
export class CommonOptionsDto { | ||
/** | ||
* Throw exception when error occurs | ||
*/ | ||
throwException: boolean = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export class GetChannelByIdParamsDto { | ||
/** | ||
* Channel ID | ||
*/ | ||
channelId: string; | ||
} |
Oops, something went wrong.