Skip to content

Commit

Permalink
fix: update how axios does requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilhermeasper committed Aug 30, 2023
1 parent 71bedb9 commit be7f773
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/services/marquinhosApi.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import axios, { AxiosInstance } from 'axios';
import axios from 'axios';
import { PlaybackData, Track } from 'src/types';

export class MarquinhosApiService {
axios: AxiosInstance;

constructor() {
this.axios = axios.create({
baseURL: `${process.env.MARQUINHOS_API_URL}/api/`,
});
}

async addToScrobbleQueue(playbackData: PlaybackData) {
try {
const response = await this.axios.post('/scrobble/queue', {
const options = {
method: 'POST',
url: `${process.env.MARQUINHOS_API_URL}/api/scrobble/queue`,
headers: { 'Content-Type': 'application/json' },
data: {
playbackData,
});
return response.data;
},
};
try {
const { data } = await axios.request(options);
return data;
} catch (error) {
console.log(error);
}
}

async dispatchScrobbleQueue(id: string) {
const options = {
method: 'POST',
url: `${process.env.MARQUINHOS_API_URL}/api/scrobble/${id}`,
};
try {
const { data } = await this.axios.post(`/scrobble/${id}`);
const { data } = await axios.request(options);
return data;
} catch (error) {
console.log(error);
Expand Down

0 comments on commit be7f773

Please sign in to comment.