Skip to content

Commit

Permalink
feat: add class and file placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyang1520 committed Oct 28, 2022
1 parent 9978db8 commit d824cf1
Show file tree
Hide file tree
Showing 16 changed files with 704 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Amplitude-Swift",
dependencies: []),
dependencies: [],
path: "Sources/Amplitude"),
.testTarget(
name: "Amplitude-SwiftTests",
dependencies: ["Amplitude-Swift"]),
Expand Down
6 changes: 0 additions & 6 deletions Sources/Amplitude-Swift/Amplitude_Swift.swift

This file was deleted.

72 changes: 72 additions & 0 deletions Sources/Amplitude/Amplitude.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
public class Amplitude {
var configuration: Configuration
var instanceName: String
init(configuration: Configuration, instanceName: String = "default") {
self.configuration = configuration
self.instanceName = instanceName
}

func getInstance(instsanceName: String) -> Amplitude {
return self
}

func track() -> Amplitude {
return self
}

func logEvent() -> Amplitude {
return self
}

func identify(type: String) -> Amplitude {
return self
}

func identify() -> Amplitude {
return self
}

func groupIdentify() -> Amplitude {
return self
}

func groupIdentify(groupType: String, groupName: String, groupProperties: [String: Any], options: [String: Any]) -> Amplitude {
return self
}

func logRevenue() -> Amplitude {
return self
}

func revenue() -> Amplitude {
return self
}

func add(plugin: Plugin) -> Amplitude {
return self
}

func remove(plugin: Plugin) -> Amplitude {
return self
}

func flush() -> Amplitude {
return self
}

func setUserId(userId: String) -> Amplitude {
return self
}

func setDeviceId(deviceId: String) -> Amplitude {
return self
}

func reset() -> Amplitude {
return self
}
}

func amplitude(apiKey: String, configs: Configuration) -> Amplitude {
return Amplitude(configuration: Configuration(flushQueueSize: <#Int#>, flushIntervalMillis: <#Int#>, instanceName: <#String#>, optOut: <#Bool#>, storageProvider: <#Storage#>, logLvel: <#LogLevelEnum#>, loggerProvider: <#Logger#>, flushMaxRetries: <#Int#>, useBatch: <#Bool#>, serverZone: <#ServerZone#>), instanceName: "default")
}
47 changes: 47 additions & 0 deletions Sources/Amplitude/Configuration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/27/22.
//

import Foundation

public class Configuration {
var flushQueueSize: Int = 30
var flushIntervalMillis: Int = 30 * 1000
var instanceName: String = "default"
var optOut: Bool = false
var storageProvider: Storage = CoreDataStorage()
var logLvel: LogLevelEnum = LogLevelEnum.WARN
var loggerProvider: any Logger = ConsoleLogger()
var minIdLength: Int?
var partnerId: String?
var callback: EventCallBack?
var flushMaxRetries: Int = 5
var useBatch: Bool = false
var serverZone: ServerZone = ServerZone.US
var serverUrl: String?
var plan: Plan?
var ingestionMetadata: IngestionMetadata?
var trackingOptions: TrackingOptions?

init(flushQueueSize: Int, flushIntervalMillis: Int, instanceName: String, optOut: Bool, storageProvider: Storage, logLvel: LogLevelEnum, loggerProvider: any Logger, minIdLength: Int? = nil, partnerId: String? = nil, callback: EventCallBack? = nil, flushMaxRetries: Int, useBatch: Bool, serverZone: ServerZone, serverUrl: String? = nil, plan: Plan? = nil, ingestionMetadata: IngestionMetadata? = nil) {
self.flushQueueSize = flushQueueSize
self.flushIntervalMillis = flushIntervalMillis
self.instanceName = instanceName
self.optOut = optOut
self.storageProvider = storageProvider
self.logLvel = logLvel
self.loggerProvider = loggerProvider
self.minIdLength = minIdLength
self.partnerId = partnerId
self.callback = callback
self.flushMaxRetries = flushMaxRetries
self.useBatch = useBatch
self.serverZone = serverZone
self.serverUrl = serverUrl
self.plan = plan
self.ingestionMetadata = ingestionMetadata
}
}
34 changes: 34 additions & 0 deletions Sources/Amplitude/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/27/22.
//

import Foundation

enum LogLevelEnum: Int {
case DEBUG
case LOG
case WARN
case ERROR
case OFF
}

enum ServerZone: String {
case US = "US"
case EU = "EU"
}

public struct Constants {
let SDK_LIBRARY = "amplitude-swift"
let DEFAULT_API_HOST = "https://api2.amplitude.com/2/httpapi"
let EU_DEFAULT_API_HOST = "https://api.eu.amplitude.com/2/httpapi"
let BATCH_API_HOST = "https://api2.amplitude.com/batch"
let EU_BATCH_API_HOST = "https://api.eu.amplitude.com/batch"
let IDENTIFY_EVENT = "$identify"
let GROUP_IDENTIFY_EVENT = "$groupidentify"
let AMP_REVENUE_EVENT = "revenue_amount"
let MAX_PROPERTY_KEYS = 1024
let MAX_STRING_LENGTH = 1024
}
40 changes: 40 additions & 0 deletions Sources/Amplitude/EventBridge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/27/22.
//

import Foundation

struct Event {
var eventType: String
var eventProperties: [String: Any]? = nil
var userProperties: [String: Any]? = nil
var groups: [String: Any]? = nil
var groupProperties: [String: Any]? = nil
}

enum EventChannel {

}

protocol EventReceiver {
func receive(channel: EventChannel, event: Event)
}


protocol EventBridgable {
func sendEvent(channel: EventChannel, event: Event)
func setReceiver(channel: EventChannel, receiver: EventReceiver)
}

class EventBridge: EventBridgable {
func sendEvent(channel: EventChannel, event: Event) {
<#code#>
}

func setReceiver(channel: EventChannel, receiver: EventReceiver) {
<#code#>
}
}
30 changes: 30 additions & 0 deletions Sources/Amplitude/Logger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/28/22.
//

import Foundation

class ConsoleLogger: Logger {
typealias LogLevel = LogLevelEnum

var logLevel: Int?

func error(message: String) {
<#code#>
}

func warn(message: String) {
<#code#>
}

func log(message: String) {
<#code#>
}

func debug(message: String) {
<#code#>
}
}
22 changes: 22 additions & 0 deletions Sources/Amplitude/Plugins/AmplitudeDestinationPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/27/22.
//

import Foundation

public class AmplitudeDestinationPlugin: Plugin {
public var type: PluginType = PluginType.Destination

public var amplitude: Amplitude?

public func setup(amplitude: Amplitude) {
<#code#>
}

public func execute(event: BaseEvent) -> BaseEvent? {
<#code#>
}
}
22 changes: 22 additions & 0 deletions Sources/Amplitude/Plugins/ContextPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/28/22.
//

import Foundation

class ContextPlugin: Plugin {
var type: PluginType = PluginType.Before

var amplitude: Amplitude?

func setup(amplitude: Amplitude) {
<#code#>
}

func execute(event: BaseEvent) -> BaseEvent? {
<#code#>
}
}
30 changes: 30 additions & 0 deletions Sources/Amplitude/Storages/CoreDataStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/28/22.
//

import Foundation

class CoreDataStorage: Storage {
func set(key: String, value: String) async {
<#code#>
}

func get(key: String) async -> String? {
<#code#>
}

func saveEvent(event: BaseEvent) async {
<#code#>
}

func getEvents() async -> [Any]? {
<#code#>
}

func reset() async {
<#code#>
}
}
31 changes: 31 additions & 0 deletions Sources/Amplitude/Storages/InMemoryStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/28/22.
//

import Foundation

class InMemoryStorage: Storage {
func set(key: String, value: String) async {
<#code#>
}

func get(key: String) async -> String? {
<#code#>
}

func saveEvent(event: BaseEvent) async {
<#code#>
}

func getEvents() async -> [Any]? {
<#code#>
}

func reset() async {
<#code#>
}

}
32 changes: 32 additions & 0 deletions Sources/Amplitude/Timeline.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// File.swift
//
//
// Created by Marvin Liu on 10/27/22.
//

import Foundation

public class Timeline {
var plugins = [PluginType: [any Plugin]]()

init() {

}

func process(event: BaseEvent) {

}

func add(plugin: Plugin) {

}

func remove(plugin: Plugin) {

}

func apply(event: BaseEvent) -> BaseEvent? {

}
}
Loading

0 comments on commit d824cf1

Please sign in to comment.