Skip to content

Commit

Permalink
Add example event for ETTrace (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itaybre authored Sep 14, 2023
1 parent bb33e27 commit d894aa2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ios/Hacker News/Network/HNApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ class HNApi {
init() {}

func fetchTopStories() async -> [Story] {
NotificationCenter.default.post(name: Notification.Name(rawValue: "EmergeMetricStarted"), object: nil, userInfo: [
"metric": "FETCH_STORIES"
])
let url = URL(string: "https://hacker-news.firebaseio.com/v0/topstories.json")!

do {
let (data, _) = try await URLSession.shared.data(from: url)
let decoder = JSONDecoder()
let storyIds = try decoder.decode([Int64].self, from: data)
let items = await fetchItems(ids: Array(storyIds.prefix(20)))

NotificationCenter.default.post(name: Notification.Name(rawValue: "EmergeMetricEnded"), object: nil, userInfo: [
"metric": "FETCH_STORIES"
])
return items.compactMap { $0 as? Story }
} catch {
print("Error fetching post IDs: \(error)")
Expand Down

0 comments on commit d894aa2

Please sign in to comment.