Skip to content

Commit 3e02008

Browse files
committed
Merge branch 'develop'
2 parents 7bd5c11 + 387a262 commit 3e02008

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1873
-399
lines changed

.travis.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ STAGE_MAIN() {
9292
pod install
9393
XC_TestMac
9494
XC_TestAutoIOS "Test-iOS"
95+
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV"
9596
else
9697
logError "Unexpected CI task: $RFCI_TASK"
9798
fi

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
language: objective-c
2-
sudo: false
2+
os: osx
33
cache: cocoapods
44
env:
55
global:
66
- LC_CTYPE=en_US.UTF-8
77
- LANG=en_US.UTF-8
88
- LANGUAGE=en_US.UTF-8
99
- RFCI_PRODUCT_NAME="RFAPI"
10-
- RFWorkspace="RFAPI.xcworkspace"
11-
matrix:
10+
jobs:
1211
include:
13-
- osx_image: xcode11.3
12+
- osx_image: xcode11.4
1413
env: RFCI_TASK="POD_LINT"
1514
- osx_image: xcode10
1615
env:

Documents/Cookbook.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# RFAPI Cookbook
2+
3+
## URL 拼接
4+
5+
RFAPIDefine.path 如果是带 scheme 的完整 URL,将直接用这个 URL;否则会先与 pathPrefix 直接进行字符串拼接,并相对 baseURL 生成最终 URL。
6+
7+
baseURL 会依次从当前规则、默认规则、RFAPI 属性中取。baseURL host 后面如果有其他 path,应以「/」结尾,如 `http://example.com/base` 实际相当于 `http://example.com`,正确的应是 `http://example.com/base/`
8+
9+
RFAPIDefine.path 支持用花括号定义参数,如 `user/{user_id}/profile`,传参时带入 `user_id: 123`,则最终 URL 会变成 `user/123/profile`
10+
11+
## 传参
12+
13+
请求的参数通过 context 的 `parameters` 属性传入:
14+
15+
```swift
16+
api.request(name: "some api") { c in
17+
c.parameters = ["foo": "bar", "number": 456, "bool": true]
18+
}
19+
```
20+
21+
如果整个参数是数组,通过 `RFAPIRequestArrayParameterKey` 传入:
22+
23+
```swift
24+
api.request(name: "some api") { c in
25+
c.parameters = [RFAPIRequestArrayParameterKey: [1, 2, 3]]
26+
}
27+
```
28+
29+
如果 HTTP body 是 `multipart/form-data` 格式的,可通过 context 的 `formData` 构建数据。
30+
31+
```swift
32+
api.request(name: "some api") { c in
33+
c.formData = { formData in
34+
try? formData.appendPart(withFileURL: fileUrl, name: "field1")
35+
formData.appendPart(withForm: someData, name: "field2")
36+
}
37+
}
38+
```
39+
40+
## Authentication
41+
42+
接口定义(RFAPIDefine) `needsAuthorization``true` 的接口会自动附加 `RFAPIDefineManager` 定义的 HTTP 头(authorizationHeader)和参数(authorizationParameters)。
43+
44+
设置方法为:
45+
46+
```swift
47+
let api = ... // RFAPI instance
48+
api.defineManager.authorizationHeader["Authorization"] = "Custom Credential"
49+
api.defineManager.authorizationParameters["Custom Parameter"] = "Custom Value"
50+
```
51+
52+
URLCredential 因接口未暴露暂不支持。
53+
54+
## 添加 HTTP header
55+
56+
在请求中附加 HTTP 头有多种方式:
57+
58+
* 如需集中式的处理,可通过重载 `RFAPI``preprocessingRequest(parametersRef:httpHeadersRef:parameters:define:context:)``finalizeSerializedRequest(_:define:context:)` 方法进行修改;
59+
* 通过接口定义(RFAPIDefine)的 `HTTPRequestHeaders` 属性,如果接口定义中设置了该属性,会使用自己的(不会与默认定义合并),否则会使用默认定义(RFAPIDefineManager.defaultDefine)的;
60+
* 通过 context 传入 `HTTPHeaders`,与其他方式设置的头进行合并,这种方式优先级最高,会覆盖接口定义和认证头。
61+
62+
## 错误处理
63+
64+
创建请求时可以通过 context 设置请求失败的回调(failure),除此之外,重载 `RFAPI``generalHandlerForError(_:define:task:failure:)` 方法可以集中处理错误。
65+
66+
[一个示例](https://github.com/BB9z/iOS-Project-Template/tree/4.1/App/Networking/API.swift#L63):对系统错误进行包装,token 失效登出,创建请求时不定义错误处理默认报错。
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RFAPI v2 升级指南
22

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

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

4545
## 国际化
4646

47-
// todo
48-
<!-- v1 的很多错误信息是硬编码在代码中的 -->
47+
v1 的错误信息是硬编码在代码中的,且是中文;现在可以在 app 中默认的 Localizable.strings 定义。

Documents/design.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

Example/Shared/Models/RFDTestEntity.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

Example/Shared/Models/RFDTestEntity.m

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// TestEntity.swift
3+
// Example-iOS
4+
//
5+
// Created by BB9z on 2020/3/29.
6+
// Copyright © 2020 RFUI. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
@objc(RFDTestEntity)
12+
class RFDTestEntity : JSONModel {
13+
@objc var uid: Int64 = -1
14+
@objc var name: String?
15+
16+
override class func keyMapper() -> JSONKeyMapper! {
17+
return JSONKeyMapper(modelToJSONDictionary: [#keyPath(RFDTestEntity.uid) : "id"])
18+
}
19+
20+
override class func propertyIsOptional(_ propertyName: String!) -> Bool {
21+
// All property is optional.
22+
return true
23+
}
24+
}

Example/Shared/OCBridging-Header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import <AFNetworking/AFURLRequestSerialization.h>
66
#import <AFNetworking/AFURLResponseSerialization.h>
7+
#import <JSONModel/JSONModel.h>
78
#import <RFAPI/RFAPI.h>
89
#import <RFAPI/RFAPIDefineConfigFile.h>
910
#import <RFAPI/RFAPIJSONModelTransformer.h>

Example/iOS-Swift/Base.lproj/LaunchScreen.storyboard

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)