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

Commit

Permalink
Merge branch 'release/0.6.1' into versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Oct 14, 2021
2 parents 3cbfb67 + b1a6832 commit fe9cc6b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: swift test -v

test-macos:
runs-on: macOS-latest
runs-on: macos-11

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
### Security
- None.

## [0.6.1] - 2021-10-14
### Changed
- Made the `baseUrl` parameter of `ApiProvider` editable.

## [0.6.0] - 2021-09-30
### Added
- New async `response` method based on the new concurrency features available in Swift 5.5.
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PackageDescription

let package = Package(
name: "Microya",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)],
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(name: "Microya", targets: ["Microya"])
],
Expand Down
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
alt="codebeat badge">
</a>
<a href="https://github.com/Flinesoft/HandySwift/releases">
<img src="https://img.shields.io/badge/Version-0.6.0-blue.svg"
alt="Version: 0.6.0">
<img src="https://img.shields.io/badge/Swift-5.3-FFAC45.svg"
alt="Swift: 5.3">
<img src="https://img.shields.io/badge/Version-0.6.1-blue.svg"
alt="Version: 0.6.1">
<img src="https://img.shields.io/badge/Swift-5.4-FFAC45.svg"
alt="Swift: 5.4">
<img src="https://img.shields.io/badge/Platforms-Apple%20%7C%20Linux-FF69B4.svg"
alt="Platforms: Apple | Linux">
<a href="https://github.com/Flinesoft/Microya/blob/main/LICENSE.md">
Expand Down Expand Up @@ -277,6 +277,22 @@ provider.publisher(on: endpoint, decodeBodyTo: TranslationsResponse.self)
.store(in: &cancellables)
```

### Concurrency Support

If you are using Swift 5.5 in your project and your minimum target is iOS/tvOS 15+, macOS 12+ or watchOS 8+, you might want to use the `async` method `response` instead. For example, the usage might look something like this:

```Swift
let result = await provider.response(on: endpoint, decodeBodyTo: TranslationsResponse.self)

switch result {
case let .success(translationsByLanguage):
// use the already decoded `[String: String]` result

case let .failure(apiError):
// error handling
}
```

### Plugins

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:
Expand Down Expand Up @@ -331,8 +347,6 @@ public var decoder: JSONDecoder { JSONDecoder() }

public var encoder: JSONEncoder { JSONEncoder() }

public var plugins: [Plugin<Self>] { [] }

public var headers: [String: String] {
[
"Content-Type": "application/json",
Expand All @@ -351,7 +365,6 @@ So technically, the `Endpoint` type only requires you to specify the following 4
```swift
protocol Endpoint {
associatedtype ClientErrorType: Decodable
var baseUrl: URL { get }
var subpath: String { get }
var method: HttpMethod { get }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Microya/Core/ApiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class ApiProvider<EndpointType: Endpoint> {
public let plugins: [Plugin<EndpointType>]

/// The common base URL of the API endpoints.
public let baseUrl: URL
public var baseUrl: URL

/// The mocking behavior of the provider. Set this to receive mocked data in your tests. Use `nil` to make actual requests to your server (the default).
public let mockingBehavior: MockingBehavior<EndpointType>?
Expand Down

0 comments on commit fe9cc6b

Please sign in to comment.