Skip to content

Commit

Permalink
Merge pull request #169 from bigMOTOR/feature/Alamofire-5_1
Browse files Browse the repository at this point in the history
Alamofire 5.1
  • Loading branch information
ashfurrow authored Apr 17, 2020
2 parents 64812f3 + 94a6ae8 commit 522138d
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 398 deletions.
13 changes: 5 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
XCODE_TEST_REPORTS: /tmp/xcode-test-results
LANG: en_US.UTF-8
macos:
xcode: '10.2.0'
xcode: '11.4'
steps:
- checkout
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS $XCODE_TEST_REPORTS
Expand All @@ -22,11 +22,8 @@ jobs:
- Carthage
key: RxAlamofire-Test-Carthage-Dependency
- run:
name: Run Tests (Swift 4.2)
command: set -o pipefail && xcodebuild test SWIFT_VERSION=4.2 -scheme 'RxAlamofire iOS' -project '_.xcodeproj' -sdk iphonesimulator -destination "name=iPhone X" | xcpretty -c -r html --output $XCODE_TEST_REPORTS/iOS_Swift42.html
- run:
name: Run Tests (Swift 5)
command: set -o pipefail && xcodebuild test SWIFT_VERSION=5.0 -scheme 'RxAlamofire iOS' -project '_.xcodeproj' -sdk iphonesimulator -destination "name=iPhone X" | xcpretty -c -r html --output $XCODE_TEST_REPORTS/iOS_Swift5.html
name: Run Tests (Swift 5.1)
command: set -o pipefail && xcodebuild test SWIFT_VERSION=5.1 -scheme 'RxAlamofire iOS' -project '_.xcodeproj' -sdk iphonesimulator -destination "platform=iOS simulator,OS=13.4,name=iPhone 11" | xcpretty -c -r html --output $XCODE_TEST_REPORTS/iOS_Swift51.html
- run:
name: Swift Package Build
command: swift build
Expand All @@ -39,7 +36,7 @@ jobs:
environment:
LANG: en_US.UTF-8
macos:
xcode: '10.2.0'
xcode: '11.4'
steps:
- checkout
- run:
Expand All @@ -66,4 +63,4 @@ workflows:
branches:
ignore: /.*/
tags:
only: /[0-9]+(\.[0-9]+)*/
only: /[0-9]+(\.[0-9]+)*/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ All notable changes to this project will be documented in this file.

* Nothing yet!

## 5.2.0

#### Updated
* Uses Alamafire 5.1.0
* Uses RxSwift 5.1.0
* Upgrade project to Swift 5.1

## 5.1.0

#### Updated
Expand Down
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "ReactiveX/RxSwift" ~> 5.0
github "Alamofire/Alamofire" ~> 4.8
github "ReactiveX/RxSwift" ~> 5.1
github "Alamofire/Alamofire" ~> 5.1
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "RxAlamofire",
platforms: [
.macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v3)
.macOS(.v10_12), .iOS(.v10), .tvOS(.v10), .watchOS(.v3)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand All @@ -17,8 +17,8 @@ let package = Package(

dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "4.8.2")),
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "5.0.1" ),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.1.0")),
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "5.1.0" ),
],

targets: [
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pod 'RxAlamofire'
Add following to `Cartfile`:

```
github "RxSwiftCommunity/RxAlamofire" ~> 5.0
github "RxSwiftCommunity/RxAlamofire" ~> 5.2
```

### Swift Package manager
Expand All @@ -189,7 +189,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/RxSwiftCommunity/RxAlamofire.git",
from: "4.4.1"),
from: "5.2.0"),
],
targets: [
Expand All @@ -207,6 +207,8 @@ To manual install this extension you should get the `RxAlamofire/Source/RxAlamof

## Requirements

RxAlamofire requires Swift 5.0 and dedicated versions of Alamofire (4.8.2) and RxSwift (5.0.0).
RxAlamofire requires Swift 5.1 and dedicated versions of Alamofire (5.1.0) and RxSwift (5.1.0).

For the last Swift 5.0 support, please use RxAlamofire 5.1.0.

For the last Swift 4.2 support, please use RxAlamofire 4.5.0.
16 changes: 8 additions & 8 deletions RxAlamofire.podspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Pod::Spec.new do |s|
s.name = "RxAlamofire"

s.version = "5.1.0"
s.version = "5.2.0"
s.license = "MIT"
s.summary = "RxSwift wrapper around the elegant HTTP networking in Swift Alamofire"
s.homepage = "https://github.com/RxSwiftCommunity/RxAlamofire"
s.authors = { "RxSwift Community" => "community@rxswift.org" }
s.source = { :git => "https://github.com/RxSwiftCommunity/RxAlamofire.git", :tag => s.version }
s.swift_version = "5.0"
s.swift_version = "5.1"

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"
s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.12"
s.tvos.deployment_target = "10.0"
s.watchos.deployment_target = "3.0"

s.requires_arc = true
Expand All @@ -20,14 +20,14 @@ Pod::Spec.new do |s|

s.subspec "Core" do |ss|
ss.source_files = "Sources/*.swift"
ss.dependency "RxSwift", "~> 5.0"
ss.dependency "Alamofire", "~> 4.8"
ss.dependency "RxSwift", "~> 5.1"
ss.dependency "Alamofire", "~> 5.1"
ss.framework = "Foundation"
end

s.subspec "RxCocoa" do |ss|
ss.source_files = "Sources/Cocoa/*.swift"
ss.dependency "RxCocoa", "~> 5.0"
ss.dependency "RxCocoa", "~> 5.1"
ss.dependency "RxAlamofire/Core"
end
end
111 changes: 61 additions & 50 deletions RxAlamofireTests/RxAlamofireTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ private struct Dummy {

class RxAlamofireSpec: XCTestCase {

var manager: SessionManager!
var manager: Session!

let testError = NSError(domain: "RxAlamofire Test Error", code: -1, userInfo: nil)
let disposeBag = DisposeBag()

//MARK: Configuration
override func setUp() {
super.setUp()
manager = SessionManager()
manager = Session()

_ = stub(condition: isHost("mywebservice.com")) { _ in
return OHHTTPStubsResponse(data: Dummy.DataStringData, statusCode:200, headers:nil)
Expand Down Expand Up @@ -72,33 +72,34 @@ class RxAlamofireSpec: XCTestCase {
}
}

func testProgress() {
do {
let dataRequest = try request(HTTPMethod.get, "http://myjsondata.com").toBlocking().first()!
let progressObservable = dataRequest.rx.progress().share(replay: 100, scope: .forever)
let _ = progressObservable.subscribe { }
let delegate = dataRequest.delegate as! DataTaskDelegate
let progressHandler = delegate.progressHandler!
[(1000, 4000), (4000, 4000)].forEach { completed, total in
let progress = Alamofire.Progress()
progress.completedUnitCount = Int64(completed)
progress.totalUnitCount = Int64(total)
progressHandler.closure(progress)
}
let actualEvents = try progressObservable.toBlocking().toArray()
let expectedEvents = [
RxProgress(bytesWritten: 0, totalBytes: 0),
RxProgress(bytesWritten: 1000, totalBytes: 4000),
RxProgress(bytesWritten: 4000, totalBytes: 4000),
]
XCTAssertEqual(actualEvents.count, expectedEvents.count)
for i in 0..<actualEvents.count {
XCTAssertEqual(actualEvents[i], expectedEvents[i])
}
} catch {
XCTFail("\(error)")
}
}
// TODO: In Alamofire 5 progress became immutable. Test logic should be completely changed.
// func testProgress() {
// do {
// let dataRequest = try request(HTTPMethod.get, "http://myjsondata.com").toBlocking().first()!
// let progressObservable = dataRequest.rx.progress().share(replay: 100, scope: .forever)
// let _ = progressObservable.subscribe { }
// let delegate = dataRequest.delegate as! DataTaskDelegate
// let progressHandler = delegate.progressHandler!
// [(1000, 4000), (4000, 4000)].forEach { completed, total in
// let progress = Alamofire.Progress()
// progress.completedUnitCount = Int64(completed)
// progress.totalUnitCount = Int64(total)
// progressHandler.closure(progress)
// }
// let actualEvents = try progressObservable.toBlocking().toArray()
// let expectedEvents = [
// RxProgress(bytesWritten: 0, totalBytes: 0),
// RxProgress(bytesWritten: 1000, totalBytes: 4000),
// RxProgress(bytesWritten: 4000, totalBytes: 4000),
// ]
// XCTAssertEqual(actualEvents.count, expectedEvents.count)
// for i in 0..<actualEvents.count {
// XCTAssertEqual(actualEvents[i], expectedEvents[i])
// }
// } catch {
// XCTFail("\(error)")
// }
// }

func testRxProgress() {
let subject = RxProgress(bytesWritten: 1000, totalBytes: 4000)
Expand All @@ -114,47 +115,57 @@ class RxAlamofireSpec: XCTestCase {
do {
let temporaryDirectory = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let fileURL = temporaryDirectory.appendingPathComponent("\(UUID().uuidString).json")
let myUrl = try "http://myjsondata.com".asURL()

let destination: DownloadRequest.DownloadFileDestination = { _, _ in (fileURL, []) }
let destination: DownloadRequest.Destination = { _, _ in (fileURL, []) }
let request = download(
"http://myjsondata.com",
URLRequest(url: myUrl),
to: destination
)

let defaultResponse = try request.rx
.response()
.toBlocking()
.first()!
let testDownloadResponseExpectation = expectation(description: "testDownloadResponse expectation")

XCTAssertEqual(defaultResponse.response?.statusCode, 200)
XCTAssertNotNil(defaultResponse.destinationURL)
_ = request
.map {
$0.response { downloadResponse in
XCTAssertEqual(downloadResponse.response?.statusCode, 200)
XCTAssertNotNil(downloadResponse.fileURL)
testDownloadResponseExpectation.fulfill()
}
}
.subscribe {}

wait(for: [testDownloadResponseExpectation], timeout: 5)
} catch {
XCTFail("\(error)")
}
}

func testDownloadResponseSerialized() {
do {
let temporaryDirectory = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let fileURL = temporaryDirectory.appendingPathComponent("\(UUID().uuidString).json")
let myUrl = try "http://myjsondata.com".asURL()

let destination: DownloadRequest.DownloadFileDestination = { _, _ in (fileURL, []) }
let destination: DownloadRequest.Destination = { _, _ in (fileURL, []) }
let request = download(
"http://myjsondata.com",
URLRequest(url: myUrl),
to: destination
)

let jsonResponse = try request.rx
.responseSerialized(responseSerializer: DownloadRequest.jsonResponseSerializer())
.toBlocking()
.first()!
let testDownloadResponseExpectation = expectation(description: "testDownloadResponse expectation")

_ = request
.map {
$0.responseJSON { jsonResponse in
guard let json = jsonResponse.value as? [String: Any] else { XCTFail("Bad Response"); return }
XCTAssertEqual(json["hello"] as? String, "world")
testDownloadResponseExpectation.fulfill()
}
}
.subscribe {}

XCTAssertEqual(jsonResponse.response?.statusCode, 200)
guard let json = jsonResponse.value as? [String: Any] else {
XCTFail("Bad Response")
return
}
XCTAssertEqual(json["hello"] as? String, "world")
wait(for: [testDownloadResponseExpectation], timeout: 5)
} catch {
XCTFail("\(error)")
}
Expand Down
6 changes: 3 additions & 3 deletions RxAlamofireTests/ValidateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ValidateSpec: XCTestCase {
static let DataJSON = DataJSONContent.data(using: String.Encoding.utf8)!
}

var manager: SessionManager!
var manager: Session!
let disposeBag = DisposeBag()

override func setUp() {
super.setUp()
manager = SessionManager()
manager = Session()

_ = stub(condition: isHost("200.xyz")) { _ in
return OHHTTPStubsResponse(data: Dummy.DataJSON, statusCode: 200, headers: ["Content-Type":"application/json"])
Expand Down Expand Up @@ -114,7 +114,7 @@ class ValidateSpec: XCTestCase {

private func validateResponseIs200(_ response: HTTPURLResponse) -> Request.ValidationResult {
if response.statusCode == 200 {
return .success
return .success(())
}

return .failure(AFError.responseValidationFailed(reason: .unacceptableStatusCode(code: response.statusCode)))
Expand Down
6 changes: 3 additions & 3 deletions Sources/Cocoa/URLSession+RxAlamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension Reactive where Base: URLSession {
_ url: URLConvertible,
parameters: [String: Any]? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: [String: String]? = nil) -> Observable<Any> {
headers: HTTPHeaders? = nil) -> Observable<Any> {
do {
let request = try RxAlamofire.urlRequest(method,
url,
Expand Down Expand Up @@ -59,7 +59,7 @@ extension Reactive where Base: URLSession {
_ url: URLConvertible,
parameters: [String: Any]? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: [String: String]? = nil) -> Observable<(response: HTTPURLResponse, data: Data)> {
headers: HTTPHeaders? = nil) -> Observable<(response: HTTPURLResponse, data: Data)> {
do {
let request = try RxAlamofire.urlRequest(method,
url,
Expand Down Expand Up @@ -87,7 +87,7 @@ extension Reactive where Base: URLSession {
_ url: URLConvertible,
parameters: [String: AnyObject]? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: [String: String]? = nil) -> Observable<Data> {
headers: HTTPHeaders? = nil) -> Observable<Data> {
do {
let request = try RxAlamofire.urlRequest(method,
url,
Expand Down
Loading

0 comments on commit 522138d

Please sign in to comment.