Proxy fully operational; Initial API requests to Genius
This commit is contained in:
@ -7,6 +7,7 @@ export function getBroadcasts(){
|
||||
return (dispatch, getState) => {
|
||||
var config = {
|
||||
method: 'GET',
|
||||
timeout: 15000,
|
||||
url: 'https://gist.githubusercontent.com/jaedb/b677dccf80daf3ccb2ef12e96e495677/raw'
|
||||
}
|
||||
$.ajax(config).then(
|
||||
|
||||
@ -4,7 +4,7 @@ var uiActions = require('../ui/actions')
|
||||
var helpers = require('../../helpers')
|
||||
|
||||
/**
|
||||
* Send an ajax request to the Spotify API
|
||||
* Send an ajax request
|
||||
*
|
||||
* @param dispatch obj
|
||||
* @param getState obj
|
||||
@ -17,26 +17,33 @@ const sendRequest = (dispatch, getState, endpoint) => {
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_'+endpoint));
|
||||
|
||||
var config = {
|
||||
method: 'GET',
|
||||
method: 'POST',
|
||||
cache: false,
|
||||
url: 'https://api.genius.com/'+endpoint+'&access_token=2AGP9sfzKQcxfKSZuGa_3lqsDIpuOiTGT7-vhJYcKaaDjHIIA2HICsxXCiC30Xxi'
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
Authorization: 'Bearer 2AGP9sfzKQcxfKSZuGa_3lqsDIpuOiTGT7-vhJYcKaaDjHIIA2HICsxXCiC30Xxi'
|
||||
},
|
||||
data: JSON.stringify({
|
||||
url: 'https://api.genius.com/'+endpoint
|
||||
}),
|
||||
url: '//'+getState().mopidy.host+':'+getState().mopidy.port+'/iris/http/proxy_request'
|
||||
};
|
||||
|
||||
$.ajax(config).then(
|
||||
response => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
resolve(response.response);
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
reject({
|
||||
config: config,
|
||||
xhr: xhr,
|
||||
status: status,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
)
|
||||
response => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
resolve(response.response);
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
reject({
|
||||
config: config,
|
||||
xhr: xhr,
|
||||
status: status,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -49,15 +56,15 @@ export function getTrackInfo(track){
|
||||
}
|
||||
query += track.name;
|
||||
|
||||
sendRequest(dispatch, getState, 'search?q='+query)
|
||||
sendRequest(dispatch, getState, 'search?q='+encodeURIComponent(query))
|
||||
.then(
|
||||
response => {
|
||||
if (response.hits && response.hits.length > 0){
|
||||
if (response.response.hits && response.response.hits.length > 0){
|
||||
dispatch({
|
||||
type: 'TRACK_LOADED',
|
||||
key: track.uri,
|
||||
track: {
|
||||
annotations: response.hits[0].result
|
||||
annotations: response.response.hits[0].result
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -68,6 +75,6 @@ export function getTrackInfo(track){
|
||||
error
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ const sendRequest = ( dispatch, getState, params ) => {
|
||||
var config = {
|
||||
method: 'GET',
|
||||
cache: true,
|
||||
timeout: 15000,
|
||||
url: '//ws.audioscrobbler.com/2.0/?format=json&api_key=4320a3ef51c9b3d69de552ac083c55e3&'+params
|
||||
}
|
||||
|
||||
|
||||
@ -159,13 +159,13 @@ const MopidyMiddleware = (function(){
|
||||
var loader_key = helpers.generateGuid()
|
||||
store.dispatch(uiActions.startLoading(loader_key, 'mopidy_'+property))
|
||||
|
||||
// Start our 10 second timeout
|
||||
// Start our 15 second timeout
|
||||
var timeout = setTimeout(
|
||||
function(){
|
||||
store.dispatch(uiActions.stopLoading(loader_key));
|
||||
reject({message: "Request timed out", call: call, value: value});
|
||||
},
|
||||
10000
|
||||
15000
|
||||
);
|
||||
|
||||
mopidyObject(value)
|
||||
|
||||
@ -59,7 +59,7 @@ export function sendAuthorization( recipient_connectionid, authorization, me ){
|
||||
return {
|
||||
type: 'PUSHER_DELIVER_MESSAGE',
|
||||
data: {
|
||||
to: recipient_connectionid,
|
||||
connection_id: recipient_connectionid,
|
||||
message: {
|
||||
type: 'spotify_authorization',
|
||||
authorization: authorization,
|
||||
|
||||
@ -63,13 +63,13 @@ const PusherMiddleware = (function(){
|
||||
|
||||
store.dispatch(uiActions.startLoading(request_id, 'pusher_'+method))
|
||||
|
||||
// Start our 10 second timeout
|
||||
// Start our 15 second timeout
|
||||
var timeout = setTimeout(
|
||||
function(){
|
||||
store.dispatch(uiActions.stopLoading(request_id));
|
||||
reject({message: "Request timed out", method: method, data: data});
|
||||
},
|
||||
10000
|
||||
15000
|
||||
);
|
||||
|
||||
// add query to our deferred responses
|
||||
|
||||
@ -33,6 +33,7 @@ const sendRequest = ( dispatch, getState, endpoint, method = 'GET', data = false
|
||||
method: method,
|
||||
url: url,
|
||||
cached: true,
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
Authorization: 'Bearer '+ response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user