82 lines
1.8 KiB
Objective-C
82 lines
1.8 KiB
Objective-C
//
|
|
// GiGaAPIRequest.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/8/15.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "GiGaAPIRequest.h"
|
|
#import "GiGaServerConfig.h"
|
|
@implementation GiGaAPIRequest
|
|
|
|
- (id)initWithDelegate:(id<GiGaApiRquestDelegate>)delegate
|
|
{
|
|
if (self = [super init]) {
|
|
self.params = [NSMutableArray array];
|
|
self.delegate = delegate;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
//默认Get访问
|
|
- (GiGaRequestTyp)requestType
|
|
{
|
|
return kRequestTypeGet;
|
|
}
|
|
|
|
//默认超时时间
|
|
- (NSTimeInterval)timeout
|
|
{
|
|
return DEFALUT_APIREQUEST_TIMEOUT;
|
|
}
|
|
|
|
//服务器地址
|
|
-(NSString *)serviceUrl{
|
|
return [GiGaServerConfig getMainUrl];
|
|
}
|
|
|
|
/** 拼接的请求地址 */
|
|
|
|
//
|
|
- (NSString *)fullUrl
|
|
{
|
|
// 服务器地址 和 接口名
|
|
NSString *url = [NSString stringWithFormat:@"%@",self.serviceUrl];
|
|
|
|
return url;
|
|
}
|
|
// 数据请求完成的 回调
|
|
- (void)callBackFinishedWithDictionary:(NSDictionary *)dic
|
|
{
|
|
// 处理 responseObject
|
|
GiGaAPIResult *resu = [[GiGaAPIResult alloc] initWithDictionary:dic];
|
|
// error ID = 0
|
|
if (resu.success) {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(serverApiFinishedSuccessed: result:)]) {
|
|
//
|
|
[self.delegate serverApiFinishedSuccessed:self result:resu];
|
|
}
|
|
// error ID = 1
|
|
} else {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(serverApiFinishedFailed:result:)]) {
|
|
[self.delegate serverApiFinishedFailed:self result:resu];
|
|
}
|
|
}
|
|
}
|
|
|
|
// 数据请求失败的回调
|
|
- (void)callBackFailed:(NSError *)error
|
|
{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(serverApiRequestFailed:error:)]) {
|
|
[self.delegate serverApiRequestFailed:self error:error];
|
|
}
|
|
}
|
|
|
|
// 拼接的基本参数
|
|
- (void)appendBaseParams
|
|
{
|
|
|
|
}
|
|
@end
|