parent
8f44cbc46f
commit
e40560aa7d
@ -0,0 +1,10 @@
|
||||
import '../model/Comment.dart';
|
||||
|
||||
class CommentViewModel {
|
||||
|
||||
// Methods
|
||||
List<Comment> getCommentsPost(int idPost) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import '../model/Music.dart';
|
||||
|
||||
class MusicViewModel {
|
||||
|
||||
final String API_URL = "";
|
||||
|
||||
// Methods
|
||||
Music getMusic(int id) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
Music getMusicWithName(String name) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
List<Music> getMusics(String name) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
import 'package:justmusic/model/Post.dart';
|
||||
|
||||
class PostViewModel {
|
||||
List<Post> _postsFriends = [];
|
||||
List<Post> _bestPosts = [];
|
||||
|
||||
// Constructor
|
||||
PostViewModel();
|
||||
|
||||
// Getters and setters
|
||||
List<Post> get postsFriends => _postsFriends;
|
||||
|
||||
List<Post> get bestPosts => _bestPosts;
|
||||
|
||||
// Methods
|
||||
List<Post> getPostsFriends() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
List<Post> getMorePostsFriends() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
List<Post> getBestPosts() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
List<Post> getMoreBestPosts() {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class TokenSpotify {
|
||||
final String clientId = 'd9b82921bbdf43efa15d0c34c28c6f93';
|
||||
final String _clientSecret = 'ba01687f59ea4ab7ad00c769e89e44d8';
|
||||
late String _accessToken;
|
||||
late DateTime _tokenEnd;
|
||||
|
||||
TokenSpotify() {
|
||||
_tokenEnd = DateTime.now().add(Duration(seconds: -1));
|
||||
}
|
||||
|
||||
Future<String> getAccessToken() async {
|
||||
if (_isTokenExpired()) {
|
||||
await _refreshToken();
|
||||
}
|
||||
return _accessToken;
|
||||
}
|
||||
|
||||
_refreshToken() async {
|
||||
final basicAuth = base64Encode(utf8.encode('$clientId:$_clientSecret'));
|
||||
final response = await http.post(
|
||||
Uri.parse('https://accounts.spotify.com/api/token'),
|
||||
headers: {
|
||||
'Authorization': 'Basic $basicAuth',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'grant_type=client_credentials',
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseData = jsonDecode(response.body);
|
||||
_accessToken = responseData['access_token'];
|
||||
_tokenEnd = DateTime.now().add(Duration(seconds: responseData['expires_in']));
|
||||
} else {
|
||||
print('Erreur lors de l\'actualisation du token : ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
bool _isTokenExpired() {
|
||||
return DateTime.now().isAfter(_tokenEnd);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
import '../model/User.dart';
|
||||
|
||||
class UserViewModel {
|
||||
User? _userCurrent;
|
||||
|
||||
// Constructor
|
||||
UserViewModel();
|
||||
|
||||
// Methods
|
||||
User getUser(int id) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue