Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApexyLoader library #16

Merged
merged 7 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Apexy.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Apexy"
s.version = "1.2.0"
s.version = "1.3.0"
s.summary = "HTTP transport library"
s.homepage = "https://github.com/RedMadRobot/apexy-ios"
s.license = { :type => "MIT"}
Expand Down Expand Up @@ -35,6 +35,11 @@ Pod::Spec.new do |s|
sp.dependency "RxSwift"
end

s.subspec 'Loader' do |sp|
sp.source_files = "Sources/ApexyLoader/*.swift"
sp.dependency "Apexy/Core"
end

s.default_subspecs = ["Alamofire"]

end
497 changes: 497 additions & 0 deletions ApexyLoaderExample/ApexyLoaderExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "Alamofire",
"repositoryURL": "https://github.com/Alamofire/Alamofire.git",
"state": {
"branch": null,
"revision": "eaf6e622dd41b07b251d8f01752eab31bc811493",
"version": "5.4.1"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
"state": {
"branch": null,
"revision": "254617dd7fae0c45319ba5fbea435bf4d0e15b5d",
"version": "5.1.2"
}
}
]
},
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// AppDelegate.swift
// ApexyLoaderExample
//
// Created by Daniil Subbotin on 04.03.2021.
//

import UIKit

@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let window = UIWindow()
self.window = window

let fetchVC = FetchViewController()
fetchVC.tabBarItem = UITabBarItem(
title: "Fetch",
image: UIImage(systemName: "arrow.down.square.fill"),
tag: 0)

let resultVC = ResultViewController()
resultVC.tabBarItem = UITabBarItem(
title: "Result",
image: UIImage(systemName: "list.bullet"),
tag: 1)

let tbc = UITabBarController()
tbc.viewControllers = [fetchVC, resultVC]

window.frame = UIScreen.main.bounds
window.rootViewController = tbc
window.makeKeyAndVisible()

return true
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Apexy
import Foundation

/// Base Endpoint for application remote resource.
///
/// Contains shared logic for all endpoints in app.
protocol BaseEndpoint: Endpoint where Content: Decodable {
/// Content wrapper.
associatedtype Root: Decodable = Content

/// Extract content from root.
func content(from root: Root) -> Content
}

extension BaseEndpoint where Root == Content {
func content(from root: Root) -> Content { return root }
}

extension BaseEndpoint {

public func content(from response: URLResponse?, with body: Data) throws -> Content {
let resource = try JSONDecoder.default.decode(Root.self, from: body)
return content(from: resource)
}
}

extension JSONDecoder {
internal static let `default`: JSONDecoder = {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
return decoder
}()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// OrganisationEndpoint.swift
// ApexyLoaderExample
//
// Created by Daniil Subbotin on 04.03.2021.
//

import Apexy
import Foundation

struct OrganisationEndpoint: BaseEndpoint {

typealias Content = Organisation

func makeRequest() -> URLRequest {
let url = URL(string: "orgs/RedMadRobot")!
return URLRequest(url: url)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// RepositoriesEndpoint.swift
// ApexyLoaderExample
//
// Created by Daniil Subbotin on 04.03.2021.
//

import Apexy
import Foundation

/// List of all Redmadrobot repositories on GitHub
struct RepositoriesEndpoint: BaseEndpoint {

typealias Content = [Repository]

func makeRequest() -> URLRequest {
let url = URL(string: "orgs/RedMadRobot/repos")!
return URLRequest(url: url)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// RepositoriesLoader.swift
// ApexyLoaderExample
//
// Created by Daniil Subbotin on 04.03.2021.
//

import Foundation
import ApexyLoader

protocol OrganisationLoading: ContentLoading {
var state: LoadingState<Organisation> { get }
}

final class OrganisationLoader: WebLoader<Organisation>, OrganisationLoading {
func load() {
guard startLoading() else { return }
request(OrganisationEndpoint()) { result in
// imitation of waiting for the request for 3 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
self.finishLoading(result)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// RepositoriesLoader.swift
// ApexyLoaderExample
//
// Created by Daniil Subbotin on 04.03.2021.
//

import Foundation
import ApexyLoader

protocol RepoLoading: ContentLoading {
var state: LoadingState<[Repository]> { get }
}

final class RepositoriesLoader: WebLoader<[Repository]>, RepoLoading {
func load() {
guard startLoading() else { return }
request(RepositoriesEndpoint()) { result in
// imitation of waiting for the request for 5 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
self.finishLoading(result)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Organisation.swift
// ApexyLoaderExample
//
// Created by Daniil Subbotin on 09.03.2021.
//

struct Organisation: Decodable {
let name: String
}