Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rwbutler committed May 17, 2020
1 parent 70e6fb1 commit 05a75e1
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2020-05-17
### Added
- Increased unit test coverage to 90%.

## [0.2.0] - 2020-05-08
### Added
- Support for Carthage and Swift Package Manager.
Expand Down
6 changes: 5 additions & 1 deletion Example/Hyperconnectivity.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
13962F2024719F1700CCE8B9 /* string-contains-response.html in Resources */ = {isa = PBXBuildFile; fileRef = 13962F1B24719EDE00CCE8B9 /* string-contains-response.html */; };
13962F232471AA1600CCE8B9 /* ConnectivityPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13962F222471AA1600CCE8B9 /* ConnectivityPublisherTests.swift */; };
13962F252471B48700CCE8B9 /* failure-response.html in Resources */ = {isa = PBXBuildFile; fileRef = 13962F242471B48700CCE8B9 /* failure-response.html */; };
13C3D88F2471C36800E0A879 /* ReachabilityPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13C3D88E2471C36800E0A879 /* ReachabilityPublisherTests.swift */; };
13EDCA922465DDFB006FAE75 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13EDCA912465DDFB006FAE75 /* UIColor.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
Expand Down Expand Up @@ -55,6 +56,7 @@
13962F1D24719EF600CCE8B9 /* string-equality-response.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "string-equality-response.html"; sourceTree = "<group>"; };
13962F222471AA1600CCE8B9 /* ConnectivityPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectivityPublisherTests.swift; sourceTree = "<group>"; };
13962F242471B48700CCE8B9 /* failure-response.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "failure-response.html"; sourceTree = "<group>"; };
13C3D88E2471C36800E0A879 /* ReachabilityPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReachabilityPublisherTests.swift; sourceTree = "<group>"; };
13EDCA912465DDFB006FAE75 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
3CA628B2EBED9449AB582CF5 /* Pods-Hyperconnectivity_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Hyperconnectivity_Tests.release.xcconfig"; path = "Target Support Files/Pods-Hyperconnectivity_Tests/Pods-Hyperconnectivity_Tests.release.xcconfig"; sourceTree = "<group>"; };
5906C1669FAA2FD5D578F683 /* Pods_Hyperconnectivity_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Hyperconnectivity_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -172,13 +174,14 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
13962F212471A95F00CCE8B9 /* Response Validation Tests */,
13962F102471919F00CCE8B9 /* Mocks */,
13962F212471A95F00CCE8B9 /* Response Validation Tests */,
134B21BF2468779E00A8F332 /* ConnectionTests.swift */,
134B21BC2466DC7200A8F332 /* ConnectivityStateTests.swift */,
607FACEB1AFB9204008FA782 /* PercentageTests.swift */,
13962F09246F3F7300CCE8B9 /* ConnectivitySubscriptionTests.swift */,
13962F222471AA1600CCE8B9 /* ConnectivityPublisherTests.swift */,
13C3D88E2471C36800E0A879 /* ReachabilityPublisherTests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
path = Tests;
Expand Down Expand Up @@ -428,6 +431,7 @@
13962F0A246F3F7300CCE8B9 /* ConnectivitySubscriptionTests.swift in Sources */,
13962F1A247196F800CCE8B9 /* ResponseContainsStringValidatorTests.swift in Sources */,
13962F18247196AE00CCE8B9 /* ResponseStringEqualityValidatorTests.swift in Sources */,
13C3D88F2471C36800E0A879 /* ReachabilityPublisherTests.swift in Sources */,
13962F162471968300CCE8B9 /* ResponseRegExValidatorTests.swift in Sources */,
607FACEC1AFB9204008FA782 /* PercentageTests.swift in Sources */,
134B21C1246877F300A8F332 /* ConnectionTests.swift in Sources */,
Expand Down
40 changes: 17 additions & 23 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Tests/ConnectivityPublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import XCTest
@testable import Hyperconnectivity

class ConnectivityPublisherTests: XCTestCase {

private var cancellable: AnyCancellable?
private let timeout: TimeInterval = 5.0

override func tearDown() {
super.tearDown()
Expand All @@ -38,7 +38,7 @@ class ConnectivityPublisherTests: XCTestCase {
XCTAssertEqual(result.state, .wifiWithInternet)
expectation.fulfill()
})
wait(for: [expectation], timeout: 2.0)
wait(for: [expectation], timeout: timeout)
}

func testSubscriberInvokedOnFailedConnectivityCheck() throws {
Expand All @@ -51,6 +51,6 @@ class ConnectivityPublisherTests: XCTestCase {
XCTAssertEqual(result.state, .wifiWithoutInternet)
expectation.fulfill()
})
wait(for: [expectation], timeout: 2.0)
wait(for: [expectation], timeout: timeout)
}
}
1 change: 0 additions & 1 deletion Example/Tests/ConnectivitySubscriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import XCTest
@testable import Hyperconnectivity

class ConnectivitySubscriptionTests: XCTestCase {

private let timeout: TimeInterval = 5.0

private func sut(subscriber: Subscribers.Sink<ConnectivityResult, Never>? = nil, connectivity: Connectivity? = nil) -> ConnectivitySubscription<Subscribers.Sink<ConnectivityResult, Never>> {
Expand Down
29 changes: 29 additions & 0 deletions Example/Tests/ReachabilityPublisherTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ReachabilityPublisherTests.swift
// Hyperconnectivity
//
// Created by Ross Butler on 17/05/2020.
// Copyright © 2020 Ross Butler. All rights reserved.
//

import Combine
import Foundation
import OHHTTPStubs
import XCTest
@testable import Hyperconnectivity

class ReachabilityPublisherTests: XCTestCase {
private var cancellable: AnyCancellable?
private let timeout: TimeInterval = 5.0

func testSubscriberInvokedOnSuccessfulReachabilityCheck() throws {
let expectation = XCTestExpectation(description: "Reachability check succeeds")
cancellable = Publishers.Reachability().sink(receiveCompletion: { _ in
}, receiveValue: { result in
XCTAssertEqual(result.connection, .wifi)
XCTAssertTrue(result.isReachable)
expectation.fulfill()
})
wait(for: [expectation], timeout: timeout)
}
}
2 changes: 1 addition & 1 deletion Hyperconnectivity.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Hyperconnectivity'
s.version = '0.2.0'
s.version = '1.0.0'
s.swift_version = '5.0'
s.summary = 'Modern replacement for Apple\'s Reachability written in Swift and made elegant using Combine'
s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct ReachabilityPublisher: Publisher {
private let configuration: Configuration

public init(configuration: Configuration = Configuration()) {
self.configuration = configuration
self.configuration = configuration.cloneForReachability()
}

public func receive<S>(subscriber: S) where S : Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReachabilitySubscription<S: Subscriber>: Subscription where S.Input == Rea
private var subscriber: S?

init(configuration: Hyperconnectivity.Configuration, subscriber: S) {
self.configuration = configuration
self.configuration = configuration.cloneForReachability()
self.subscriber = subscriber
startNotifier(with: subscriber)
}
Expand All @@ -40,6 +40,7 @@ private extension ReachabilitySubscription {
private func stopNotifier() {
connectivity?.stopNotifier()
connectivity = nil
subscriber?.receive(completion: Subscribers.Completion<Never>.finished)
subscriber = nil
}
}
Expand Down
27 changes: 20 additions & 7 deletions Hyperconnectivity/Classes/Model/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import Foundation

public struct HyperconnectivityConfiguration {
public static let defaultConnectivityURLs = [
URL(string: "https://www.apple.com/library/test/success.html")!,
URL(string: "https://captive.apple.com/hotspot-detect.html")!
]
URL(string: "https://www.apple.com/library/test/success.html"),
URL(string: "https://captive.apple.com/hotspot-detect.html")
]
.compactMap { $0 }
public static let defaultURLSessionConfiguration: URLSessionConfiguration = {
let sessionConfiguration = URLSessionConfiguration.default
sessionConfiguration.requestCachePolicy = .reloadIgnoringCacheData
Expand All @@ -33,22 +34,34 @@ public struct HyperconnectivityConfiguration {
public init(callbackQueue: DispatchQueue = DispatchQueue.main,
connectivityQueue: DispatchQueue = DispatchQueue.global(qos: .utility),
connectivityURLs: [URL] = Self.defaultConnectivityURLs,
responseValidator: ResponseValidator = ResponseStringValidator(
validationMode: .containsExpectedResponseString
),
responseValidator: ResponseValidator? = nil,
shouldCheckConnectivity: Bool = true,
successThreshold: Percentage = Percentage(50.0),
urlSessionConfiguration: URLSessionConfiguration = Self.defaultURLSessionConfiguration
) {
let defaultValidator = ResponseStringValidator(
validationMode: .containsExpectedResponseString
)
self.callbackQueue = callbackQueue
self.connectivityQueue = connectivityQueue
self.connectivityURLs = connectivityURLs
self.responseValidator = responseValidator
self.responseValidator = responseValidator ?? defaultValidator
self.shouldCheckConnectivity = shouldCheckConnectivity
self.successThreshold = successThreshold
self.urlSessionConfiguration = urlSessionConfiguration
}

func cloneForReachability() -> Self {
return HyperconnectivityConfiguration(
callbackQueue: callbackQueue,
connectivityQueue: connectivityQueue,
connectivityURLs: [],
responseValidator: responseValidator,
shouldCheckConnectivity: false,
successThreshold: Percentage(0.0),
urlSessionConfiguration: urlSessionConfiguration)
}

/// Convenience method for determining whether or not the response is valid.
func isResponseValid(_ response: (Data, URLResponse)) -> Bool {
responseValidator.isResponseValid(response.1, data: response.0)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
[![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://swift.org/)
[![Twitter](https://img.shields.io/badge/twitter-@ross_w_butler-blue.svg?style=flat)](https://twitter.com/ross_w_butler)

⚠️ _Note that this framework is a work in progress until reaching version 1.0._

Hyperconnectivity is a modern replacement for Reachability written fully in Swift and using Apple's [Combine](https://developer.apple.com/documentation/combine) framework. It offers the ability to detect reachability, Internet connectivity as well the presence of [captive portals](https://en.wikipedia.org/wiki/Captive_portal). It is an offshoot of the [Connectivity](https://github.com/rwbutler/Connectivity) project which offers similar features. To find out which one is right for you, take a look at the [Connectivity vs Hyperconnectivity](#connectivity-vs-hyperconnectivity) section below for a comparison.

- [Features](#features)
Expand Down

0 comments on commit 05a75e1

Please sign in to comment.