reddit service implementation
parent
522ec2de51
commit
af5b35589d
|
@ -31,11 +31,7 @@ async function startApplication() {
|
|||
console.log('Database Maintenance Start')
|
||||
await databaseMaintenance.runMaintenanceTasks()
|
||||
|
||||
const redditSessionManager = await redditSession.getInstance(databaseService)
|
||||
|
||||
const response = await redditSessionManager.axiosInstance.get('/me')
|
||||
|
||||
console.log(JSON.stringify(response.data, null, 4))
|
||||
await redditSession.getInstance(databaseService)
|
||||
|
||||
// Initialize services with any required dependencies
|
||||
const commentFetcher = new CommentProcessor(databaseService);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import axios, { AxiosError } from 'axios';
|
||||
import SessionManager from '../session/SessionManager';
|
||||
|
||||
export class RedditService {
|
||||
private sessionManager: SessionManager;
|
||||
|
||||
constructor(sessionManager: SessionManager) {
|
||||
this.sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
async getUserInfo(username: string): Promise<any> {
|
||||
try {
|
||||
const response = await this.sessionManager.axiosInstance.get(`/user/${username}/about`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching user info:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async sendMessage(username: string, subject: string, message: string): Promise<void> {
|
||||
try {
|
||||
await this.sessionManager.axiosInstance.post('/api/compose', {
|
||||
api_type: 'json',
|
||||
to: username,
|
||||
subject: subject,
|
||||
text: message,
|
||||
});
|
||||
console.log(`Message sent to ${username}`);
|
||||
} catch (error) {
|
||||
console.error('Error sending message:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue