Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
enum DashboardDynamicCardAnalyticsEvent: Hashable {
public enum DashboardDynamicCardAnalyticsEvent: Hashable {

case cardShown(id: String)
case cardTapped(id: String, url: String?)
case cardCtaTapped(id: String, url: String?)

var name: String {
public var name: String {
switch self {
case .cardShown: return "dynamic_dashboard_card_shown"
case .cardTapped: return "dynamic_dashboard_card_tapped"
case .cardCtaTapped: return "dynamic_dashboard_card_cta_tapped"
}
}

var properties: [String: String] {
public var properties: [String: String] {
switch self {
case .cardShown(let id):
return [Keys.id: id]
Expand Down
27 changes: 27 additions & 0 deletions Modules/Sources/WordPressShared/Utility/IncrementalDelay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation

/// Provides a sequence of incremental delays, repeating the last one
/// indefinitely.
///
public struct IncrementalDelay<Element> {
public var current: Element

private let delaySequence: AnySequence<Element>
private var iterator: AnyIterator<Element>

public init(_ sequence: [Element]) {
precondition(!sequence.isEmpty, "IncrementalDelay sequence can't be empty")
delaySequence = sequence.repeatingLast()
iterator = delaySequence.makeIterator()
current = iterator.next()!
}

public mutating func increment() {
current = iterator.next()!
}

public mutating func reset() {
iterator = delaySequence.makeIterator()
current = iterator.next()!
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

struct LoggingURLRedactor {
public struct LoggingURLRedactor {

static func redactedURL(_ url: URL) -> URL {
public static func redactedURL(_ url: URL) -> URL {

if isAuthURL(url) {
return redactParameter(named: "token", in: url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Int {
/// - Precondition: divisor must be > 0
/// - returns: an Int rounded to the nearest integer that's a multiple of the argument.
///
func round(_ divisor: UInt) -> Int {
public func round(_ divisor: UInt) -> Int {
assert(divisor > 0)
if self == 0 || divisor == 0 {
return self
Expand All @@ -30,39 +30,39 @@ extension Comparable {
/// - max if self > max
/// - otherwise it returns self
///
func clamp(min minValue: Self, max maxValue: Self) -> Self {
public func clamp(min minValue: Self, max maxValue: Self) -> Self {
return Swift.min(Swift.max(self, minValue), maxValue)
}
}

extension CGSize {
func clamp(min minValue: CGSize, max maxValue: CGSize) -> CGSize {
public func clamp(min minValue: CGSize, max maxValue: CGSize) -> CGSize {
let width = self.width.clamp(min: minValue.width, max: maxValue.width)
let height = self.height.clamp(min: minValue.height, max: maxValue.height)
return CGSize(width: width, height: height)
}

func clamp(min minValue: CGFloat, max maxValue: CGFloat) -> CGSize {
public func clamp(min minValue: CGFloat, max maxValue: CGFloat) -> CGSize {
let minSize = CGSize(width: minValue, height: minValue)
let maxSize = CGSize(width: maxValue, height: maxValue)
return clamp(min: minSize, max: maxSize)
}

func clamp(min minValue: Int, max maxValue: Int) -> CGSize {
public func clamp(min minValue: Int, max maxValue: Int) -> CGSize {
return clamp(min: CGFloat(minValue), max: CGFloat(maxValue))
}

func scaled(by scale: CGFloat) -> CGSize {
public func scaled(by scale: CGFloat) -> CGSize {
CGSize(width: width * scale, height: height * scale)
}

func rounded() -> CGSize {
public func rounded() -> CGSize {
CGSize(width: width.rounded(), height: height.rounded())
}
}

extension CGFloat {
func zeroIfNaN() -> CGFloat {
public func zeroIfNaN() -> CGFloat {
return self.isNaN ? 0.0 : self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension NotificationCenter {
///
@discardableResult
@objc
func observeOnce(forName name: NSNotification.Name?, object: Any?, queue: OperationQueue?, using block: @escaping (Foundation.Notification) -> Swift.Void, filter: ((Foundation.Notification) -> Bool)? = nil) -> NSObjectProtocol {
public func observeOnce(forName name: NSNotification.Name?, object: Any?, queue: OperationQueue?, using block: @escaping (Foundation.Notification) -> Swift.Void, filter: ((Foundation.Notification) -> Bool)? = nil) -> NSObjectProtocol {
let oneTimeObserver = OneTimeObserver(action: block)

let observer = NotificationCenter.default.addObserver(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import Foundation

struct QRLoginToken: Equatable {
let token: String
let data: String
public struct QRLoginToken: Equatable {
public let token: String
public let data: String

static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.token == rhs.token && lhs.data == rhs.data
public init(token: String, data: String) {
self.token = token
self.data = data
}

public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.token == rhs.token && lhs.data == rhs.data
}
}

struct QRLoginURLParser {
public struct QRLoginURLParser {
private let urlString: String

init(urlString: String) {
public init(urlString: String) {
self.urlString = urlString
}

/// Attempts to retrieve the QR Login token information from the incoming urlString
/// - Returns: QRLoginToken or nil if the parsing fails for any reason
func parse() -> QRLoginToken? {
public func parse() -> QRLoginToken? {
// Early validation, making sure this is a valid URL from a valid host
guard let url = URL(string: urlString), Self.isValidHost(url: url) else {
return nil
Expand All @@ -39,7 +44,7 @@ struct QRLoginURLParser {
}

/// Validates that the input URL is coming from a valid host
static func isValidHost(url: URL) -> Bool {
public static func isValidHost(url: URL) -> Bool {
guard let host = url.host else {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import Foundation
public struct Queue<Element> {
private var elements = [Element]()

public init() {}

/// Push `element` onto the back of the queue
///
mutating func push(_ element: Element) {
public mutating func push(_ element: Element) {
elements.insert(element, at: elements.startIndex)
}

/// Remove and return the item at the front of the queue
///
mutating func pop() -> Element? {
return elements.popLast()
public mutating func pop() -> Element? {
elements.popLast()
}

/// Removes all elements; If `where` is given, only the elements matching the
/// predicate will be removed.
mutating func removeAll(where shouldBeRemoved: ((Element) -> Bool)? = nil) {
public mutating func removeAll(where shouldBeRemoved: ((Element) -> Bool)? = nil) {
if let shouldBeRemoved {
elements.removeAll(where: shouldBeRemoved)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Foundation
import WordPressShared

/// A struct that returns the Reader CSS URL
/// If you need to fix an issue in the CSS, see pbArwn-GU-p2
///
struct ReaderCSS {
public struct ReaderCSS {
private let store: KeyValueDatabase

private let now: Int
Expand All @@ -14,17 +13,17 @@ struct ReaderCSS {
private let expirationDays: Int = 5

private var expirationDaysInSeconds: Int {
return expirationDays * 60 * 60 * 24
expirationDays * 60 * 60 * 24
}

static let updatedKey = "ReaderCSSLastUpdated"

/// Returns a custom Reader CSS URL
/// This value can be changed under Settings > Debug
///
var customAddress: String? {
public var customAddress: String? {
get {
return store.object(forKey: "reader-css-url") as? String
store.object(forKey: "reader-css-url") as? String
}
set {
store.set(newValue, forKey: "reader-css-url")
Expand All @@ -34,19 +33,22 @@ struct ReaderCSS {
/// Returns the Reader CSS appending a timestamp
/// We force it to update based on the `expirationDays` property
///
var address: String {
public var address: String {
guard let lastUpdated = store.object(forKey: type(of: self).updatedKey) as? Int,
now - lastUpdated < expirationDaysInSeconds || !isInternetReachable() else {
now - lastUpdated < expirationDaysInSeconds || !isInternetReachable()
else {
saveCurrentDate()
return url(appendingTimestamp: now)
}

return url(appendingTimestamp: lastUpdated)
}

init(now: Int = Int(Date().timeIntervalSince1970),
store: KeyValueDatabase = UserPersistentStoreFactory.instance(),
isInternetReachable: @escaping () -> Bool = ReachabilityUtils.isInternetReachable) {
public init(
now: Int = Int(Date().timeIntervalSince1970),
store: KeyValueDatabase = UserPersistentStoreFactory.instance(),
isInternetReachable: @escaping () -> Bool = ReachabilityUtils.isInternetReachable
) {
self.store = store
self.now = now
self.isInternetReachable = isInternetReachable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Describes the header information presented to a user during individual steps of Site Creation.
/// This struct is best suited for cases where these values are static (i.e., not retrieved from the server).
///
public struct SiteCreationHeaderData {
public let title: String
public let subtitle: String

public init(title: String, subtitle: String) {
self.title = title
self.subtitle = subtitle
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
import WordPress
@testable import WordPressShared

class ArrayTests: XCTestCase {
func testRepeatLast() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testable import WordPress
@testable import WordPressShared
import XCTest

final class DashboardDynamicCardAnalyticsEventTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
import WordPress
@testable import WordPressShared

class DelayTests: XCTestCase {
func testIncrementalDelay() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import WordPress
@testable import WordPressShared

class LoggingURLRedactorTests: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import WordPress
@testable import WordPressShared

class MathTest: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation
import XCTest

@testable import WordPress

class MediaUploadHashTests: XCTestCase {

override func setUp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import WordPress
@testable import WordPressShared

private let counterKey = "counter"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import WordPress
@testable import WordPressShared

class QRLoginURLParserTests: XCTestCase {
/// Test to make sure isValidHost returns true when passed a valid URL host
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import WordPress
@testable import WordPressShared

class QueueTests: XCTestCase {
private var queue = Queue<Int>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import WordPressShared
import XCTest

@testable import WordPress
@testable import WordPressShared

class ReaderCSSTests: XCTestCase {
// MARK: - When online
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import WordPress
@testable import WordPressShared

final class SiteCreationHeaderDataTests: XCTestCase {
private struct Constants {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
import WordPress
import WordPressShared

class URLHelpersTests: XCTestCase {

Expand Down
28 changes: 0 additions & 28 deletions Tests/KeystoneTests/Tests/Extensions/DictionaryHelpersTests.swift

This file was deleted.

Loading