add spotify service
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
897cbaa6a3
commit
e1fe02e63c
@ -1,9 +1,17 @@
|
||||
import Music from "./Music";
|
||||
|
||||
class Spot {
|
||||
private userId : string;
|
||||
public music : Music;
|
||||
export class Spot {
|
||||
private _userId : string;
|
||||
public _music : Music;
|
||||
constructor(userId : string, music : Music){
|
||||
this.userId = userId;
|
||||
this.music = music;
|
||||
this._userId = userId;
|
||||
this._music = music;
|
||||
}
|
||||
get userSpotifyId(): string {
|
||||
return this._userId;
|
||||
}
|
||||
get idSpotify(): Music {
|
||||
return this._music;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
class TokenSpotify {
|
||||
String _accessToken;
|
||||
final String _refreshToken;
|
||||
late DateTime _tokenEnd;
|
||||
|
||||
// TokenSpotify(this._accessToken, this._refreshToken, int expiresIn) {
|
||||
// _setTokenEnd(expiresIn);
|
||||
// }
|
||||
|
||||
// _setTokenEnd(int expiresIn) {
|
||||
// _tokenEnd = DateTime.now().add(Duration(seconds: expiresIn));
|
||||
// }
|
||||
|
||||
// Future<String> getAccessToken() async {
|
||||
// if (DateTime.now().isAfter(_tokenEnd)) {
|
||||
// await _actualiseToken();
|
||||
// }
|
||||
// return _accessToken;
|
||||
// }
|
||||
|
||||
// _actualiseToken() async {
|
||||
// var urlToken = Uri.https('accounts.spotify.com', 'api/token', {
|
||||
// 'grant_type': 'refresh_token',
|
||||
// 'refresh_token': _refreshToken,
|
||||
// 'client_id': ApiSpotifyIdentification.clientId
|
||||
// });
|
||||
// setResponse(await http.post(urlToken, headers: <String, String>{
|
||||
// 'Content-Type': 'application/x-www-form-urlencoded'
|
||||
// }));
|
||||
// var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
|
||||
// _accessToken = decodedResponse['access_token'];
|
||||
// _setTokenEnd(decodedResponse['expires_in']);
|
||||
// }
|
||||
}
|
@ -1,9 +1,42 @@
|
||||
class User {
|
||||
export class User {
|
||||
//attributes from DAFL
|
||||
private idFlad : any;;
|
||||
private idSpotify : any;
|
||||
private _idFlad : string;
|
||||
private _idSpotify : string;
|
||||
private _email : string;
|
||||
private _createdAt : Date;
|
||||
private _name : string;
|
||||
public image : string = require('../assets/images/jul.png');
|
||||
//constructors
|
||||
constructor(){
|
||||
constructor(idFlad : string, idSpotify : string, email : string, createdAt : Date, name : string, image : string){
|
||||
this._name = name;
|
||||
this._idFlad = idFlad;
|
||||
this._idSpotify = idSpotify;
|
||||
this._createdAt = createdAt;
|
||||
this._email = email;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
get idFlad(): string {
|
||||
return this._idFlad;
|
||||
}
|
||||
get idSpotify(): string {
|
||||
return this._idSpotify;
|
||||
}
|
||||
get email(): string {
|
||||
return this._email;
|
||||
}
|
||||
get createAt(): Date {
|
||||
return this._createdAt;
|
||||
}
|
||||
get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
static empty() {
|
||||
return new User('','','',new Date(),'',require('../assets/images/jul.png'));
|
||||
}
|
||||
|
||||
toString() {
|
||||
return 'User : ' + this.idFlad + ', ' + this.name + ', ' + this.idSpotify;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import Music from "../Music";
|
||||
|
||||
export default class MusicFactory {
|
||||
static mapFromSpotifyTrack(jsonMusic :any ): Music {
|
||||
const music = new Music(
|
||||
jsonMusic.id,
|
||||
jsonMusic.name,
|
||||
jsonMusic.album.images[0].url
|
||||
);
|
||||
return music;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import { User } from "../User";
|
||||
|
||||
export class UserFactory {
|
||||
|
||||
public static JsonToModel( jsonUser :any ) : User{
|
||||
return new User(jsonUser.idFlad, jsonUser.idSpotify, jsonUser.email, jsonUser.createdAt, jsonUser.name, jsonUser.imageUrl);
|
||||
}
|
||||
public static uptade( jsonUser :any ) : User{
|
||||
return new User(jsonUser.idFlad, jsonUser.idSpotify, jsonUser.email, jsonUser.createdAt, jsonUser.name, jsonUser.imageUrl);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,17 @@
|
||||
import Music from "../../Model/Music";
|
||||
import { Spot } from "../../Model/Spot";
|
||||
import {spotTypes} from "../types/spotTypes";
|
||||
|
||||
export const setSpotList = (spotList: Spot[]) => {
|
||||
return {
|
||||
type: spotTypes.FETCH_SPOT,
|
||||
payload: spotList,
|
||||
playload: spotList,
|
||||
};
|
||||
}
|
||||
|
||||
export const setUserCurrentMusic = (currentMusic: Music) => {
|
||||
return {
|
||||
type: spotTypes.FETCH_SPOT,
|
||||
playload: currentMusic,
|
||||
};
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export const discoveriesTypes = {
|
||||
FETCH_DISCOVERIES : 'FETCH_DISCOVERIES',
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
export const favoritesTypes = {
|
||||
ADD_FAVORITE_MUSICS : 'ADD_FAVORITE_MUSICS',
|
||||
REMOVE_FAVORITE_MUSICS : 'REMOVE_FAVORITE_MUSICS',
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export const playlistTypes = {
|
||||
FETCH_USER_PLAYLISTS : 'FETCH_SPOT',
|
||||
SAVE_IN_FLAD_PLAYLIST : 'SAVE_IN_FLAD_PLAYLIST',
|
||||
FETCH_FLAD_PLAYLIST : 'FETCH_SPOT',
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
export const spotTypes = {
|
||||
FETCH_SPOT : 'FETCH_NOUNOURS',
|
||||
FETCH_SPOT : 'FETCH_SPOT',
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export const spotifyTypes = {
|
||||
GET_USER_CURRENT_MUSIC : 'GET_USER_CURRENT_MUSIC',
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
interface IspotifyService {
|
||||
getMusicById(idMusic : string): Promise<any>;
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import axios, { AxiosError } from "axios";
|
||||
|
||||
export type Methods = 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
|
||||
|
||||
export interface FetchOptions {
|
||||
/** The headers to apply. */
|
||||
headers?: Record<string, string>;
|
||||
/** The method type. */
|
||||
method?: Methods;
|
||||
/** Search query parameters. */
|
||||
params?: Record<string, any>;
|
||||
/** The json body to send if available. */
|
||||
body?: Record<string, string | boolean | number | (string | boolean | number)[]>;
|
||||
}
|
||||
|
||||
export class RequestHandler{
|
||||
private _version: `v${number}` = 'v1';
|
||||
get version(): string {
|
||||
return this._version;
|
||||
}
|
||||
|
||||
public async spotifyFetch(url: string, options: FetchOptions = {}, token: string) {
|
||||
const resp = await axios({
|
||||
url: `https://api.spotify.com/${this.version}${url}`,
|
||||
method: options.method || 'GET',
|
||||
params: options.params,
|
||||
headers: {
|
||||
Authorization: "Bearer " + token,
|
||||
Accept: 'application/json',
|
||||
...options.headers
|
||||
},
|
||||
data: options.body
|
||||
});
|
||||
console.log()
|
||||
return resp;
|
||||
// if (
|
||||
// // @ts-ignore
|
||||
// error.response.data?.error?.message == "Invalid access token" ||
|
||||
// // @ts-ignore
|
||||
// error.response.data?.error?.message == "The access token expired" &&
|
||||
// this.refreshMeta
|
||||
// ) await this.refreshFromMeta();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue