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.2.0' into versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Aug 15, 2020
2 parents ae71364 + 956bc1e commit 8c3927d
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.2.0] - 2020-08-15
### Changed
- Make some fields of the `JsonApi` protocol optional by providing default implementation.

## [0.1.0] - 2019-02-14
### Added
- Add `JsonApi` type similar to `TargetType` in Moya with additional JSON `Codable` support.
Expand Down
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Contributing

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.
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.

## Getting Started

This section will tell you how you can get started contributing to MungoHealer.
This section will tell you how you can get started contributing to Microya.

### Prerequisites

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

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

### Commit Messages

Expand Down
39 changes: 39 additions & 0 deletions Frameworks/Microya/Models/JsonApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,35 @@ public enum JsonApiError: Error {
case unknownError(Error)
}

/// The protocol which defines the structure of an API endpoint.
public protocol JsonApi {
/// The JSON decoder to be used for decoding.
var decoder: JSONDecoder { get }

/// The JSNO encoder to be used for encoding.
var encoder: JSONEncoder { get }

/// The common base URL of the API endpoints.
var baseUrl: URL { get }

/// The headers to be sent per request.
var headers: [String: String] { get }

/// The subpath to be added to the base URL.
var path: String { get }

/// The HTTP method to be used for the request.
var method: Method { get }

/// The URL query parameters to be sent (part after ? in URLs, e.g. google.com?query=Harry+Potter).
var queryParameters: [(key: String, value: String)] { get }

/// The body data to be sent along the request (e.g. JSON contents in a POST request).
var bodyData: Data? { get }
}

extension JsonApi {
/// Performs the request. Make sure to specify the correct return type (e.g. let result: MyType = api.request...).
public func request<ResultType: Decodable>(type: ResultType.Type) -> Result<ResultType, JsonApiError> {
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
Expand Down Expand Up @@ -93,3 +109,26 @@ extension JsonApi {
return urlComponents.url!
}
}

/// Extension to provide default contents for optional fields.
extension JsonApi {
public var decoder: JSONDecoder {
JSONDecoder()
}

public var encoder: JSONEncoder {
JSONEncoder()
}

public var headers: [String: String] {
[:]
}

public var queryParameters: [(key: String, value: String)] {
[]
}

public var bodyData: Data? {
nil
}
}
2 changes: 1 addition & 1 deletion Frameworks/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.1</string>
<string>0.2.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
Binary file added Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions Microya.podspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
Pod::Spec.new do |s|

s.name = "Microya"
s.version = "0.1.1"
s.version = "0.2.0"
s.summary = "A micro version of the Moya network abstraction layer written in Swift."

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

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

s.author = { "Cihat Gündüz" => "[email protected]" }
s.social_media_url = "https://twitter.com/Dschee"
s.social_media_url = "https://twitter.com/Jeehut"

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"

s.source = { :git => "https://github.com/Flinesoft/Microya.git", :tag => "#{s.version}" }
s.source_files = "Sources", "Sources/**/*.swift"
s.source_files = "Frameworks/**/*.swift"
s.framework = "Foundation"
s.swift_version = "4.2"

Expand Down
51 changes: 38 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
<p align="center">
<img src="https://raw.githubusercontent.com/Flinesoft/Microya/stable/Logo.png"
width=600>
<img src="https://raw.githubusercontent.com/Flinesoft/Microya/main/Logo.png"
width=396>
</p>

<p align="center">
<a href="https://app.bitrise.io/app/9144757ac274834d">
<img src="https://app.bitrise.io/app/9144757ac274834d/status.svg?token=wnogmmQA9Zy7_2u75vRKdg"
<img src="https://app.bitrise.io/app/9144757ac274834d/status.svg?token=wnogmmQA9Zy7_2u75vRKdg&branch=main"
alt="Build Status">
</a>
<a href="https://codebeat.co/projects/github-com-flinesoft-microya-stable">
<a href="https://codebeat.co/projects/github-com-flinesoft-microya-main">
<img src="https://codebeat.co/badges/a669e100-d30d-4801-b72d-3625ab7240be"
alt="codebeat badge">
</a>
<a href="https://github.com/Flinesoft/HandySwift/releases">
<img src="https://img.shields.io/badge/Version-0.2.0-blue.svg"
alt="Version: 0.2.0">
<img src="https://img.shields.io/badge/Swift-4.2-FFAC45.svg"
alt="Swift: 4.2">
<img src="https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS-FF69B4.svg"
alt="Platforms: iOS | macOS | tvOS | watchOS">
<a href="https://github.com/Flinesoft/Microya/blob/stable/LICENSE.md">
<a href="https://github.com/Flinesoft/Microya/blob/main/LICENSE.md">
<img src="https://img.shields.io/badge/License-MIT-lightgrey.svg"
alt="License: MIT">
</a>
<br />
<a href="https://paypal.me/Dschee/5EUR">
<img src="https://img.shields.io/badge/PayPal-Donate-orange.svg"
alt="PayPal: Donate">
</a>
<a href="https://github.com/sponsors/Jeehut">
<img src="https://img.shields.io/badge/GitHub-Become a sponsor-orange.svg"
alt="GitHub: Become a sponsor">
</a>
<a href="https://patreon.com/Jeehut">
<img src="https://img.shields.io/badge/Patreon-Become a patron-orange.svg"
alt="Patreon: Become a patron">
</a>
</p>

<p align="center">
<a href="#installation">Installation</a>
• <a href="#usage">Usage</a>
• <a href="#donation">Donation</a>
• <a href="https://github.com/Flinesoft/Microya/issues">Issues</a>
• <a href="#contributing">Contributing</a>
• <a href="#license">License</a>
</p>

# Microya

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

## Installation

Expand Down Expand Up @@ -103,7 +120,7 @@ extension MicrosoftTranslatorApi: JsonApi {
var path: String {
switch self {
case .languages:
return "/languages"
return "/languages"

case .translate:
return "/translate"
Expand All @@ -113,7 +130,7 @@ extension MicrosoftTranslatorApi: JsonApi {
var method: Method {
switch self {
case .languages:
return .get
return .get

case .translate:
return .post
Expand Down Expand Up @@ -151,7 +168,7 @@ extension MicrosoftTranslatorApi: JsonApi {
var headers: [String: String] {
switch self {
case .languages:
return [:]
return [:]

case .translate:
return [
Expand All @@ -165,7 +182,7 @@ extension MicrosoftTranslatorApi: JsonApi {

</details>

### Step 3: Calling your API endpoint with the result type
### Step 3: Calling your API endpoint with the Result type

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

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

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

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.
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.


## Donation

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)**.

Thank you very much for any donation, it really helps out a lot! 💯


## Contributing

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


## License
Expand Down

0 comments on commit 8c3927d

Please sign in to comment.