Skip to content

Commit

Permalink
consolidate switch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Mar 6, 2024
1 parent 6153514 commit d0e5f07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,44 +81,12 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
result.success("init called..")
}

"track" -> {
"track", "identify", "groupIdentify", "setGroup", "revenue" -> {
val event = getEvent(call)
amplitude.track(event)
amplitude.logger.debug("Track event: ${call.arguments}")
amplitude.logger.debug("Track ${call.method} event: ${call.arguments}")

result.success("track called..")
}

"identify" -> {
val event = getEvent(call)
amplitude.track(event)
amplitude.logger.debug("Track identify event: ${call.arguments}")

result.success("identify called..")
}

"groupIdentify" -> {
val event = getEvent(call)
amplitude.track(event)
amplitude.logger.debug("Track group identify event: ${call.arguments}")

result.success("groupIdentify called..")
}

"setGroup" -> {
val event = getEvent(call)
amplitude.track(event)
amplitude.logger.debug("Track set group event: ${call.arguments}")

result.success("setGroup called..")
}

"revenue" -> {
val event = getEvent(call)
amplitude.track(event)
amplitude.logger.debug("Track revenue event: ${call.arguments}")

result.success("revenue called..")
result.success("${call.method} called..")
}

"setUserId" -> {
Expand Down
72 changes: 4 additions & 68 deletions ios/Classes/SwiftAmplitudeFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import AmplitudeSwift

result("init called..")

case "track":
case "track", "identify", "groupIdentify", "setGroup", "revenue":
guard let args = call.arguments as? [String: Any] else {
print("\(call.method) called but call.arguments type casting failed.")
return
Expand All @@ -44,75 +44,11 @@ import AmplitudeSwift
do {
let event = try getEvent(args: args)
amplitude?.track(event: event)
amplitude?.logger?.debug(message: "Track event: \(String(describing: call.arguments))")
amplitude?.logger?.debug(message: "Track \(call.method) event: \(String(describing: call.arguments))")

result("track called..")
result("\(call.method) called..")
} catch {
amplitude?.logger?.warn(message: "track called but failed.")
}

case "identify":
guard let args = call.arguments as? [String: Any] else {
print("\(call.method) called but call.arguments type casting failed.")
return
}

do {
let event = try getEvent(args: args)
amplitude?.track(event: event)
amplitude?.logger?.debug(message: "Track identify event: \(String(describing: call.arguments))")

result("identify called..")
} catch {
amplitude?.logger?.warn(message: "identify called but failed.")
}

case "groupIdentify":
guard let args = call.arguments as? [String: Any] else {
print("\(call.method) called but call.arguments type casting failed.")
return
}

do {
let event = try getEvent(args: args)
amplitude?.track(event: event)
amplitude?.logger?.debug(message: "Track group identify event: \(String(describing: call.arguments))")

result("groupIdentify called..")
} catch {
amplitude?.logger?.warn(message: "groupIdentify called but failed.")
}

case "setGroup":
guard let args = call.arguments as? [String: Any] else {
print("\(call.method) called but call.arguments type casting failed.")
return
}

do {
let event = try getEvent(args: args)
amplitude?.track(event: event)
amplitude?.logger?.debug(message: "Track set group event: \(String(describing: call.arguments))")

result("setGroup called..")
} catch {
amplitude?.logger?.warn(message: "setGroup called but failed.")
}

case "revenue":
guard let args = call.arguments as? [String: Any] else {
print("\(call.method) called but call.arguments type casting failed.")
return
}

do {
let event = try getEvent(args: args)
amplitude?.track(event: event)
amplitude?.logger?.debug(message: "Track revenue event: \(String(describing: call.arguments))")

result("revenue called..")
} catch {
amplitude?.logger?.warn(message: "revenue called but failed.")
amplitude?.logger?.warn(message: "\(call.method) called but failed.")
}

case "setUserId":
Expand Down

0 comments on commit d0e5f07

Please sign in to comment.