No need for tiles, just service status
This commit is contained in:
@ -4,13 +4,14 @@ var uiActions = require('../ui/actions')
|
||||
var helpers = require('../../helpers')
|
||||
|
||||
/**
|
||||
* Send an ajax request to the Spotify API
|
||||
* Send an ajax request to the LastFM API
|
||||
*
|
||||
* @param dispatch obj
|
||||
* @param getState obj
|
||||
* @param endpoint params = the url params to send
|
||||
* @param dispatch = obj
|
||||
* @param getState = obj
|
||||
* @param params = string, the url params to send
|
||||
* @param signed = boolean
|
||||
**/
|
||||
const sendRequest = (dispatch, getState, params ) => {
|
||||
const sendRequest = (dispatch, getState, params, signed) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
var loader_key = helpers.generateGuid()
|
||||
@ -75,11 +76,11 @@ export function connect(){
|
||||
|
||||
dispatch({ type: 'LASTFM_CONNECTING' });
|
||||
|
||||
// Authorized, dual-purpose our connection to get the current user
|
||||
// Authorized? Multi-purpose our connection test to get the current user
|
||||
if (getState().lastfm.session){
|
||||
dispatch(getMe());
|
||||
|
||||
// Not authorized, just use a generic lookup to test our connection
|
||||
// Not authorized? Just use a generic lookup to test our connection
|
||||
} else {
|
||||
sendRequest(dispatch, getState, 'method=artist.getInfo&artist=')
|
||||
.then(
|
||||
@ -91,6 +92,33 @@ export function connect(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signed requests
|
||||
* TODO
|
||||
**/
|
||||
|
||||
export function loveTrack(artist, track){
|
||||
return (dispatch, getState) => {
|
||||
var params = 'method=track.love&artist='+artist+'&track='+track
|
||||
sendRequest(dispatch, getState, params, true)
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'LASTFM_TRACK_LOVED',
|
||||
artist: artist,
|
||||
track: track
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Non-signed requests
|
||||
**/
|
||||
|
||||
export function getMe(){
|
||||
return (dispatch, getState) => {
|
||||
var params = 'method=user.getInfo&user='+getState().lastfm.session.name
|
||||
|
||||
@ -192,25 +192,8 @@ export function set(data){
|
||||
|
||||
export function connect(){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({ type: 'SPOTIFY_CONNECTING' });
|
||||
|
||||
// send a generic request to ensure spotify is up and running
|
||||
// there is no 'test' or 'ping' endpoint on the Spotify API
|
||||
sendRequest(dispatch, getState, 'browse/categories?limit=1' )
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_CONNECTED'
|
||||
});
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not connect to Spotify',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
dispatch(getMe());
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,12 +243,14 @@ export function getMe(){
|
||||
type: 'SPOTIFY_ME_LOADED',
|
||||
data: response
|
||||
});
|
||||
dispatch({ type: 'SPOTIFY_CONNECTED' });
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not load your profile',
|
||||
error
|
||||
));
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -27,10 +27,7 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch(spotifyActions.getAllLibraryPlaylists())
|
||||
}
|
||||
|
||||
// Get the current logged-in user
|
||||
store.dispatch(spotifyActions.getMe())
|
||||
|
||||
next(action)
|
||||
next(action);
|
||||
break
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
|
||||
Reference in New Issue
Block a user