Skip to content

Commit

Permalink
adding documentation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed May 10, 2024
1 parent 2c8d4fa commit 8ad9a53
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
24 changes: 23 additions & 1 deletion Sources/AviaryInsights/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,37 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

/// Represents an event in Plausible, such as a pageview or a custom event.
public struct Event: Sendable {
/// Default name for a pageview event.
public static let pageview = "pageview"

/// Name of the event.
public let name: String

/// Domain name of the site in Plausible.
public let domain: String?

/// URL of the page where the event was triggered.
public let url: String

/// Referrer for this event.
public let referrer: String?
public let props: [String: (any Sendable)?]?

/// Custom properties for the event.
public let props: [String: any Sendable]?

/// Revenue data for this event.
public let revenue: Revenue?

/// Initializes an event.
/// - Parameters:
/// - url: URL of the page where the event was triggered.
/// - name: Name of the event. Defaults to `pageview`.
/// - domain: Domain name of the site in Plausible. Defaults to `nil`.
/// - referrer: Referrer for this event. Defaults to `nil`.
/// - props: Custom properties for the event. Defaults to `nil`.
/// - revenue: Revenue data for this event. Defaults to `nil`.
public init(
url: String,
name: String = Self.pageview,
Expand Down
23 changes: 22 additions & 1 deletion Sources/AviaryInsights/Plausible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@ import OpenAPIURLSession
import FoundationNetworking
#endif

/// Represents an interface to interact with the Plausible API.
public struct Plausible: Sendable {
// swiftlint:disable:next force_try
// swiftlint:disable force_try
/// Default server URL for the Plausible API.
public static let defaultServerURL = try! Servers.server1()
// swiftlint:enable force_try

private let client: Client
/// Default domain associated with the Plausible instance.
public let defaultDomain: String

private init(client: Client, defaultDomain: String) {
self.client = client
self.defaultDomain = defaultDomain
}

/// Initializes a Plausible instance.
/// - Parameters:
/// - transport: Client transport for sending requests.
/// - defaultDomain: Default domain associated with the Plausible instance.
/// - serverURL: Server URL for the Plausible API. Defaults to `defaultServerURL`.
public init(
transport: any ClientTransport,
defaultDomain: String,
Expand All @@ -56,6 +65,11 @@ public struct Plausible: Sendable {
self.init(client: client, defaultDomain: defaultDomain)
}

/// Initializes a Plausible instance.
/// - Parameters:
/// - defaultDomain: Default domain associated with the Plausible instance.
/// - serverURL: Server URL for the Plausible API. Defaults to `defaultServerURL`.
/// - configuration: Configuration for URLSessionTransport. Defaults to `nil`.
public init(
defaultDomain: String,
serverURL: URL = Self.defaultServerURL,
Expand All @@ -73,6 +87,11 @@ public struct Plausible: Sendable {
)

Check warning on line 87 in Sources/AviaryInsights/Plausible.swift

View check run for this annotation

Codecov / codecov/patch

Sources/AviaryInsights/Plausible.swift#L83-L87

Added lines #L83 - L87 were not covered by tests
}

/// Initializes a Plausible instance with a custom URLSession.
/// - Parameters:
/// - session: URLSession to use for making requests.
/// - defaultDomain: Default domain associated with the Plausible instance.
/// - serverURL: Server URL for the Plausible API. Defaults to `defaultServerURL`.
public init(
session: URLSession,
defaultDomain: String,
Expand All @@ -85,6 +104,8 @@ public struct Plausible: Sendable {
)

Check warning on line 104 in Sources/AviaryInsights/Plausible.swift

View check run for this annotation

Codecov / codecov/patch

Sources/AviaryInsights/Plausible.swift#L99-L104

Added lines #L99 - L104 were not covered by tests
}

/// Sends an event to the Plausible API.
/// - Parameter event: Event to be sent.
public func postEvent(_ event: Event) async throws {
_ = try await client.post_sol_event(
body: .init(event: event, defaultDomain: defaultDomain)
Expand Down
8 changes: 8 additions & 0 deletions Sources/AviaryInsights/Revenue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

/// Represents revenue data for an event in Plausible.
public struct Revenue: Sendable {
/// Currency code for the revenue amount.
public let currency: String

/// Amount of revenue.
public let amount: Double

/// Initializes revenue data for an event.
/// - Parameters:
/// - currency: Currency code for the revenue amount.
/// - amount: Amount of revenue.
public init(currency: String, amount: Double) {
self.currency = currency
self.amount = amount
Expand Down

0 comments on commit 8ad9a53

Please sign in to comment.