Skip to content

Commit

Permalink
Address all SwiftLint violations (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio authored Jan 30, 2025
2 parents 9ec7343 + e832cde commit a0a579c
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 221 deletions.
6 changes: 3 additions & 3 deletions Demo/ParselyDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import ParselyAnalytics

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

// This is unused but necessary in a Storyboard without UISceneDelegate setup.
// Without it, the app will show a black screen and log:
//
// > The app delegate must implement the window property if it wants to use a main storyboard file.
var window: UIWindow?

var parsely: Parsely!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.parsely = Parsely.sharedInstance
self.parsely.configure(siteId: "parsely-configured-default.com")

return true
}
}
8 changes: 4 additions & 4 deletions Demo/ParselyDemo/FirstViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import ParselyAnalytics

class FirstViewController: UIViewController {
let delegate = UIApplication.shared.delegate as! AppDelegate

@IBAction func didTouchButton(_ sender: Any) {
log("didTouchButton")
let demoMetas = ParselyMetadata(authors: ["Yogi Berr"])
delegate.parsely.trackPageView(url: "http://parsely.com/path/cool-blog-post/1?qsarg=nawp&anotherone=yup", metadata: demoMetas, extraData: ["product-id": "12345"], siteId: "subdomain.parsely-test.com")
}

@IBAction func didStartEngagement(_ sender: Any) {
log("didStartEngagement")
delegate.parsely.startEngagement(url: "http://parsely.com/very-not-real", urlref:"http://parsely.com/not-real", extraData: ["product-id": "12345"], siteId: "engaged.parsely-test.com")
delegate.parsely.startEngagement(url: "http://parsely.com/very-not-real", urlref: "http://parsely.com/not-real", extraData: ["product-id": "12345"], siteId: "engaged.parsely-test.com")
}

@IBAction func didStopEngagement(_ sender: Any) {
log("didStopEngagement")
delegate.parsely.stopEngagement()
Expand Down
12 changes: 6 additions & 6 deletions Sources/EngagedTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import Foundation
import os.log

class EngagedTime: Sampler {
override func sampleFn(key : String) -> Bool {
override func sampleFn(key: String) -> Bool {
guard let trackedData = accumulators[key] else {
os_log("No accumulator found for key %s. Skipping sampling.", log: OSLog.tracker, type: .debug, key)
return false
}

return trackedData.isEngaged
}

override func heartbeatFn(data: Accumulator, enableHeartbeats: Bool) {
if enableHeartbeats != true {
return
Expand All @@ -32,20 +32,20 @@ class EngagedTime: Sampler {

parselyTracker.track.event(event: event)
}

func startInteraction(url: String, urlref: String = "", extra_data: Dictionary<String, Any>?, idsite: String) {
endInteraction()
os_log("Starting Interaction", log: OSLog.tracker, type: .debug)
let eventArgs = generateEventArgs(url: url, urlref: urlref, extra_data: extra_data, idsite: idsite)
trackKey(key: url, contentDuration: nil, eventArgs: eventArgs, resetOnExisting: true);
trackKey(key: url, contentDuration: nil, eventArgs: eventArgs, resetOnExisting: true)
accumulators[url]!.isEngaged = true
}

func endInteraction() {
os_log("Ending Interaction", log: OSLog.tracker, type: .debug)
for (url, _) in accumulators {
guard var _ = accumulators[url] else {
os_log("No accumulator found for %s, skipping endInteraction", log: OSLog.tracker, type:.debug, url)
os_log("No accumulator found for %s, skipping endInteraction", log: OSLog.tracker, type: .debug, url)
return
}
accumulators[url]!.isEngaged = false
Expand Down
10 changes: 5 additions & 5 deletions Sources/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Event {
private(set) var last_session_timestamp: UInt64?
private(set) var parsely_site_uuid: String?
let rand: UInt64

init(_ action: String,
url: String,
urlref: String?,
Expand Down Expand Up @@ -58,21 +58,21 @@ class Event {
parsely_site_uuid = visitor
}

func toDict() -> Dictionary<String,Any> {
func toDict() -> Dictionary<String, Any> {
var params: Dictionary<String, Any> = [
"url": self.url,
"urlref": self.urlref,
"action": self.action,
"idsite": self.idsite,
]

var data: [String: Any] = extra_data
data["ts"] = self.rand

if let parsely_site_uuid {
data["parsely_site_uuid"] = parsely_site_uuid
}

params["data"] = data

if let metas = self.metadata {
Expand Down
14 changes: 7 additions & 7 deletions Sources/EventQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ extension Array {

struct EventQueue<T> {
var list = [T]()
mutating func push(_ element:T) {

mutating func push(_ element: T) {
os_log("Event pushed into queue", log: OSLog.tracker, type: .debug)
list.append(element)
}

mutating func push<Collection>(contentsOf elements:Collection) where T == Collection.Element, Collection: Sequence {
mutating func push<Collection>(contentsOf elements: Collection) where T == Collection.Element, Collection: Sequence {
os_log("Events pushed into queue", log: OSLog.tracker, type: .debug)
list.append(contentsOf: elements)
}

mutating func pop() -> T? {
if list.isEmpty {
return nil
}
os_log("Event popped from queue", log: OSLog.tracker, type: .debug)
return list.removeFirst()
}
mutating func get(count:Int = 0) -> [T] {

mutating func get(count: Int = 0) -> [T] {
if count == 0 {
os_log("Got %zd events from queue", log: OSLog.tracker, type: .debug, list.count)
return list.take(list.count)
}
os_log("Got %zd events from queue", log: OSLog.tracker, type: .debug, count)
return list.take(count)
}

func length() -> Int {
return list.count
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import os.log
class HttpClient {
static func sendRequest(request: ParselyRequest, queue: DispatchQueue, completion: ((Error?) -> Void)? = nil) {
os_log("Sending request to %s", log: OSLog.tracker, type: .debug, request.url)

guard let url = URL(string: request.url) else {
os_log("Failed to create URL from %s", log: OSLog.tracker, type: .error, request.url)
return
}

var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
urlRequest.httpBody = try? JSONSerialization.data(withJSONObject: request.params)
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")

request.headers.forEach { key, value in
urlRequest.setValue(value, forHTTPHeaderField: key)
}

URLSession.shared.dataTask(with: urlRequest) { _, _, error in
if let err = error {
os_log("Request failed: %s", log: OSLog.tracker, type: .error, err.localizedDescription)
Expand Down
28 changes: 14 additions & 14 deletions Sources/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class ParselyMetadata {
var section: String?
var tags: Array<String>?
var duration: TimeInterval?

/**
A class to manage and re-use metadata. Metadata contained in an instance of this
class will conform to Parsely's schema.

- Parameter canonical_url: A post's canonical url. For videos, it is overridden with the vId and thus can be omitted.
- Parameter pub_date: Date this piece of content was published.
- Parameter title: Title of the content.
Expand All @@ -22,15 +22,15 @@ public class ParselyMetadata {
- Parameter section: Same as section for website integration.
- Parameter tags: Up to 20 tags on an event are allowed.
- Parameter duration: Durations passed explicitly to trackVideoStart take precedence over any in metadata.
*/
*/
public init(canonical_url: String? = nil,
pub_date: Date? = nil,
title: String? = nil,
authors: Array<String>? = nil,
image_url: String? = nil,
section: String? = nil,
tags: Array<String>? = nil,
duration: TimeInterval? = nil) {
pub_date: Date? = nil,
title: String? = nil,
authors: Array<String>? = nil,
image_url: String? = nil,
section: String? = nil,
tags: Array<String>? = nil,
duration: TimeInterval? = nil) {
self.canonical_url = canonical_url
self.pub_date = pub_date
self.title = title
Expand All @@ -40,15 +40,15 @@ public class ParselyMetadata {
self.tags = tags
self.duration = duration
}

func toDict() -> Dictionary<String, Any> {
var metas: Dictionary<String, Any> = [:]

if let canonical_url {
metas["link"] = canonical_url
}
if let pub_date {
metas["pub_date"] = String(format:"%i", pub_date.millisecondsSince1970)
metas["pub_date"] = String(format: "%i", pub_date.millisecondsSince1970)
}
if let title {
metas["title"] = title
Expand All @@ -68,7 +68,7 @@ public class ParselyMetadata {
if let duration {
metas["duration"] = duration
}

return metas
}
}
Loading

0 comments on commit a0a579c

Please sign in to comment.