Skip to content

Commit

Permalink
Merge pull request #52 from BottleRocketStudios/feature/requestRename
Browse files Browse the repository at this point in the history
Feature/request rename
  • Loading branch information
wmcginty authored Jul 18, 2018
2 parents 25abb52 + f17aa01 commit d5bbf7d
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 216 deletions.
26 changes: 15 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,51 @@

##### Enhancements

* Two new error-facing protocols were added. `NetworkServiceFailureInitializable` represents a `Swift.Error` that can be initialized from a `NetworkServiceFailure` object. `DecodingFailureInitializable` represents a `Swift.Error` that can be initialized from a `DecodingError` as a result of decoding `Data`. These conformances have been added as extensions to `AnyError` (meaning `AnyNetworkRequest` usage is unaffected). As a result of these new protocols, the `BackendServiceError` type has been removed. Types conforming to `NetworkRequest` now have an associated `ErrorType` which must conform to `NetworkServiceFailureInitializable`. If a request generates any sort of failure response, the custom error type will be initialized from it instead of returning a generic `BackendServiceError`. In addition, if `NetworkRequest.ErrorType` conforms to `DecodingFailureInitializable`, the custom erorr type will be instantiated and returned.
* Two new error-facing protocols were added. `NetworkServiceFailureInitializable` represents a `Swift.Error` that can be initialized from a `NetworkServiceFailure` object. `DecodingFailureInitializable` represents a `Swift.Error` that can be initialized from a `DecodingError` as a result of decoding `Data`. These conformances have been added as extensions to `AnyError` (meaning `AnyRequest` usage is unaffected). As a result of these new protocols, the `BackendServiceError` type has been removed. Types conforming to `Request` now have an associated `ErrorType` which must conform to `NetworkServiceFailureInitializable`. If a request generates any sort of failure response, the custom error type will be initialized from it instead of returning a generic `BackendServiceError`. In addition, if `Request.ErrorType` conforms to `DecodingFailureInitializable`, the custom erorr type will be instantiated and returned.
[Will McGinty](https://github.com/wmcginty)
[#38](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/38)
* Added a new initalizer to `AnyNetworkRequest` which accepts a `String` value designating the key of JSON at which to begin decoding.

* Added a new initalizer to `AnyRequest` which accepts a `String` value designating the key of JSON at which to begin decoding.
[Will McGinty](https://github.com/wmcginty)
[#41](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/41)
* Separated the generation/encoding of the URL query from the `NetworkRequest` object into an extension `URL`.

* Separated the generation/encoding of the URL query from the `Request` object into an extension `URL`.
[Will McGinty](https://github.com/wmcginty)
[#40](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/40)

* Add functionality to `NetworkReqest` to allow for replacing and adding to the HTTP headers.
[Will McGinty](https://github.com/wmcginty)
[#43](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/43)

* Simplify usage of `DecodableContainer` types with `JSONDecoder`
[Will McGinty](https://github.com/wmcginty)
[#44](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/44)

* Add a subsystem which can perform transparent error using `RequestRecoveryStrategy`.
[Will McGinty](https://github.com/wmcginty)
[#45](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/45)

* Simplify usage of `dataTransfomer` extensions with custom error types
[Will McGinty](https://github.com/wmcginty)
[#47](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/47)

* Add `HTTP.HeaderValue` for JSON API specification.
[Earl Gaspard](https://github.com/earlgaspard)
[#46](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/46)

* Converted `HTTP.Status`nested types (`HTTP.Status.Success`, `HTTP.Status.ClientError`, etc.) from enums to `RawRepresentable` structs. This keeps the library more open for extension by allowing clients to more easily specify and use custom HTTP status codes.
[Tyler Milner](https://github.com/tylermilner)
[#49](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/49)
[#50](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/50)

* Implemented synthesized `Equatable` and `Hashable` conformance that was introduced in Swift 4.1.
[Tyler Milner](https://github.com/tylermilner)
[#51](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/51)

* Renamed `NetworkRequest` and `AnyNetworkRequest` to `Request` and `AnyRequest`.
[Will McGinty](https://github.com/wmcginty)
[#51](https://github.com/BottleRocketStudios/iOS-Hyperspace/pull/52)

##### Bug Fixes

* None.
Expand Down
20 changes: 10 additions & 10 deletions Examples/Playground/Hyperspace.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ struct NewPost: Encodable {

// MARK: - Example

/// 1. Customize the defaults for NetworkRequest creation (optional)
/// 1. Customize the defaults for Request creation (optional)

NetworkRequestDefaults.defaultTimeout = 60 // Default timeout is 30 seconds
NetworkRequestDefaults.defaultCachePolicy = .reloadIgnoringLocalCacheData // Default cache policy is '.useProtocolCachePolicy'
RequestDefaults.defaultTimeout = 60 // Default timeout is 30 seconds
RequestDefaults.defaultCachePolicy = .reloadIgnoringLocalCacheData // Default cache policy is '.useProtocolCachePolicy'

/// 2. Create your concrete NetworkRequest types
/// 2. Create your concrete Request types

struct GetUserRequest: NetworkRequest {
struct GetUserRequest: Request {
// Define the model we want to get back
typealias ResponseType = User
typealias ErrorType = AnyError

// Define NetworkRequest property values
// Define Request property values
var method: HTTP.Method = .get
var url: URL {
return URL(string: "http://jsonplaceholder.typicode.com/users/\(userId)")!
Expand All @@ -60,12 +60,12 @@ struct GetUserRequest: NetworkRequest {
}
}

struct CreatePostRequest: NetworkRequest {
struct CreatePostRequest: Request {
// Define the model we want to get back
typealias ResponseType = Post
typealias ErrorType = AnyError

// Define NetworkRequest property values
// Define Request property values
var method: HTTP.Method = .post
var url = URL(string: "http://jsonplaceholder.typicode.com/posts")!
var headers: [HTTP.HeaderKey: HTTP.HeaderValue]? = [.contentType: .applicationJSON]
Expand All @@ -83,7 +83,7 @@ struct CreatePostRequest: NetworkRequest {
}
}

/// 3. Instantiate your concrete NetworkRequest types
/// 3. Instantiate your concrete Request types

let getUserRequest = GetUserRequest(userId: 1)
let createPostRequest = CreatePostRequest(newPost: NewPost(userId: 1, title: "Test tile", body: "Test body"))
Expand All @@ -92,7 +92,7 @@ let createPostRequest = CreatePostRequest(newPost: NewPost(userId: 1, title: "Te

let backendService = BackendService()

/// 5. Execute the NetworkRequest
/// 5. Execute the Request

func getUser(completion: @escaping () -> Void) {
backendService.execute(request: getUserRequest) { (result) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ struct NewPost: Encodable {

// MARK: - Request

let getUserRequest = AnyNetworkRequest<User>(method: .get, url: URL(string: "http://jsonplaceholder.typicode.com/users/1")!)
let getUserRequest = AnyRequest<User>(method: .get, url: URL(string: "http://jsonplaceholder.typicode.com/users/1")!)

let newPost = NewPost(userId: 1, title: "Test tile", body: "Test body")
let postBody = try? JSONEncoder().encode(newPost)

let createPostRequest = AnyNetworkRequest<Post>(method: .post,
let createPostRequest = AnyRequest<Post>(method: .post,
url: URL(string: "http://jsonplaceholder.typicode.com/posts")!,
headers: [.contentType: .applicationJSON],
body: postBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Result

PlaygroundPage.current.needsIndefiniteExecution = true

struct DeletePostRequest: NetworkRequest {
struct DeletePostRequest: Request {
typealias ResponseType = EmptyResponse
typealias ErrorType = AnyError

Expand All @@ -27,9 +27,9 @@ struct DeletePostRequest: NetworkRequest {

let deletePostRequest = DeletePostRequest(postId: 1)

// Alternatively, you can use the "AnyNetworkRequest" type to implement this simple DELETE request:
// Alternatively, you can use the "AnyRequest" type to implement this simple DELETE request:

//let deletePostRequest = AnyNetworkRequest<EmptyResponse>(method: .delete, url: URL(string: "http://jsonplaceholder.typicode.com/posts/1")!) { (data) -> Result<EmptyResponse, AnyError> in
//let deletePostRequest = AnyRequest<EmptyResponse>(method: .delete, url: URL(string: "http://jsonplaceholder.typicode.com/posts/1")!) { (data) -> Result<EmptyResponse, AnyError> in
// return .success(EmptyResponse())
//}

Expand Down
16 changes: 8 additions & 8 deletions Examples/Shared/NetworkRequests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NetworkRequests.swift
// Requests.swift
// Hyperspace_Example
//
// Created by Tyler Milner on 7/14/17.
Expand All @@ -12,8 +12,8 @@ import Result

// MARK: - Network Request Defaults

// An extension like this can be used so that you don't have to specify them in every NetworkRequest you create.
extension NetworkRequest {
// An extension like this can be used so that you don't have to specify them in every Request you create.
extension Request {
static var defaultTimeout: TimeInterval {
return 30.0
}
Expand All @@ -33,13 +33,13 @@ extension NetworkRequest {

// MARK: - Get User Request

struct GetUserRequest: NetworkRequest {
struct GetUserRequest: Request {

// Define the model we want to get back
typealias ResponseType = User
typealias ErrorType = AnyError

// Define NetworkRequest property values
// Define Request property values
var method: HTTP.Method = .get
var url: URL {
return URL(string: "https://jsonplaceholder.typicode.com/users/\(userId)")!
Expand All @@ -58,13 +58,13 @@ struct GetUserRequest: NetworkRequest {

// MARK: - Create Post Request

struct CreatePostRequest: NetworkRequest {
struct CreatePostRequest: Request {

// Define the model we want to get back
typealias ResponseType = Post
typealias ErrorType = AnyError

// Define NetworkRequest property values
// Define Request property values
var method: HTTP.Method = .post
var url = URL(string: "https://jsonplaceholder.typicode.com/posts")!
var headers: [HTTP.HeaderKey: HTTP.HeaderValue]? = [.contentType: .applicationJSON]
Expand All @@ -82,7 +82,7 @@ struct CreatePostRequest: NetworkRequest {

// MARK: - Delete Post Request

struct DeletePostRequest: NetworkRequest {
struct DeletePostRequest: Request {
typealias ResponseType = EmptyResponse
typealias ErrorType = AnyError

Expand Down
Loading

0 comments on commit d5bbf7d

Please sign in to comment.