Skip to content

Commit a13db0c

Browse files
Merge pull request #73 from dbsystel/develop
All changes for 1.0
2 parents a72f917 + 60f4adf commit a13db0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1005
-1351
lines changed

.travis.yml

+18-28
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,32 @@ matrix:
99
before_install:
1010
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
1111
- cd ..
12-
- export SWIFT_VERSION=swift-4.0-RELEASE
13-
- wget https://swift.org/builds/swift-3.1-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz
12+
- export SWIFT_VERSION=swift-4.0.3-RELEASE
13+
- wget https://swift.org/builds/swift-4.0.3-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz
1414
- tar xzf $SWIFT_VERSION-ubuntu14.04.tar.gz
1515
- export PATH="${PWD}/${SWIFT_VERSION}-ubuntu14.04/usr/bin:${PATH}"
1616
- cd DBNetworkStack
1717
script:
1818
- swift test --verbose
1919
- os: osx
20-
osx_image: xcode9
20+
osx_image: xcode9.2
2121
language: objective-c
2222
env: "macOS"
23+
before_install:
24+
- gem install jazzy
2325
script:
24-
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=OS X' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty
25-
- os: osx
26-
osx_image: xcode9
27-
language: objective-c
28-
env: "iOS"
29-
script:
30-
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=iOS Simulator,name=iPhone SE,OS=latest' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage YES | xcpretty
26+
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "platform=macOS" test | xcpretty
27+
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "platform=tvOS Simulator,name=Apple TV" test | xcpretty
28+
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "platform=watchOS Simulator,name=Apple Watch - 38mm" build | xcpretty
29+
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination "platform=iOS Simulator,name=iPhone SE" test | xcpretty
30+
- swift test & pod spec lint --allow-warnings & carthage build --no-skip-current
31+
- jazzy --clean --author "DBSystel" --github_url https://github.com/dbsystel/DBNetworkStack --module DBNetworkStack --output docs
3132
after_success:
3233
- bash <(curl -s https://codecov.io/bash)
33-
- os: osx
34-
osx_image: xcode9
35-
language: objective-c
36-
env: "watchOS"
37-
script:
38-
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=watchOS Simulator,name=Apple Watch Series 2 - 38mm' build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty
39-
- os: osx
40-
osx_image: xcode9
41-
language: objective-c
42-
env: "tvOS"
43-
script:
44-
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=latest' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty
45-
- os: osx
46-
osx_image: xcode9
47-
language: objective-c
48-
env: "SPM, Carthage, CocoaPods"
49-
script:
50-
- swift test & pod spec lint & carthage build --no-skip-current
34+
deploy:
35+
provider: pages
36+
local_dir: ${TRAVIS_BUILD_DIR}/docs
37+
skip_cleanup: true
38+
github_token: $GITHUB_TOKEN
39+
on:
40+
branch: master

DBNetworkStack.podspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "DBNetworkStack"
19-
s.version = "0.5.0"
19+
s.version = "1.0.0"
2020
s.summary = "DBNetworkStack is a network abstraction for fetching request and mapping them to model objects."
2121

2222
# This description is used to generate tags and improve search results.
@@ -27,7 +27,6 @@ Pod::Spec.new do |s|
2727
s.description = "DBNetworkStack is a network abstraction for fetching request and mapping them to model objects. It supports mocking via protocols."
2828

2929
s.homepage = "https://github.com/dbsystel/DBNetworkStack"
30-
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
3130

3231

3332
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

DBNetworkStack.xcodeproj/project.pbxproj

+44-70
Large diffs are not rendered by default.

JSONExample.playground/Contents.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//: Playground - noun: a place where people can play
2-
31
import DBNetworkStack
42
import PlaygroundSupport
53

@@ -9,7 +7,7 @@ URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
97

108
//Prepare NetworkAccess & NetworkService
119
let networkAccess = URLSession(configuration: .default)
12-
let networkService = NetworkService(networkAccess: networkAccess)
10+
let networkService = BasicNetworkService(networkAccess: networkAccess)
1311

1412
struct IPOrigin: Decodable {
1513
let origin: String
@@ -20,8 +18,8 @@ let request = URLRequest(path: "ip", baseURL: url)
2018

2119
let resource = Resource<IPOrigin>(request: request, decoder: JSONDecoder())
2220

23-
networkService.request(resource, onCompletion: { origin in
24-
print(origin)
21+
networkService.request(resource, onCompletionWithResponse: { origin, response in
22+
print(origin, response)
2523
}, onError: { error in
2624
print(error)
2725
})

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
| 🚄 | Extendable API |
1616
| 🎹        | Composable Features           |
1717
| &#9989; | Fully unit tested |
18+
| 📕  | [Documented here](https://dbsystel.github.io/DBNetworkStack/)            |
1819

1920
The idea behind this project comes from this [talk.objc.io article](https://talk.objc.io/episodes/S01E01-networking).
2021

2122
## Basic Demo
2223
Lets say you want to fetch a ``html`` string.
2324

24-
First you have to create a service, by providing a network access. You can use URLSession out of the box or provide your own custom solution by implementing ```NetworkAccessProviding```.
25+
First you have to create a service, by providing a network access. You can use URLSession out of the box or provide your own custom solution by implementing ```NetworkAccess```.
2526

2627
```swift
2728

2829
let networkAccess = URLSession(configuration: .default)
29-
let networkService = NetworkService(networkAccess: networkAccess)
30+
let networkService = BasicNetworkService(networkAccess: networkAccess)
3031

3132
```
3233

@@ -49,7 +50,7 @@ networkService.request(resource, onCompletion: { htmlText in
4950

5051
```
5152

52-
## Loade types conforming to `Decodable`
53+
## Load types conforming to Swift-`Decodable`
5354
```swift
5455
struct IPOrigin: Decodable {
5556
let origin: String
@@ -69,13 +70,13 @@ networkService.request(resource, onCompletion: { origin in
6970

7071
## Accessing HTTPResponse
7172

72-
Request your resource and handle the result & response. This is similar to just requesting a resulting model.
73+
Request your resource and handle the result & http response. This is similar to just requesting a resulting model.
7374
```swift
74-
extension Resource where Model: XMLDocument {
75-
public init(request: URLRequestConvertible) {
76-
self.init(request: request, parse: { try XMLDocument(data: $0 })
77-
}
78-
}
75+
networkService.request(resource, onCompletionWithResponse: { origin, response in
76+
print(origin, response)
77+
}, onError: { error in
78+
//Handle errors
79+
})
7980
```
8081

8182
## Protocol oriented architecture / Exchangability
@@ -84,10 +85,10 @@ The following table shows all the protocols and their default implementations.
8485

8586
| Protocol | Default Implementation |
8687
| -------------------------------- | ---------------------- |
87-
| ```NetworkAccessProviding``` | ```URLSession``` |
88-
| ```NetworkServiceProviding``` | ```NetworkService``` |
88+
| ```NetworkAccess``` | ```URLSession``` |
89+
| ```NetworkService``` | ```BasicNetworkService``` |
8990
| ```URLRequestConvertible``` | ```URLRequest``` |
90-
| ```NetworkTaskRepresenting``` | ```URLSessionTask``` |
91+
| ```NetworkTask``` | ```URLSessionTask``` |
9192

9293
## Composable Features
9394

@@ -111,7 +112,7 @@ The following table shows all the protocols and their default implementations.
111112
Specify the following in your `Cartfile`:
112113

113114
```ogdl
114-
github "dbsystel/dbnetworkstack" ~> 0.7
115+
github "dbsystel/dbnetworkstack" ~> 1.0
115116
```
116117

117118
### CocoaPods

SimpleDemo.playground/Contents.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//: Playground - noun: a place where people can play
2-
31
import DBNetworkStack
42
import PlaygroundSupport
53

@@ -9,11 +7,11 @@ URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
97

108
//Prepare NetworkAccess & NetworkService
119
let networkAccess = URLSession(configuration: .default)
12-
let networkService = NetworkService(networkAccess: networkAccess)
10+
let networkService = BasicNetworkService(networkAccess: networkAccess)
1311

1412
//Create a Resource with a given URLRequest and parsing
1513
let url: URL! = URL(string: "https://bahn.de")
16-
let request = URLRequest(path: "/p/view/index.shtml", baseURL: url)
14+
let request = URLRequest(path: "p/view/index.shtml", baseURL: url)
1715
let resource = Resource(request: request, parse: { String(data: $0, encoding: .utf8) })
1816

1917
networkService.request(resource, onCompletion: { htmlText in

Source/BasicNetworkService.swift

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// Copyright (C) 2017 DB Systel GmbH.
3+
// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a
6+
// copy of this software and associated documentation files (the "Software"),
7+
// to deal in the Software without restriction, including without limitation
8+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
// and/or sell copies of the Software, and to permit persons to whom the
10+
// Software is furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
// DEALINGS IN THE SOFTWARE.
22+
//
23+
24+
import Foundation
25+
import Dispatch
26+
27+
/**
28+
`BasicNetworkService` handles network request for resources by using a given `NetworkAccess`.
29+
30+
**Example**:
31+
```swift
32+
// Just use an URLSession for the networkAccess.
33+
let basicNetworkService: NetworkService = BasicNetworkService(networkAccess: URLSession(configuration: .default))
34+
```
35+
36+
- seealso: `NetworkService`
37+
*/
38+
public final class BasicNetworkService: NetworkService {
39+
let networkAccess: NetworkAccess
40+
let networkResponseProcessor: NetworkResponseProcessor
41+
42+
/**
43+
Creates an `BasicNetworkService` instance with a given network access to execute requests on.
44+
45+
- parameter networkAccess: provides basic access to the network.
46+
*/
47+
public init(networkAccess: NetworkAccess) {
48+
self.networkAccess = networkAccess
49+
self.networkResponseProcessor = NetworkResponseProcessor()
50+
}
51+
52+
/**
53+
Fetches a resource asynchronously from remote location. Execution of the requests starts immediately.
54+
Execution happens on no specific queue. It dependes on the network access which queue is used.
55+
Once execution is finished either the completion block or the error block gets called.
56+
You decide on which queue these blocks get executed.
57+
58+
**Example**:
59+
```swift
60+
let networkService: NetworkService = //
61+
let resource: Resource<String> = //
62+
63+
networkService.request(queue: .main, resource: resource, onCompletionWithResponse: { htmlText, response in
64+
print(htmlText, response)
65+
}, onError: { error in
66+
// Handle errors
67+
})
68+
```
69+
70+
- parameter queue: The `DispatchQueue` to execute the completion and error block on.
71+
- parameter resource: The resource you want to fetch.
72+
- parameter onCompletionWithResponse: Callback which gets called when fetching and transforming into model succeeds.
73+
- parameter onError: Callback which gets called when fetching or transforming fails.
74+
75+
- returns: a running network task
76+
*/
77+
@discardableResult
78+
public func request<Result>(queue: DispatchQueue, resource: Resource<Result>, onCompletionWithResponse: @escaping (Result, HTTPURLResponse) -> Void,
79+
onError: @escaping (NetworkError) -> Void) -> NetworkTask {
80+
let request = resource.request.asURLRequest()
81+
let dataTask = networkAccess.load(request: request, callback: { data, response, error in
82+
self.networkResponseProcessor.processAsyncResponse(queue: queue, response: response, resource: resource, data: data,
83+
error: error, onCompletion: onCompletionWithResponse, onError: onError)
84+
})
85+
return dataTask
86+
}
87+
88+
}

Source/DBNetworkStack.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//
2-
// DBNetworkStack.h
3-
//
4-
// Copyright (C) 2016 DB Systel GmbH.
2+
// Copyright (C) 2017 DB Systel GmbH.
53
// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/
64
//
75
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -22,8 +20,6 @@
2220
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2321
// DEALINGS IN THE SOFTWARE.
2422
//
25-
// Created by Lukas Schmidt on 22.08.16.
26-
//
2723

2824
#import <Foundation/Foundation.h>
2925

Source/HTTPMethod.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//
2-
// HTTPMethod.swift
3-
//
4-
// Copyright (C) 2016 DB Systel GmbH.
5-
// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/
2+
// Copyright (C) 2017 DB Systel GmbH.
3+
// DB Systel GmbH; Jürgen-Ponto-Platz 1; D-60329 Frankfurt am Main; Germany; http://www.dbsystel.de/
64
//
75
// Permission is hereby granted, free of charge, to any person obtaining a
86
// copy of this software and associated documentation files (the "Software"),
@@ -22,8 +20,6 @@
2220
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2321
// DEALINGS IN THE SOFTWARE.
2422
//
25-
// Created by Lukas Schmidt on 21.07.16.
26-
//
2723

2824
import Foundation
2925

Source/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.7.0</string>
18+
<string>1.0.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Source/JSONArrayResource.swift

-52
This file was deleted.

0 commit comments

Comments
 (0)