diff --git a/src/index.ts b/src/index.ts index 454d480..40ec440 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/src/reddit/services/reddit.ts b/src/reddit/services/reddit.ts new file mode 100644 index 0000000..fddc199 --- /dev/null +++ b/src/reddit/services/reddit.ts @@ -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 { + 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 { + 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; + } + } +}