Skip to content

Commit

Permalink
✨ Add new endpoints for screen capture calls
Browse files Browse the repository at this point in the history
  • Loading branch information
iujames authored and mmaatttt committed Apr 11, 2023
1 parent 845d3d6 commit 2a9878e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
53 changes: 53 additions & 0 deletions Sources/AppcuesKit/Data/Networking/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,59 @@ internal enum APIEndpoint: Endpoint {
}
}

/// Mobile SDK configuration endpoints, providing links to other services.
internal enum SettingsEndpoint: Endpoint {
case settings

func url(config: Appcues.Config, storage: DataStoring) -> URL? {
guard var components = URLComponents(url: NetworkClient.sdkSettingsHost, resolvingAgainstBaseURL: false) else { return nil }

switch self {
case .settings:
components.path = "/bundle/accounts/\(config.accountID)/mobile/settings"
}

return components.url
}
}

/// Appcues Customer API endpoints.
internal enum CustomerAPIEndpoint: Endpoint {
case preSignedImageUpload(host: URL, filename: String)
case screenCapture(host: URL)

var host: URL {
switch self {
case let .preSignedImageUpload(host, _):
return host
case let .screenCapture(host):
return host
}
}

func url(config: Appcues.Config, storage: DataStoring) -> URL? {
guard var components = URLComponents(url: host, resolvingAgainstBaseURL: false) else { return nil }

switch self {
case let .preSignedImageUpload(_, filename):
components.path = "/v1/accounts/\(config.accountID)/mobile/\(config.applicationID)/pre-upload-screenshot"
components.query = "?name=\(filename)"
case .screenCapture:
components.path = "/v1/accounts/\(config.accountID)/mobile/\(config.applicationID)/screens"
}

return components.url
}
}

internal struct URLEndpoint: Endpoint {
let url: URL?

func url(config: Appcues.Config, storage: DataStoring) -> URL? {
return url
}
}

internal protocol Endpoint {
func url(config: Appcues.Config, storage: DataStoring) -> URL?
}
4 changes: 3 additions & 1 deletion Sources/AppcuesKit/Data/Networking/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ internal class NetworkClient: Networking {
}

extension NetworkClient {
// swiftlint:disable:next force_unwrapping
// swiftlint:disable force_unwrapping
static let defaultAPIHost = URL(string: "https://api.appcues.net")!
static let sdkSettingsHost = URL(string: "https://fast.appcues.com")!
// swiftlint:enable force_unwrapping

static var defaultURLSession: URLSession {
let configuration = URLSessionConfiguration.ephemeral
Expand Down

0 comments on commit 2a9878e

Please sign in to comment.