Skip to content

Commit

Permalink
feat: setup lint, jira issue create, fix all file lint issues, update…
Browse files Browse the repository at this point in the history
… config
  • Loading branch information
liuyang1520 committed Nov 2, 2022
1 parent d824cf1 commit 8e1beb1
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 187 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/jira-issue-create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Creates jira tickets for new github issues to help triage
name: Jira Issue Creator For Kotlin

on:
issues:
types: [opened]
workflow_call:
inputs:
label:
type: string

jobs:
call-workflow-passing-data:
uses: amplitude/Amplitude-TypeScript/.github/workflows/jira-issue-create-template.yml@main
with:
label: "Swift"
secrets:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint

on:
pull_request:
push:
branches:
- main

jobs:
lint:
runs-on: macos-12
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set Xcode 14
run: |
sudo xcode-select -switch /Applications/Xcode_14.1.app
- name: Lint
run: swiftlint
6 changes: 6 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
disabled_rules:
- function_body_length
- trailing_comma
identifier_name:
allowed_symbols: "_"
min_length: 1
10 changes: 7 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let package = Package(
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Amplitude-Swift",
targets: ["Amplitude-Swift"]),
targets: ["Amplitude-Swift"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -21,9 +22,12 @@ let package = Package(
.target(
name: "Amplitude-Swift",
dependencies: [],
path: "Sources/Amplitude"),
path: "Sources/Amplitude"
),
.testTarget(
name: "Amplitude-SwiftTests",
dependencies: ["Amplitude-Swift"]),
dependencies: ["Amplitude-Swift"],
path: "Tests/AmplitudeTests"
),
]
)
41 changes: 3 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,9 @@
<br />
</p>

# Amplitude-{LanguageName}
# Amplitude-Swift

This is Amplitude's latest version of the {LanguageName} SDK.
This is Amplitude's latest version of the Swift SDK.

## Need Help?
If you have any issues using our SDK, feel free to [create a GitHub issue](https://github.com/amplitude/Amplitude-SDK-Template/issues/new) or submit a request on [Amplitude Help](https://help.amplitude.com/hc/en-us/requests/new).


# Template Usage

## Creating a new repository
- Go to [create a new repo page](https://github.com/organizations/amplitude/repositories/new)
- Name your repository as Amplitude-{language} (example: Amplitude-TypeScript)
- Provide a description like “{Language} Amplitude Analytics SDK”
- Specify Internal as the type of repository. We will make it Public later
- Add a README.md file
- Use the suggested .gitignore template for the language you are using

## Securing the repository
- Go to the Settings page in your repository
- Go to Branches
- Add a branch protection rule called “main” for the main branch
- Check “Require a pull request before merging”
- Check “Require approvals”
- Check “Dismiss stale pull request approvals when new commits are pushed”
- If there are any status checks, check “Require status checks to pass before merging”

## Adding team members
- Go to Settings page in your repository
- Go to Collaborators and teams
- In Manage Access section, click on Add teams
- Search by the name of the team, and click Add teams

## Applying templates
- Clone the new repository
- Create a branch (You do not have to preface the branch name with the JIRA ticket number)
- Create .github/pull_request_template.md using this template
- Create a .github/ISSUE_TEMPLATE folder with the following files
- Add a LICENSE file
- Edit the README.md as necessary
- Create a PR with these files and have someone review (This makes sure we have the proper branch protection rules)
If you have any issues using our SDK, feel free to [create a GitHub issue](https://github.com/amplitude/Amplitude-Swift/issues/new) or submit a request on [Amplitude Help](https://help.amplitude.com/hc/en-us/requests/new).
51 changes: 30 additions & 21 deletions Sources/Amplitude/Amplitude.swift
Original file line number Diff line number Diff line change
@@ -1,72 +1,81 @@
public class Amplitude {
var configuration: Configuration
var instanceName: String
init(configuration: Configuration, instanceName: String = "default") {
init(
configuration: Configuration,
instanceName: String = Constants.Configuration.DEFAULT_INSTANCE
) {
self.configuration = configuration
self.instanceName = instanceName
}


convenience init(apiKey: String, configuration: Configuration) {
configuration.apiKey = apiKey
self.init(configuration: configuration)
}

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 {

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")
}
46 changes: 33 additions & 13 deletions Sources/Amplitude/Configuration.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
//
// 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 apiKey: String
var flushQueueSize: Int
var flushIntervalMillis: Int
var instanceName: String
var optOut: Bool
var storageProvider: Storage
var logLvel: LogLevelEnum
var loggerProvider: any Logger
var minIdLength: Int?
var partnerId: String?
var callback: EventCallBack?
var flushMaxRetries: Int = 5
var useBatch: Bool = false
var serverZone: ServerZone = ServerZone.US
var flushMaxRetries: Int
var useBatch: Bool
var serverZone: ServerZone
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) {

init(
apiKey: String,
flushQueueSize: Int = Constants.Configuration.FLUSH_QUEUE_SIZE,
flushIntervalMillis: Int = Constants.Configuration.FLUSH_INTERVAL_MILLIS,
instanceName: String = Constants.Configuration.DEFAULT_INSTANCE,
optOut: Bool = false,
storageProvider: Storage = PersistentStorage(),
logLvel: LogLevelEnum = LogLevelEnum.WARN,
loggerProvider: any Logger = ConsoleLogger(),
minIdLength: Int? = nil,
partnerId: String? = nil,
callback: EventCallBack? = nil,
flushMaxRetries: Int = Constants.Configuration.FLUSH_MAX_RETRIES,
useBatch: Bool = false,
serverZone: ServerZone = ServerZone.US,
serverUrl: String = Constants.DEFAULT_API_HOST,
plan: Plan? = nil,
ingestionMetadata: IngestionMetadata? = nil
) {
self.apiKey = apiKey
self.flushQueueSize = flushQueueSize
self.flushIntervalMillis = flushIntervalMillis
self.instanceName = instanceName
Expand Down
34 changes: 21 additions & 13 deletions Sources/Amplitude/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
//
//
// Created by Marvin Liu on 10/27/22.
//
Expand All @@ -16,19 +16,27 @@ enum LogLevelEnum: Int {
}

enum ServerZone: String {
case US = "US"
case EU = "EU"
case US
case 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
static let SDK_LIBRARY = "amplitude-swift"
static let DEFAULT_API_HOST = "https://api2.amplitude.com/2/httpapi"
static let EU_DEFAULT_API_HOST = "https://api.eu.amplitude.com/2/httpapi"
static let BATCH_API_HOST = "https://api2.amplitude.com/batch"
static let EU_BATCH_API_HOST = "https://api.eu.amplitude.com/batch"
static let IDENTIFY_EVENT = "$identify"
static let GROUP_IDENTIFY_EVENT = "$groupidentify"
static let AMP_REVENUE_EVENT = "revenue_amount"
static let MAX_PROPERTY_KEYS = 1024
static let MAX_STRING_LENGTH = 1024

struct Configuration {
static let FLUSH_QUEUE_SIZE = 30
static let FLUSH_INTERVAL_MILLIS = 30 * 1000 // 30s
static let DEFAULT_INSTANCE = "default_instance"
static let FLUSH_MAX_RETRIES = 5
static let MIN_TIME_BETWEEN_SESSIONS_MILLIS = 300000
}
}
17 changes: 7 additions & 10 deletions Sources/Amplitude/EventBridge.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
//
//
// Created by Marvin Liu on 10/27/22.
//
Expand All @@ -9,32 +9,29 @@ 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
var eventProperties: [String: Any]?
var userProperties: [String: Any]?
var groups: [String: Any]?
var groupProperties: [String: Any]?
}

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#>
}
}
Loading

0 comments on commit 8e1beb1

Please sign in to comment.