From 7d5894224b8e5b8186ce29704fee708965597a3d Mon Sep 17 00:00:00 2001
From: Richard Mwewa <74001397+rly0nheart@users.noreply.github.com>
Date: Sun, 3 Dec 2023 18:57:08 +0000
Subject: [PATCH] Delete RPST GUI/RPST/ApiHandler.vb
---
RPST GUI/RPST/ApiHandler.vb | 55 -------------------------------------
1 file changed, 55 deletions(-)
delete mode 100644 RPST GUI/RPST/ApiHandler.vb
diff --git a/RPST GUI/RPST/ApiHandler.vb b/RPST GUI/RPST/ApiHandler.vb
deleted file mode 100644
index d2a56d4..0000000
--- a/RPST GUI/RPST/ApiHandler.vb
+++ /dev/null
@@ -1,55 +0,0 @@
-Imports System.IO
-Imports System.Net.Http
-Imports Newtonsoft.Json
-Imports Newtonsoft.Json.Linq
-
-'''
-''' Handles requests to Reddit and Github APIs.
-'''
-Public Class ApiHandler
- Public Property LogFile As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RedditPostScrapingTool", "logs", $"debug.log")
- Public Property Headers As String = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15"
- Public Property UpdatesEndpoint As String = "https://api.github.com/repos/bellingcat/reddit-post-scraping-tool/releases/latest"
-
- '''
- ''' Asyncrosnously scrape Reddit data.
- '''
- ''' Json object containing scraped data.
- Public Async Function ScrapeRedditAsync(subreddit As String, listing As String, limit As Integer, timeframe As String) As Task(Of JObject)
- Dim ApiEndpoint As String = $"https://www.reddit.com/r/{subreddit}/{listing}.json?limit={limit}&t={timeframe}"
- Return Await GetJObjectFromEndpointAsync(endpoint:=ApiEndpoint)
- End Function
-
- '''
- ''' Asyncrosnously gets remote version information from the repository release page.
- '''
- ''' Json object containing update data.
- Public Async Function CheckUpdatesAsync() As Task(Of JObject)
- Return Await GetJObjectFromEndpointAsync(endpoint:=UpdatesEndpoint)
- End Function
-
- '''
- ''' Asyncronously retrieves a JObject from the specified endpoint.
- '''
- ''' The URL endpoint to retrieve data from.
- ''' A JObject containing the retrieved data.
- Private Async Function GetJObjectFromEndpointAsync(endpoint As String) As Task(Of JObject)
- Try
- Using httpClient As New HttpClient()
- httpClient.DefaultRequestHeaders.Add("User-Agent", Headers)
- Dim response As HttpResponseMessage = Await httpClient.GetAsync(endpoint)
- If response.IsSuccessStatusCode Then
- Dim json As String = response.Content.ReadAsStringAsync().Result
- Dim data As JObject = JsonConvert.DeserializeObject(Of JObject)(json)
- Return data
- Else
- MessageBox.Show(response.ReasonPhrase, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End If
- End Using
- Catch ex As Exception
- My.Computer.FileSystem.WriteAllText(LogFile, $"{DateTime.Now}: {ex}{Environment.NewLine}", True)
- MessageBox.Show($"{ex.Message}. Please see the debug log '{LogFile}' for more information.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- Return New JObject()
- End Function
-End Class