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

Commit 8c3927d

Browse files
committed
Merge branch 'release/0.2.0' into versions
2 parents ae71364 + 956bc1e commit 8c3927d

8 files changed

Lines changed: 95 additions & 21 deletions

File tree

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1717
### Security
1818
- None.
1919

20+
## [0.2.0] - 2020-08-15
21+
### Changed
22+
- Make some fields of the `JsonApi` protocol optional by providing default implementation.
23+
2024
## [0.1.0] - 2019-02-14
2125
### Added
2226
- Add `JsonApi` type similar to `TargetType` in Moya with additional JSON `Codable` support.

CONTRIBUTING.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# Contributing
22

3-
Bug reports and pull requests are welcome on GitHub at https://github.com/JamitLabs/MungoHealer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
3+
Bug reports and pull requests are welcome on GitHub at https://github.com/Flinesoft/Microya. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
44

55
## Getting Started
66

7-
This section will tell you how you can get started contributing to MungoHealer.
7+
This section will tell you how you can get started contributing to Microya.
88

99
### Prerequisites
1010

1111
Before you start developing, please make sure you have the following tools installed on your machine:
1212

1313
- Xcode 10.0+
1414
- [SwiftLint](https://github.com/realm/SwiftLint)
15-
- [ProjLint](https://github.com/JamitLabs/ProjLint)
16-
- [Beak](https://github.com/yonaskolb/Beak)
1715

1816
### Commit Messages
1917

Frameworks/Microya/Models/JsonApi.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,35 @@ public enum JsonApiError: Error {
1515
case unknownError(Error)
1616
}
1717

18+
/// The protocol which defines the structure of an API endpoint.
1819
public protocol JsonApi {
20+
/// The JSON decoder to be used for decoding.
1921
var decoder: JSONDecoder { get }
22+
23+
/// The JSNO encoder to be used for encoding.
2024
var encoder: JSONEncoder { get }
2125

26+
/// The common base URL of the API endpoints.
2227
var baseUrl: URL { get }
28+
29+
/// The headers to be sent per request.
2330
var headers: [String: String] { get }
31+
32+
/// The subpath to be added to the base URL.
2433
var path: String { get }
34+
35+
/// The HTTP method to be used for the request.
2536
var method: Method { get }
37+
38+
/// The URL query parameters to be sent (part after ? in URLs, e.g. google.com?query=Harry+Potter).
2639
var queryParameters: [(key: String, value: String)] { get }
40+
41+
/// The body data to be sent along the request (e.g. JSON contents in a POST request).
2742
var bodyData: Data? { get }
2843
}
2944

3045
extension JsonApi {
46+
/// Performs the request. Make sure to specify the correct return type (e.g. let result: MyType = api.request...).
3147
public func request<ResultType: Decodable>(type: ResultType.Type) -> Result<ResultType, JsonApiError> {
3248
let dispatchGroup = DispatchGroup()
3349
dispatchGroup.enter()
@@ -93,3 +109,26 @@ extension JsonApi {
93109
return urlComponents.url!
94110
}
95111
}
112+
113+
/// Extension to provide default contents for optional fields.
114+
extension JsonApi {
115+
public var decoder: JSONDecoder {
116+
JSONDecoder()
117+
}
118+
119+
public var encoder: JSONEncoder {
120+
JSONEncoder()
121+
}
122+
123+
public var headers: [String: String] {
124+
[:]
125+
}
126+
127+
public var queryParameters: [(key: String, value: String)] {
128+
[]
129+
}
130+
131+
public var bodyData: Data? {
132+
nil
133+
}
134+
}

Frameworks/SupportingFiles/Info.plist

Lines changed: 1 addition & 1 deletion
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.1.1</string>
18+
<string>0.2.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Logo.png

15.3 KB
Loading

Microya.podspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
Pod::Spec.new do |s|
22

33
s.name = "Microya"
4-
s.version = "0.1.1"
4+
s.version = "0.2.0"
55
s.summary = "A micro version of the Moya network abstraction layer written in Swift."
66

77
s.description = <<-DESC
88
A micro version of the Moya network abstraction layer written in Swift.
9+
Currently only supports JSON APIs.
910
DESC
1011

1112
s.homepage = "https://github.com/Flinesoft/Microya"
1213
s.license = { :type => "MIT", :file => "LICENSE" }
1314

1415
s.author = { "Cihat Gündüz" => "cocoapods@cihatguenduez.de" }
15-
s.social_media_url = "https://twitter.com/Dschee"
16+
s.social_media_url = "https://twitter.com/Jeehut"
1617

1718
s.ios.deployment_target = "8.0"
1819
s.osx.deployment_target = "10.10"
1920
s.tvos.deployment_target = "9.0"
2021

2122
s.source = { :git => "https://github.com/Flinesoft/Microya.git", :tag => "#{s.version}" }
22-
s.source_files = "Sources", "Sources/**/*.swift"
23+
s.source_files = "Frameworks/**/*.swift"
2324
s.framework = "Foundation"
2425
s.swift_version = "4.2"
2526

README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
11
<p align="center">
2-
<img src="https://raw.githubusercontent.com/Flinesoft/Microya/stable/Logo.png"
3-
width=600>
2+
<img src="https://raw.githubusercontent.com/Flinesoft/Microya/main/Logo.png"
3+
width=396>
44
</p>
55

66
<p align="center">
77
<a href="https://app.bitrise.io/app/9144757ac274834d">
8-
<img src="https://app.bitrise.io/app/9144757ac274834d/status.svg?token=wnogmmQA9Zy7_2u75vRKdg"
8+
<img src="https://app.bitrise.io/app/9144757ac274834d/status.svg?token=wnogmmQA9Zy7_2u75vRKdg&branch=main"
99
alt="Build Status">
1010
</a>
11-
<a href="https://codebeat.co/projects/github-com-flinesoft-microya-stable">
11+
<a href="https://codebeat.co/projects/github-com-flinesoft-microya-main">
1212
<img src="https://codebeat.co/badges/a669e100-d30d-4801-b72d-3625ab7240be"
1313
alt="codebeat badge">
1414
</a>
15+
<a href="https://github.com/Flinesoft/HandySwift/releases">
16+
<img src="https://img.shields.io/badge/Version-0.2.0-blue.svg"
17+
alt="Version: 0.2.0">
1518
<img src="https://img.shields.io/badge/Swift-4.2-FFAC45.svg"
1619
alt="Swift: 4.2">
1720
<img src="https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS-FF69B4.svg"
1821
alt="Platforms: iOS | macOS | tvOS | watchOS">
19-
<a href="https://github.com/Flinesoft/Microya/blob/stable/LICENSE.md">
22+
<a href="https://github.com/Flinesoft/Microya/blob/main/LICENSE.md">
2023
<img src="https://img.shields.io/badge/License-MIT-lightgrey.svg"
2124
alt="License: MIT">
2225
</a>
26+
<br />
27+
<a href="https://paypal.me/Dschee/5EUR">
28+
<img src="https://img.shields.io/badge/PayPal-Donate-orange.svg"
29+
alt="PayPal: Donate">
30+
</a>
31+
<a href="https://github.com/sponsors/Jeehut">
32+
<img src="https://img.shields.io/badge/GitHub-Become a sponsor-orange.svg"
33+
alt="GitHub: Become a sponsor">
34+
</a>
35+
<a href="https://patreon.com/Jeehut">
36+
<img src="https://img.shields.io/badge/Patreon-Become a patron-orange.svg"
37+
alt="Patreon: Become a patron">
38+
</a>
2339
</p>
2440

2541
<p align="center">
2642
<a href="#installation">Installation</a>
2743
• <a href="#usage">Usage</a>
44+
• <a href="#donation">Donation</a>
2845
• <a href="https://github.com/Flinesoft/Microya/issues">Issues</a>
2946
• <a href="#contributing">Contributing</a>
3047
• <a href="#license">License</a>
3148
</p>
3249

3350
# Microya
3451

35-
A micro version of the Moya network abstraction layer written in Swift.
52+
A micro version of the [Moya](https://github.com/Moya/Moya) network abstraction layer written in Swift.
3653

3754
## Installation
3855

@@ -103,7 +120,7 @@ extension MicrosoftTranslatorApi: JsonApi {
103120
var path: String {
104121
switch self {
105122
case .languages:
106-
return "/languages"
123+
return "/languages"
107124

108125
case .translate:
109126
return "/translate"
@@ -113,7 +130,7 @@ extension MicrosoftTranslatorApi: JsonApi {
113130
var method: Method {
114131
switch self {
115132
case .languages:
116-
return .get
133+
return .get
117134

118135
case .translate:
119136
return .post
@@ -151,7 +168,7 @@ extension MicrosoftTranslatorApi: JsonApi {
151168
var headers: [String: String] {
152169
switch self {
153170
case .languages:
154-
return [:]
171+
return [:]
155172

156173
case .translate:
157174
return [
@@ -165,7 +182,7 @@ extension MicrosoftTranslatorApi: JsonApi {
165182

166183
</details>
167184

168-
### Step 3: Calling your API endpoint with the result type
185+
### Step 3: Calling your API endpoint with the Result type
169186

170187
Call an API endpoint providing a `Decodable` type of the expected result (if any) by using this method pre-implemented in the `JsonApi` protocol:
171188

@@ -191,15 +208,23 @@ Note that you can also use the throwing `get()` function of Swift 5's `Result` t
191208

192209
```Swift
193210
let endpoint = MicrosoftTranslatorApi.translate(texts: ["Test"], from: .english, to: [.german, .japanese, .turkish])
194-
let translationsByLanguage = try endpoint.request(type: [String: String].self)
211+
let translationsByLanguage = try endpoint.request(type: [String: String].self).get()
195212
// use the already decoded `[String: String]` result
196213
```
197214

198-
There's even useful functional methods defines on the `Results` 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.
215+
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.
216+
217+
218+
## Donation
219+
220+
Microya was brought to you by [Cihat Gündüz](https://github.com/Jeehut) in his free time. If you want to thank me and support the development of this project, please **make a small donation on [PayPal](https://paypal.me/Dschee/5EUR)**. In case you also like my other [open source contributions](https://github.com/Flinesoft) and [articles](https://medium.com/@Jeehut), please consider motivating me by **becoming a sponsor on [GitHub](https://github.com/sponsors/Jeehut)** or a **patron on [Patreon](https://www.patreon.com/Jeehut)**.
221+
222+
Thank you very much for any donation, it really helps out a lot! 💯
223+
199224

200225
## Contributing
201226

202-
See the file [CONTRIBUTING.md](https://github.com/JamitLabs/MungoHealer/blob/stable/CONTRIBUTING.md).
227+
See the file [CONTRIBUTING.md](https://github.com/Flinesoft/Microya/blob/main/CONTRIBUTING.md).
203228

204229

205230
## License

0 commit comments

Comments
 (0)