Skip to content

Commit 381d8e3

Browse files
committed
update API
1 parent bf260d0 commit 381d8e3

File tree

5 files changed

+66
-30
lines changed

5 files changed

+66
-30
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: objective-c
2+
osx_image: xcode8

Demo/Demo/Base.lproj/Main.storyboard

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
67
</dependencies>
78
<scenes>
8-
<!--View Controller-->
9+
<!--Joke List View Controller-->
910
<scene sceneID="tne-QT-ifu">
1011
<objects>
11-
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
12+
<viewController id="BYZ-38-t0r" customClass="JokeListViewController" sceneMemberID="viewController">
1213
<layoutGuides>
1314
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
1415
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1516
</layoutGuides>
1617
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
1819
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2021
</view>
2122
</viewController>
2223
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>

Demo/Demo/JokeList/JokeListViewController.m

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,47 @@
77
//
88

99
#import "JokeListViewController.h"
10+
#import "PSJokeListModel.h"
1011

1112
@interface JokeListViewController ()
1213

14+
@property (nonatomic, strong) PSJokeListModel *model;
15+
16+
1317
@end
1418

1519
@implementation JokeListViewController
1620

17-
- (void)viewDidLoad {
21+
#pragma mark - Public
22+
23+
#pragma mark - Life cycle
24+
- (void)viewDidLoad
25+
{
1826
[super viewDidLoad];
19-
// Do any additional setup after loading the view.
27+
[self.model fetchJokeList];
2028
}
2129

22-
- (void)didReceiveMemoryWarning {
23-
[super didReceiveMemoryWarning];
24-
// Dispose of any resources that can be recreated.
25-
}
30+
#pragma mark - IBAction
31+
2632

27-
/*
2833
#pragma mark - Navigation
2934

30-
// In a storyboard-based application, you will often want to do a little preparation before navigation
31-
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
32-
// Get the new view controller using [segue destinationViewController].
33-
// Pass the selected object to the new view controller.
35+
36+
#pragma mark - Delegate
37+
38+
39+
#pragma mark - Private Method
40+
41+
42+
#pragma mark - Getter and Setter
43+
44+
- (PSJokeListModel *)model
45+
{
46+
if (!_model)
47+
{
48+
_model = [[PSJokeListModel alloc] init];
49+
}
50+
return _model;
3451
}
35-
*/
3652

3753
@end

Demo/Demo/JokeList/PSJokeListModel.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ @implementation PSJokeListModel
1212

1313
- (void)fetchJokeList
1414
{
15-
[self.webService requestEasilyWithMethod:HTHTTPMethodGET
16-
path:@"api/4/section/2"
17-
parameters:nil
18-
businessSuccess:^(PSResponse * _Nonnull response) {
19-
// 做业务成功之后想做的事情
20-
} finally:^{
21-
// 做网络请求结束之后想做的事情
22-
}];
15+
[self.webService getEasilyWithPath:@"api/4/section/2"
16+
parameters:nil
17+
businessSuccess:^(PSResponse * _Nonnull response) {
18+
// 做业务成功之后想做的事情
19+
} finally:^{
20+
// 做网络请求结束之后想做的事情
21+
}];
2322
}
2423

2524
@end

HTWebService/HTWebService.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,39 @@ typedef void (^HTAlwaysExecuteBlock)();
7979

8080
#pragma mark - Core Method
8181

82+
/**
83+
* 简化请求,出错后框架会自动处理。
84+
* @param method HTTP Method
85+
* @param subPath API地址
86+
* @param parameters 参数
87+
* @param bizSuccessBlock 业务成功执行此block NONULL
88+
* @param bizFailureBlock 业务失败执行此block
89+
* @param reqFailureBlock 请求失败执行此block
90+
* @param alwaysExecuteBlock 如果非nil 则不论请求成功或者失败,都会执行
91+
*/
8292
- (void)requestEasilyWithMethod:(HTHTTPMethod)method
8393
path:(nonnull NSString *)subPath
8494
parameters:(nullable id)parameters
8595
businessSuccess:(nonnull HTBusinessSuccessBlock)bizSuccessBlock
8696
finally:(nullable HTAlwaysExecuteBlock)alwaysExecuteBlock;
8797

98+
99+
/**
100+
* 静默请求,出错后框架会吞掉错误。
101+
* @param method HTTP Method
102+
* @param subPath API地址
103+
* @param parameters 参数
104+
* @param bizSuccessBlock 业务成功执行此block NONULL
105+
* @param alwaysExecuteBlock 如果非nil 则不论请求成功或者失败,都会执行
106+
*/
88107
- (void)requestSilentlyWithMethod:(HTHTTPMethod)method
89108
path:(nonnull NSString *)subPath
90109
parameters:(nullable id)parameters
91110
businessSuccess:(nonnull HTBusinessSuccessBlock)bizSuccessBlock
92111
finally:(nullable HTAlwaysExecuteBlock)alwaysExecuteBlock;
93112

94113
/**
95-
* 自行选择 HTTP Method 进行请求
114+
* 完整的请求,框架不会统一处理错误。
96115
* @param method HTTP Method
97116
* @param subPath API地址
98117
* @param parameters 参数
@@ -109,9 +128,8 @@ typedef void (^HTAlwaysExecuteBlock)();
109128
requestFailure:(nullable HTRequestFailureBlock)reqFailureBlock
110129
finally:(nullable HTAlwaysExecuteBlock)alwaysExecuteBlock;
111130

112-
@end
113131

114-
@interface HTWebService (Convience)
132+
#pragma mark - Convience Call Method
115133

116134
/**
117135
* 简化版GET请求,只处理业务成功的状态。其他状态默认展现一下提示窗口。

0 commit comments

Comments
 (0)