Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z committed Jul 22, 2020
2 parents 7bd5c11 + 387a262 commit 3e02008
Show file tree
Hide file tree
Showing 50 changed files with 1,873 additions and 399 deletions.
1 change: 1 addition & 0 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ STAGE_MAIN() {
pod install
XC_TestMac
XC_TestAutoIOS "Test-iOS"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV"
else
logError "Unexpected CI task: $RFCI_TASK"
fi
Expand Down
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
language: objective-c
sudo: false
os: osx
cache: cocoapods
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
- LANGUAGE=en_US.UTF-8
- RFCI_PRODUCT_NAME="RFAPI"
- RFWorkspace="RFAPI.xcworkspace"
matrix:
jobs:
include:
- osx_image: xcode11.3
- osx_image: xcode11.4
env: RFCI_TASK="POD_LINT"
- osx_image: xcode10
env:
Expand Down
66 changes: 66 additions & 0 deletions Documents/Cookbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# RFAPI Cookbook

## URL 拼接

RFAPIDefine.path 如果是带 scheme 的完整 URL,将直接用这个 URL;否则会先与 pathPrefix 直接进行字符串拼接,并相对 baseURL 生成最终 URL。

baseURL 会依次从当前规则、默认规则、RFAPI 属性中取。baseURL host 后面如果有其他 path,应以「/」结尾,如 `http://example.com/base` 实际相当于 `http://example.com`,正确的应是 `http://example.com/base/`

RFAPIDefine.path 支持用花括号定义参数,如 `user/{user_id}/profile`,传参时带入 `user_id: 123`,则最终 URL 会变成 `user/123/profile`

## 传参

请求的参数通过 context 的 `parameters` 属性传入:

```swift
api.request(name: "some api") { c in
c.parameters = ["foo": "bar", "number": 456, "bool": true]
}
```

如果整个参数是数组,通过 `RFAPIRequestArrayParameterKey` 传入:

```swift
api.request(name: "some api") { c in
c.parameters = [RFAPIRequestArrayParameterKey: [1, 2, 3]]
}
```

如果 HTTP body 是 `multipart/form-data` 格式的,可通过 context 的 `formData` 构建数据。

```swift
api.request(name: "some api") { c in
c.formData = { formData in
try? formData.appendPart(withFileURL: fileUrl, name: "field1")
formData.appendPart(withForm: someData, name: "field2")
}
}
```

## Authentication

接口定义(RFAPIDefine) `needsAuthorization``true` 的接口会自动附加 `RFAPIDefineManager` 定义的 HTTP 头(authorizationHeader)和参数(authorizationParameters)。

设置方法为:

```swift
let api = ... // RFAPI instance
api.defineManager.authorizationHeader["Authorization"] = "Custom Credential"
api.defineManager.authorizationParameters["Custom Parameter"] = "Custom Value"
```

URLCredential 因接口未暴露暂不支持。

## 添加 HTTP header

在请求中附加 HTTP 头有多种方式:

* 如需集中式的处理,可通过重载 `RFAPI``preprocessingRequest(parametersRef:httpHeadersRef:parameters:define:context:)``finalizeSerializedRequest(_:define:context:)` 方法进行修改;
* 通过接口定义(RFAPIDefine)的 `HTTPRequestHeaders` 属性,如果接口定义中设置了该属性,会使用自己的(不会与默认定义合并),否则会使用默认定义(RFAPIDefineManager.defaultDefine)的;
* 通过 context 传入 `HTTPHeaders`,与其他方式设置的头进行合并,这种方式优先级最高,会覆盖接口定义和认证头。

## 错误处理

创建请求时可以通过 context 设置请求失败的回调(failure),除此之外,重载 `RFAPI``generalHandlerForError(_:define:task:failure:)` 方法可以集中处理错误。

[一个示例](https://github.com/BB9z/iOS-Project-Template/tree/4.1/App/Networking/API.swift#L63):对系统错误进行包装,token 失效登出,创建请求时不定义错误处理默认报错。
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RFAPI v2 升级指南

> *Because there should be no non-Chinese developers using this library before, this guide is not available in English at this time.*
> *Because there should be no non-Chinese developers using this library before, this guide is not available in English.*
v1 到 v2 几乎全部重写,内部变化很大,但是实际项目需要调整的地方应该不多。

Expand Down Expand Up @@ -44,5 +44,4 @@ v1 请求有两个方法,正常请求和表单上传请求,正常请求有

## 国际化

// todo
<!-- v1 的很多错误信息是硬编码在代码中的 -->
v1 的错误信息是硬编码在代码中的,且是中文;现在可以在 app 中默认的 Localizable.strings 定义。
4 changes: 0 additions & 4 deletions Documents/design.md

This file was deleted.

14 changes: 0 additions & 14 deletions Example/Shared/Models/RFDTestEntity.h

This file was deleted.

18 changes: 0 additions & 18 deletions Example/Shared/Models/RFDTestEntity.m

This file was deleted.

24 changes: 24 additions & 0 deletions Example/Shared/Models/TestEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// TestEntity.swift
// Example-iOS
//
// Created by BB9z on 2020/3/29.
// Copyright © 2020 RFUI. All rights reserved.
//

import Foundation

@objc(RFDTestEntity)
class RFDTestEntity : JSONModel {
@objc var uid: Int64 = -1
@objc var name: String?

override class func keyMapper() -> JSONKeyMapper! {
return JSONKeyMapper(modelToJSONDictionary: [#keyPath(RFDTestEntity.uid) : "id"])
}

override class func propertyIsOptional(_ propertyName: String!) -> Bool {
// All property is optional.
return true
}
}
1 change: 1 addition & 0 deletions Example/Shared/OCBridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#import <AFNetworking/AFURLRequestSerialization.h>
#import <AFNetworking/AFURLResponseSerialization.h>
#import <JSONModel/JSONModel.h>
#import <RFAPI/RFAPI.h>
#import <RFAPI/RFAPIDefineConfigFile.h>
#import <RFAPI/RFAPIJSONModelTransformer.h>
Expand Down
31 changes: 0 additions & 31 deletions Example/iOS-Swift/Base.lproj/LaunchScreen.storyboard

This file was deleted.

File renamed without changes.
51 changes: 51 additions & 0 deletions Example/iOS-Swift/Launching/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
<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"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="18" translatesAutoresizingMaskIntoConstraints="NO" id="RZF-Zt-LQk">
<rect key="frame" x="155" y="234.5" width="65" height="65"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="RFAPI" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0dB-em-eZT">
<rect key="frame" x="0.0" y="0.0" width="65" height="26.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle2"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Example" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vCa-yw-B28">
<rect key="frame" x="0.0" y="44.5" width="65" height="20.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="RZF-Zt-LQk" firstAttribute="centerX" secondItem="fZj-Pm-80C" secondAttribute="centerX" id="V71-TF-DHL"/>
<constraint firstItem="RZF-Zt-LQk" firstAttribute="centerY" secondItem="fZj-Pm-80C" secondAttribute="centerY" multiplier="0.8" id="eAB-Up-kcN"/>
<constraint firstItem="RZF-Zt-LQk" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="fZj-Pm-80C" secondAttribute="leading" constant="20" id="gsS-en-wrg"/>
</constraints>
<viewLayoutGuide key="safeArea" id="fZj-Pm-80C"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="47.200000000000003" y="278.41079460269867"/>
</scene>
</scenes>
</document>
51 changes: 51 additions & 0 deletions Example/iOS-Swift/Launching/LaunchScreen_zh-Hans.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
<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"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="18" translatesAutoresizingMaskIntoConstraints="NO" id="RZF-Zt-LQk">
<rect key="frame" x="153" y="234.5" width="69.5" height="65"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="RFAPI" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0dB-em-eZT">
<rect key="frame" x="0.0" y="0.0" width="69.5" height="26.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle2"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="演示项目" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vCa-yw-B28">
<rect key="frame" x="0.0" y="44.5" width="69.5" height="20.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="RZF-Zt-LQk" firstAttribute="centerX" secondItem="fZj-Pm-80C" secondAttribute="centerX" id="V71-TF-DHL"/>
<constraint firstItem="RZF-Zt-LQk" firstAttribute="centerY" secondItem="fZj-Pm-80C" secondAttribute="centerY" multiplier="0.8" id="eAB-Up-kcN"/>
<constraint firstItem="RZF-Zt-LQk" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="fZj-Pm-80C" secondAttribute="leading" constant="20" id="gsS-en-wrg"/>
</constraints>
<viewLayoutGuide key="safeArea" id="fZj-Pm-80C"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="47.200000000000003" y="278.41079460269867"/>
</scene>
</scenes>
</document>
Loading

0 comments on commit 3e02008

Please sign in to comment.