Given a Package.swift
like:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "foo",
products: [
.executable(name: "Foo", targets: ["Foo"]),
],
dependencies: [
// TODO: Add dependencies here...
],
targets: [
.target(
name: "Foo",
dependencies: [
// TODO: Add library names here...
]),
]
)
Replace // TODO: Add dependencies here...
with:
.package(url: "https://github.com/dayindustries/user-analytics-swift.git"),
And replace // TODO: Add library names here...
with:
"UserAnalytics"
Currently the test is a "smoke test" (hits an actual API over the network). The intent is to replace this with stubbed tests, time permitting.
export USER_ANALYTICS_TOKEN='XXXX'
export USER_ANALYTICS_ENDPOINT='https://some.host'
swift test
import UserAnalytics
let userAnalytics = UserAnalytics(token: token, endpoint: endpoint)
let data: Dictionary<String, Any> = [
"distinct_id": "1",
"time": UserAnalytics.toAthenaTimestamp(Date()),
"ip": "71.198.38.200",
"env": "prod",
"event": "Signed Up",
"subcategory": "",
"event_id": "",
"source": "someservice",
"client": "ios",
"os_version": "",
"app_version": ""
]
userAnalytics.post(streamName: "UserAnalytics", data: data) { data, error in
if error != nil || data == nil {
// TODO: Handle something going wrong...
}
let dictionary = try JSONSerialization.jsonObject(with: data!, options: [])
if dictionary == nil {
// TODO: Couldn't parse the dictionary...
}
// Do something with the string body...
print(dictionary)
}
- Add the "list streams" API action (not critical for general usage)
- Add the "describe stream" API action (not critical for general usage)
- Replace the live test with a stubbed one
- Add an additional script for live testing