Skip to content

Commit 05a75e1

Browse files
committed
Release 1.0.0
1 parent 70e6fb1 commit 05a75e1

File tree

12 files changed

+102
-60
lines changed

12 files changed

+102
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.0.0] - 2020-05-17
8+
### Added
9+
- Increased unit test coverage to 90%.
10+
711
## [0.2.0] - 2020-05-08
812
### Added
913
- Support for Carthage and Swift Package Manager.

Example/Hyperconnectivity.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
13962F2024719F1700CCE8B9 /* string-contains-response.html in Resources */ = {isa = PBXBuildFile; fileRef = 13962F1B24719EDE00CCE8B9 /* string-contains-response.html */; };
2323
13962F232471AA1600CCE8B9 /* ConnectivityPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13962F222471AA1600CCE8B9 /* ConnectivityPublisherTests.swift */; };
2424
13962F252471B48700CCE8B9 /* failure-response.html in Resources */ = {isa = PBXBuildFile; fileRef = 13962F242471B48700CCE8B9 /* failure-response.html */; };
25+
13C3D88F2471C36800E0A879 /* ReachabilityPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13C3D88E2471C36800E0A879 /* ReachabilityPublisherTests.swift */; };
2526
13EDCA922465DDFB006FAE75 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13EDCA912465DDFB006FAE75 /* UIColor.swift */; };
2627
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
2728
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
@@ -55,6 +56,7 @@
5556
13962F1D24719EF600CCE8B9 /* string-equality-response.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "string-equality-response.html"; sourceTree = "<group>"; };
5657
13962F222471AA1600CCE8B9 /* ConnectivityPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectivityPublisherTests.swift; sourceTree = "<group>"; };
5758
13962F242471B48700CCE8B9 /* failure-response.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "failure-response.html"; sourceTree = "<group>"; };
59+
13C3D88E2471C36800E0A879 /* ReachabilityPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReachabilityPublisherTests.swift; sourceTree = "<group>"; };
5860
13EDCA912465DDFB006FAE75 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
5961
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>"; };
6062
5906C1669FAA2FD5D578F683 /* Pods_Hyperconnectivity_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Hyperconnectivity_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -172,13 +174,14 @@
172174
607FACE81AFB9204008FA782 /* Tests */ = {
173175
isa = PBXGroup;
174176
children = (
175-
13962F212471A95F00CCE8B9 /* Response Validation Tests */,
176177
13962F102471919F00CCE8B9 /* Mocks */,
178+
13962F212471A95F00CCE8B9 /* Response Validation Tests */,
177179
134B21BF2468779E00A8F332 /* ConnectionTests.swift */,
178180
134B21BC2466DC7200A8F332 /* ConnectivityStateTests.swift */,
179181
607FACEB1AFB9204008FA782 /* PercentageTests.swift */,
180182
13962F09246F3F7300CCE8B9 /* ConnectivitySubscriptionTests.swift */,
181183
13962F222471AA1600CCE8B9 /* ConnectivityPublisherTests.swift */,
184+
13C3D88E2471C36800E0A879 /* ReachabilityPublisherTests.swift */,
182185
607FACE91AFB9204008FA782 /* Supporting Files */,
183186
);
184187
path = Tests;
@@ -428,6 +431,7 @@
428431
13962F0A246F3F7300CCE8B9 /* ConnectivitySubscriptionTests.swift in Sources */,
429432
13962F1A247196F800CCE8B9 /* ResponseContainsStringValidatorTests.swift in Sources */,
430433
13962F18247196AE00CCE8B9 /* ResponseStringEqualityValidatorTests.swift in Sources */,
434+
13C3D88F2471C36800E0A879 /* ReachabilityPublisherTests.swift in Sources */,
431435
13962F162471968300CCE8B9 /* ResponseRegExValidatorTests.swift in Sources */,
432436
607FACEC1AFB9204008FA782 /* PercentageTests.swift in Sources */,
433437
134B21C1246877F300A8F332 /* ConnectionTests.swift in Sources */,

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 17 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Hyperconnectivity/Hyperconnectivity-Info.plist

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Tests/ConnectivityPublisherTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import XCTest
1313
@testable import Hyperconnectivity
1414

1515
class ConnectivityPublisherTests: XCTestCase {
16-
1716
private var cancellable: AnyCancellable?
17+
private let timeout: TimeInterval = 5.0
1818

1919
override func tearDown() {
2020
super.tearDown()
@@ -38,7 +38,7 @@ class ConnectivityPublisherTests: XCTestCase {
3838
XCTAssertEqual(result.state, .wifiWithInternet)
3939
expectation.fulfill()
4040
})
41-
wait(for: [expectation], timeout: 2.0)
41+
wait(for: [expectation], timeout: timeout)
4242
}
4343

4444
func testSubscriberInvokedOnFailedConnectivityCheck() throws {
@@ -51,6 +51,6 @@ class ConnectivityPublisherTests: XCTestCase {
5151
XCTAssertEqual(result.state, .wifiWithoutInternet)
5252
expectation.fulfill()
5353
})
54-
wait(for: [expectation], timeout: 2.0)
54+
wait(for: [expectation], timeout: timeout)
5555
}
5656
}

Example/Tests/ConnectivitySubscriptionTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import XCTest
1313
@testable import Hyperconnectivity
1414

1515
class ConnectivitySubscriptionTests: XCTestCase {
16-
1716
private let timeout: TimeInterval = 5.0
1817

1918
private func sut(subscriber: Subscribers.Sink<ConnectivityResult, Never>? = nil, connectivity: Connectivity? = nil) -> ConnectivitySubscription<Subscribers.Sink<ConnectivityResult, Never>> {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// ReachabilityPublisherTests.swift
3+
// Hyperconnectivity
4+
//
5+
// Created by Ross Butler on 17/05/2020.
6+
// Copyright © 2020 Ross Butler. All rights reserved.
7+
//
8+
9+
import Combine
10+
import Foundation
11+
import OHHTTPStubs
12+
import XCTest
13+
@testable import Hyperconnectivity
14+
15+
class ReachabilityPublisherTests: XCTestCase {
16+
private var cancellable: AnyCancellable?
17+
private let timeout: TimeInterval = 5.0
18+
19+
func testSubscriberInvokedOnSuccessfulReachabilityCheck() throws {
20+
let expectation = XCTestExpectation(description: "Reachability check succeeds")
21+
cancellable = Publishers.Reachability().sink(receiveCompletion: { _ in
22+
}, receiveValue: { result in
23+
XCTAssertEqual(result.connection, .wifi)
24+
XCTAssertTrue(result.isReachable)
25+
expectation.fulfill()
26+
})
27+
wait(for: [expectation], timeout: timeout)
28+
}
29+
}

Hyperconnectivity.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Hyperconnectivity'
3-
s.version = '0.2.0'
3+
s.version = '1.0.0'
44
s.swift_version = '5.0'
55
s.summary = 'Modern replacement for Apple\'s Reachability written in Swift and made elegant using Combine'
66
s.description = <<-DESC

Hyperconnectivity/Classes/Combine/ReachabilityPublisher.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public struct ReachabilityPublisher: Publisher {
1919
private let configuration: Configuration
2020

2121
public init(configuration: Configuration = Configuration()) {
22-
self.configuration = configuration
22+
self.configuration = configuration.cloneForReachability()
2323
}
2424

2525
public func receive<S>(subscriber: S) where S : Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {

Hyperconnectivity/Classes/Combine/ReachabilitySubscription.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ReachabilitySubscription<S: Subscriber>: Subscription where S.Input == Rea
1414
private var subscriber: S?
1515

1616
init(configuration: Hyperconnectivity.Configuration, subscriber: S) {
17-
self.configuration = configuration
17+
self.configuration = configuration.cloneForReachability()
1818
self.subscriber = subscriber
1919
startNotifier(with: subscriber)
2020
}
@@ -40,6 +40,7 @@ private extension ReachabilitySubscription {
4040
private func stopNotifier() {
4141
connectivity?.stopNotifier()
4242
connectivity = nil
43+
subscriber?.receive(completion: Subscribers.Completion<Never>.finished)
4344
subscriber = nil
4445
}
4546
}

Hyperconnectivity/Classes/Model/Configuration.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import Foundation
99

1010
public struct HyperconnectivityConfiguration {
1111
public static let defaultConnectivityURLs = [
12-
URL(string: "https://www.apple.com/library/test/success.html")!,
13-
URL(string: "https://captive.apple.com/hotspot-detect.html")!
14-
]
12+
URL(string: "https://www.apple.com/library/test/success.html"),
13+
URL(string: "https://captive.apple.com/hotspot-detect.html")
14+
]
15+
.compactMap { $0 }
1516
public static let defaultURLSessionConfiguration: URLSessionConfiguration = {
1617
let sessionConfiguration = URLSessionConfiguration.default
1718
sessionConfiguration.requestCachePolicy = .reloadIgnoringCacheData
@@ -33,22 +34,34 @@ public struct HyperconnectivityConfiguration {
3334
public init(callbackQueue: DispatchQueue = DispatchQueue.main,
3435
connectivityQueue: DispatchQueue = DispatchQueue.global(qos: .utility),
3536
connectivityURLs: [URL] = Self.defaultConnectivityURLs,
36-
responseValidator: ResponseValidator = ResponseStringValidator(
37-
validationMode: .containsExpectedResponseString
38-
),
37+
responseValidator: ResponseValidator? = nil,
3938
shouldCheckConnectivity: Bool = true,
4039
successThreshold: Percentage = Percentage(50.0),
4140
urlSessionConfiguration: URLSessionConfiguration = Self.defaultURLSessionConfiguration
4241
) {
42+
let defaultValidator = ResponseStringValidator(
43+
validationMode: .containsExpectedResponseString
44+
)
4345
self.callbackQueue = callbackQueue
4446
self.connectivityQueue = connectivityQueue
4547
self.connectivityURLs = connectivityURLs
46-
self.responseValidator = responseValidator
48+
self.responseValidator = responseValidator ?? defaultValidator
4749
self.shouldCheckConnectivity = shouldCheckConnectivity
4850
self.successThreshold = successThreshold
4951
self.urlSessionConfiguration = urlSessionConfiguration
5052
}
5153

54+
func cloneForReachability() -> Self {
55+
return HyperconnectivityConfiguration(
56+
callbackQueue: callbackQueue,
57+
connectivityQueue: connectivityQueue,
58+
connectivityURLs: [],
59+
responseValidator: responseValidator,
60+
shouldCheckConnectivity: false,
61+
successThreshold: Percentage(0.0),
62+
urlSessionConfiguration: urlSessionConfiguration)
63+
}
64+
5265
/// Convenience method for determining whether or not the response is valid.
5366
func isResponseValid(_ response: (Data, URLResponse)) -> Bool {
5467
responseValidator.isResponseValid(response.1, data: response.0)

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
[![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://swift.org/)
88
[![Twitter](https://img.shields.io/badge/twitter-@ross_w_butler-blue.svg?style=flat)](https://twitter.com/ross_w_butler)
99

10-
⚠️ _Note that this framework is a work in progress until reaching version 1.0._
11-
1210
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.
1311

1412
- [Features](#features)

0 commit comments

Comments
 (0)