Skip to content

Instantly share code, notes, and snippets.

@joshuawright11
Last active February 4, 2022 21:40
Show Gist options
  • Save joshuawright11/57c4ff03db0bd4ab4fcd20bb752faf5e to your computer and use it in GitHub Desktop.
Save joshuawright11/57c4ff03db0bd4ab4fcd20bb752faf5e to your computer and use it in GitHub Desktop.
struct UploadAnalyticsJob: Job {
func run() async throws {
var allEvents: [AnalyticsEvent] = []
allEvents.append(contentsOf: try await CardEvent.all().map(\.event))
}
}
extension CardEvent {
fileprivate var event: AnalyticsEvent {
.cardEvent(
amount: card.amount,
network: card.network,
merchantAddressCity: card.merchantAddressCity,
merchantName: card.merchantName)
}
}
struct AnalyticsEvent {
// ...
static func cardEvent(
amount: String,
network: String,
merchantAddressCity: String?,
merchantName: String?
) -> AnalyticsEvent {
AnalyticsEvent(
event: "Card",
properties: [
.amount(amount),
.network(network),
merchantAddressCity.map { .merchantAddressCity($0) },
merchantName.map { .merchantName($0) },
].compactMap { $0 })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment