From 5d2130b6f57fdf5e52300c857fbd6693fe7a984e Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sun, 16 Apr 2023 19:56:42 +0200 Subject: [PATCH] Rename functions --- hn.go | 6 +++--- main.go | 6 +++--- sn.go | 14 +++++++------- sn_test.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hn.go b/hn.go index db84907..df02fe7 100644 --- a/hn.go +++ b/hn.go @@ -30,7 +30,7 @@ func init() { HackerNewsFirebaseUrl = "https://hacker-news.firebaseio.com/v0" } -func fetchTopStoriesFromHN() []Story { +func FetchHackerNewsTopStories() []Story { // API docs: https://github.com/HackerNews/API url := fmt.Sprintf("%s/topstories.json", HackerNewsFirebaseUrl) @@ -53,7 +53,7 @@ func fetchTopStoriesFromHN() []Story { var stories [limit]Story for i, id := range ids { - story := fetchStoryByID(id) + story := FetchStoryById(id) stories[i] = story } @@ -61,7 +61,7 @@ func fetchTopStoriesFromHN() []Story { return stories[:] } -func fetchStoryByID(id ItemID) Story { +func FetchStoryById(id ItemID) Story { url := fmt.Sprintf("https://hacker-news.firebaseio.com/v0/item/%d.json", id) resp, err := http.Get(url) if err != nil { diff --git a/main.go b/main.go index 365ccca..27fa5c6 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,9 @@ package main func main() { - stories := fetchTopStoriesFromHN() - filtered := filterByRelevanceForSN(&stories) + stories := FetchHackerNewsTopStories() + filtered := CurateContentForStackerNews(&stories) for _, story := range *filtered { - postToSN(&story) + PostStoryToStackerNews(&story) } } diff --git a/sn.go b/sn.go index 48013a6..91f7eac 100644 --- a/sn.go +++ b/sn.go @@ -46,7 +46,7 @@ func init() { } } -func makeGraphQLRequest(body GraphQLPayload) *http.Response { +func MakeStackerNewsRequest(body GraphQLPayload) *http.Response { bodyJSON, err := json.Marshal(body) if err != nil { log.Fatal("Error during json.Marshal:", err) @@ -70,14 +70,14 @@ func makeGraphQLRequest(body GraphQLPayload) *http.Response { return resp } -func filterByRelevanceForSN(stories *[]Story) *[]Story { +func CurateContentForStackerNews(stories *[]Story) *[]Story { // TODO: filter by relevance slice := (*stories)[0:1] return &slice } -func fetchDupes(url string) *[]Dupe { +func FetchStackerNewsDupes(url string) *[]Dupe { body := GraphQLPayload{ Query: ` query Dupes($url: String!) { @@ -91,7 +91,7 @@ func fetchDupes(url string) *[]Dupe { "url": url, }, } - resp := makeGraphQLRequest(body) + resp := MakeStackerNewsRequest(body) defer resp.Body.Close() var dupesResp DupesResponse @@ -103,8 +103,8 @@ func fetchDupes(url string) *[]Dupe { return &dupesResp.Data.Dupes } -func postToSN(story *Story) { - dupes := fetchDupes(story.Url) +func PostStoryToStackerNews(story *Story) { + dupes := FetchStackerNewsDupes(story.Url) if len(*dupes) > 0 { return } @@ -122,6 +122,6 @@ func postToSN(story *Story) { "title": story.Title, }, } - resp := makeGraphQLRequest(body) + resp := MakeStackerNewsRequest(body) defer resp.Body.Close() } diff --git a/sn_test.go b/sn_test.go index 020e5cc..806b53d 100644 --- a/sn_test.go +++ b/sn_test.go @@ -9,6 +9,6 @@ import ( func TestFetchDupes(t *testing.T) { // TODO: mock HTTP request url := "https://en.wikipedia.org/wiki/Dishwasher_salmon" - dupes := fetchDupes(url) + dupes := FetchStackerNewsDupes(url) assert.NotEmpty(t, *dupes, "Expected at least one duplicate") }