diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 4346d44..d613881 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aeefc3f..7565209 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,10 @@ # 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 @@ -12,8 +12,6 @@ Before you start developing, please make sure you have the following tools insta - Xcode 10.0+ - [SwiftLint](https://github.com/realm/SwiftLint) -- [ProjLint](https://github.com/JamitLabs/ProjLint) -- [Beak](https://github.com/yonaskolb/Beak) ### Commit Messages diff --git a/Frameworks/Microya/Models/JsonApi.swift b/Frameworks/Microya/Models/JsonApi.swift index 0c42d75..6fdef3d 100644 --- a/Frameworks/Microya/Models/JsonApi.swift +++ b/Frameworks/Microya/Models/JsonApi.swift @@ -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(type: ResultType.Type) -> Result { let dispatchGroup = DispatchGroup() dispatchGroup.enter() @@ -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 + } +} diff --git a/Frameworks/SupportingFiles/Info.plist b/Frameworks/SupportingFiles/Info.plist index 84545a2..23d96cb 100755 --- a/Frameworks/SupportingFiles/Info.plist +++ b/Frameworks/SupportingFiles/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.1 + 0.2.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/Logo.png b/Logo.png new file mode 100644 index 0000000..6cd7baa Binary files /dev/null and b/Logo.png differ diff --git a/Microya.podspec b/Microya.podspec index 6bc8b43..a59af30 100755 --- a/Microya.podspec +++ b/Microya.podspec @@ -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" => "cocoapods@cihatguenduez.de" } - 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" diff --git a/README.md b/README.md index 8248499..863186d 100755 --- a/README.md +++ b/README.md @@ -1,30 +1,47 @@

- +

- Build Status - + codebeat badge + + Version: 0.2.0 Swift: 4.2 Platforms: iOS | macOS | tvOS | watchOS - + License: MIT +
+ + PayPal: Donate + + + GitHub: Become a sponsor + + + Patreon: Become a patron +

InstallationUsage + • DonationIssuesContributingLicense @@ -32,7 +49,7 @@ # 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 @@ -103,7 +120,7 @@ extension MicrosoftTranslatorApi: JsonApi { var path: String { switch self { case .languages: - return "/languages" + return "/languages" case .translate: return "/translate" @@ -113,7 +130,7 @@ extension MicrosoftTranslatorApi: JsonApi { var method: Method { switch self { case .languages: - return .get + return .get case .translate: return .post @@ -151,7 +168,7 @@ extension MicrosoftTranslatorApi: JsonApi { var headers: [String: String] { switch self { case .languages: - return [:] + return [:] case .translate: return [ @@ -165,7 +182,7 @@ extension MicrosoftTranslatorApi: JsonApi { -### 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: @@ -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