From 3a0b8730ecf279bd8297c933e4294493bb2daccb Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Fri, 20 Aug 2021 21:17:52 -0400 Subject: [PATCH] Add request file --- lib/utility/request.dart | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/utility/request.dart diff --git a/lib/utility/request.dart b/lib/utility/request.dart new file mode 100644 index 00000000..91f0a813 --- /dev/null +++ b/lib/utility/request.dart @@ -0,0 +1,37 @@ +import 'dart:convert'; + +import 'package:http/http.dart' as http; + +class Request { + static Future getDefaultToken() async { + final url = Uri( + scheme: 'https', + host: 'id.twitch.tv', + path: '/oauth2/token', + queryParameters: { + 'client_id': const String.fromEnvironment('CLIENT_ID'), + 'client_secret': const String.fromEnvironment('SECRET'), + 'grant_type': 'client_credentials' + }, + ); + + final response = await http.post(url); + final decoded = jsonDecode(response.body); + print(decoded); + return decoded['access_token']; + } + + static void getTopChannels({required String token}) async { + final url = Uri.parse('https://api.twitch.tv/helix/streams?first=10'); + final headers = {'Authorization': 'Bearer $token', 'Client-Id': const String.fromEnvironment('CLIENT_ID')}; + final response = await http.get(url, headers: headers); + final decoded = jsonDecode(response.body); + print(decoded); + final data = decoded['data']; + print(data); + + //final List emotes = decoded.map((emote) => EmoteBTTVGlobal.fromJson(emote)).toList(); + } +} + +enum HTTPMethod { GET, POST }