Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 1a02c5a

Browse files
committed
Bump version num & document changes
1 parent 7946428 commit 1a02c5a

2 files changed

Lines changed: 48 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
55

66
## [Unreleased]
77
### Added
8-
- Microya now supports Combine publishers, just call `publisher(on:decodeBodyTo:)` or `publisher(on:)` instead of `performRequest(on:decodeBodyTo:)` or `performRequest(on:)` and you'll get an `AnyPublisher` request stream to subscribe to. In success cases you will receive the decoded typed object, in error cases an `ApiError` object exactly like within the `performRequest` completion closure. But instead of a `Result` type you can use `sink` or `catch` from the Combine framework.
8+
- None.
99
### Changed
10-
- The `queryParameters` is no longer of type `[String: String]`, but `[String: QueryParameterValue]` now. Existing code like `["search": searchTerm]` will need to be updated to `["search": .string(searchTerm)]`. Apart from `.string` this now also allows specifying an array of strings like so: `["tags": .array(userSelectedTags)]`. String & array literals are supported directly, e.g. `["sort": "createdAt"]` or `["sort": ["createdAt", "id"]]`.
10+
- None.
1111
### Deprecated
1212
- None.
1313
### Removed
@@ -17,6 +17,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1717
### Security
1818
- None.
1919

20+
## [0.4.0] - 2020-11-21
21+
### Added
22+
- Microya now supports Combine publishers, just call `publisher(on:decodeBodyTo:)` or `publisher(on:)` instead of `performRequest(on:decodeBodyTo:)` or `performRequest(on:)` and you'll get an `AnyPublisher` request stream to subscribe to. In success cases you will receive the decoded typed object, in error cases an `ApiError` object exactly like within the `performRequest` completion closure. But instead of a `Result` type you can use `sink` or `catch` from the Combine framework.
23+
### Changed
24+
- The `queryParameters` is no longer of type `[String: String]`, but `[String: QueryParameterValue]` now. Existing code like `["search": searchTerm]` will need to be updated to `["search": .string(searchTerm)]`. Apart from `.string` this now also allows specifying an array of strings like so: `["tags": .array(userSelectedTags)]`. String & array literals are supported directly, e.g. `["sort": "createdAt"]` or `["sort": ["createdAt", "id"]]`.
25+
2026
## [0.3.0] - 2020-11-03
2127
### Added
2228
- New `ApiProvider` type encapsulating different request methods with support for plugins.

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
alt="codebeat badge">
1414
</a>
1515
<a href="https://github.com/Flinesoft/HandySwift/releases">
16-
<img src="https://img.shields.io/badge/Version-0.3.0-blue.svg"
17-
alt="Version: 0.3.0">
16+
<img src="https://img.shields.io/badge/Version-0.4.0-blue.svg"
17+
alt="Version: 0.4.0">
1818
<img src="https://img.shields.io/badge/Swift-5.3-FFAC45.svg"
1919
alt="Swift: 5.3">
2020
<img src="https://img.shields.io/badge/Platforms-Apple%20%7C%20Linux-FF69B4.svg"
@@ -82,7 +82,7 @@ public protocol Endpoint {
8282
var headers: [String: String] { get }
8383
var subpath: String { get }
8484
var method: HttpMethod { get }
85-
var queryParameters: [String: String] { get }
85+
var queryParameters: [String: QueryParameterValue] { get }
8686
}
8787
```
8888

@@ -140,16 +140,16 @@ extension MicrosoftTranslatorEndpoint: Endpoint {
140140
}
141141
}
142142

143-
var queryParameters: [String: String] {
144-
var queryParameters: [String: String] = ["api-version": "3.0"]
143+
var queryParameters: [String: QueryParameterValue] {
144+
var queryParameters: [String: QueryParameterValue] = ["api-version": "3.0"]
145145

146146
switch self {
147147
case .languages:
148148
break
149149

150150
case let .translate(_, sourceLanguage, targetLanguages, _):
151-
queryParameters["from"] = sourceLanguage.rawValue
152-
queryParameters["to"] = targetLanguages.map { $0.rawValue }.joined(by: ",")
151+
queryParameters["from"] = .string(sourceLanguage.rawValue)
152+
queryParameters["to"] = .array(targetLanguages.map { $0.rawValue })
153153
}
154154

155155
return queryParameters
@@ -233,6 +233,38 @@ let translationsByLanguage = try provider.performRequestAndWait(on: endpoint, de
233233

234234
There's even useful functional methods defined on the `Result` type like `map()`, `flatMap()` or `mapError()` and `flatMapError()`. See the "Transforming Result" section in [this](https://www.hackingwithswift.com/articles/161/how-to-use-result-in-swift) article for more information.
235235

236+
### Combine Support
237+
238+
`performRequest(on:decodeBodyTo:)` or `performRequest()`
239+
240+
If you are using Combine in your project (e.g. because you're using SwiftUI), you might want to replace the calls to `performRequest(on:decodeBodyTo:)` or `performRequest(on:)` with the Combine calls `publisher(on:decodeBodyTo:)` or `publisher(on:)`. This will give you an `AnyPublisher` request stream to subscribe to. In success cases you will receive the decoded typed object, in error cases an `ApiError` object exactly like within the `performRequest` completion closure. But instead of a `Result` type you can use `sink` or `catch` from the Combine framework.
241+
242+
For example, the usage with Combine might look something like this:
243+
244+
```Swift
245+
var cancellables: Set<AnyCancellable> = []
246+
247+
provider.publisher(on: endpoint, decodeBodyTo: TranslationsResponse.self)
248+
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
249+
.subscribe(on: DispatchQueue.global())
250+
.receive(on: DispatchQueue.main)
251+
.sink(
252+
receiveCompletion: { _ in }
253+
receiveValue: { (translationsResponse: TranslationsResponse) in
254+
// do something with the success response object
255+
}
256+
)
257+
.catch { apiError in
258+
switch apiError {
259+
case let .clientError(statusCode, clientError):
260+
// show an alert to customer with status code & data from clientError body
261+
default:
262+
logger.handleApiError(apiError)
263+
}
264+
}
265+
.store(in: &cancellables)
266+
```
267+
236268
### Plugins
237269

238270
The initializer of `ApiProvider` accepts an array of `Plugin` objects. You can implement your own plugins or use one of the existing ones in the [Plugins](https://github.com/Flinesoft/Microya/tree/main/Sources/Microya/Plugins) directory. Here's are the callbacks a custom `Plugin` subclass can override:
@@ -297,7 +329,7 @@ public var headers: [String: String] {
297329
]
298330
}
299331

300-
public var queryParameters: [String: String] { [:] }
332+
public var queryParameters: [String: QueryParameterValue] { [:] }
301333
```
302334

303335
So technically, the `Endpoint` type only requires you to specify the following 4 things:

0 commit comments

Comments
 (0)