Skip to content

Commit

Permalink
Merge pull request #205 from longbai/multizone
Browse files Browse the repository at this point in the history
multizone
  • Loading branch information
longbai authored Oct 11, 2016
2 parents ad2c730 + 3b587da commit 0c3344a
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 174 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Changelog

## 7.1.2 (2016-10-11)
## 增加
* 增加zone2

## 7.1.1 (2016-09-08)
## 改变
* 修正 happydns 调用函数
Expand Down
2 changes: 1 addition & 1 deletion Qiniu.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Qiniu'
s.version = '7.1.1'
s.version = '7.1.2'
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
s.homepage = 'https://github.com/qiniu/objc-sdk'
s.social_media_url = 'http://weibo.com/qiniutek'
Expand Down
6 changes: 6 additions & 0 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
DFF525371A626A3700D02BA1 /* QNHttpDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = DFF525361A626A3700D02BA1 /* QNHttpDelegate.h */; };
DFF525391A64079B00D02BA1 /* QNSessionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF525381A64079B00D02BA1 /* QNSessionTest.m */; };
DFFE0E6019E6575600D7A0FC /* QNFileRecorderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */; };
FDEA88661DAC10D000D037E5 /* QNAutoZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */; };
FDEA88671DAC10D000D037E5 /* QNAutoZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -193,6 +195,7 @@
DFF525361A626A3700D02BA1 /* QNHttpDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNHttpDelegate.h; sourceTree = "<group>"; };
DFF525381A64079B00D02BA1 /* QNSessionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionTest.m; sourceTree = "<group>"; };
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNFileRecorderTest.m; sourceTree = "<group>"; };
FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNAutoZoneTest.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -378,6 +381,7 @@
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */,
DFF525381A64079B00D02BA1 /* QNSessionTest.m */,
DF437CDE1B243A2C0099587B /* QNUpTokenTest.m */,
FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */,
);
path = QiniuSDKTests;
sourceTree = SOURCE_ROOT;
Expand Down Expand Up @@ -760,6 +764,7 @@
DF293C9719DB865800799011 /* QNCrc32Test.m in Sources */,
DFA9B64519DFE43500A15FD1 /* QNTempFile.m in Sources */,
DFF525391A64079B00D02BA1 /* QNSessionTest.m in Sources */,
FDEA88661DAC10D000D037E5 /* QNAutoZoneTest.m in Sources */,
DFA9B63F19DFD8C900A15FD1 /* QNEtagTest.m in Sources */,
DF2CDE7119DAE90300CE01FB /* QNBase64Test.m in Sources */,
);
Expand Down Expand Up @@ -803,6 +808,7 @@
DF0A032B1B3BAC6E00E3778C /* QNEtagTest.m in Sources */,
DF0A032C1B3BAC6E00E3778C /* QNTempFile.m in Sources */,
DF0A032D1B3BAC6E00E3778C /* QNFileRecorderTest.m in Sources */,
FDEA88671DAC10D000D037E5 /* QNAutoZoneTest.m in Sources */,
DF0A032F1B3BAC6E00E3778C /* QNSessionTest.m in Sources */,
DF0A03301B3BAC6E00E3778C /* QNUpTokenTest.m in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Common/QNVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
/**
* sdk 版本
*/
static const NSString *kQiniuVersion = @"7.1.1";
static const NSString *kQiniuVersion = @"7.1.2";
4 changes: 4 additions & 0 deletions QiniuSDK/Http/QNSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
withProgressBlock:(QNInternalProgressBlock)progressBlock
withCancelBlock:(QNCancelBlock)cancelBlock;

- (void)get:(NSString *)url
withHeaders:(NSDictionary *)headers
withCompleteBlock:(QNCompleteBlock)completeBlock;

@end

#endif
30 changes: 30 additions & 0 deletions QiniuSDK/Http/QNSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,36 @@ - (void)post:(NSString *)url
});
}

- (void)get:(NSString *)url
withHeaders:(NSDictionary *)headers
withCompleteBlock:(QNCompleteBlock)completeBlock {
QNAsyncRun(^{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSData* s = [@"{}" dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *resp = nil;
QNResponseInfo* info;
if (error == nil) {
info = [QNSessionManager buildResponseInfo:httpResponse withError:nil withDuration:0 withResponse:s withHost:@"" withIp:@""];
if (info.isOK) {
resp = responseObject;
}
} else {
info = [QNSessionManager buildResponseInfo:httpResponse withError:error withDuration:0 withResponse:s withHost:@"" withIp:@""];
}

completeBlock(info, resp);
}];
[dataTask resume];
});
}

@end

#endif
8 changes: 4 additions & 4 deletions QiniuSDK/Http/QNUserAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "QNUserAgent.h"
#import "QNVersion.h"

static NSString *clientId(void) {
static NSString *qn_clientId(void) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED
NSString *s = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
if (s == nil) {
Expand All @@ -31,7 +31,7 @@
#endif
}

static NSString *userAgent(NSString *id) {
static NSString *qn_userAgent(NSString *id) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED
return [NSString stringWithFormat:@"QiniuObject-C/%@ (%@; iOS %@; %@)", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], id];
#else
Expand All @@ -51,8 +51,8 @@ - (NSString *)description {

- (instancetype)init {
if (self = [super init]) {
_id = clientId();
_ua = userAgent(_id);
_id = qn_clientId();
_ua = qn_userAgent(_id);
}
return self;
}
Expand Down
65 changes: 44 additions & 21 deletions QiniuSDK/Storage/QNConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef NSString * (^QNUrlConvert)(NSString *url);
@class QNConfigurationBuilder;
@class QNDnsManager;
@class QNServiceAddress;
@class QNZone;
/**
* Builder block
*
Expand All @@ -37,14 +38,9 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
@interface QNConfiguration : NSObject

/**
* 默认上传服务器地址
*/
@property (copy, nonatomic, readonly) QNServiceAddress *up;

/**
* 备用上传服务器地址
* 存储区域
*/
@property (copy, nonatomic, readonly) QNServiceAddress *upBackup;
@property (copy, nonatomic, readonly) QNZone *zone;

/**
* 断点上传时的分片大小
Expand Down Expand Up @@ -94,29 +90,21 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);

@end

typedef void (^QNPrequeryReturn)(int code);

@class QNUpToken;

@interface QNZone : NSObject

/**
* 默认上传服务器地址
*/
@property (nonatomic, readonly) QNServiceAddress *up;
- (QNServiceAddress *)up:(QNUpToken*)token;

/**
* 备用上传服务器地址
*/
@property (nonatomic, readonly) QNServiceAddress *upBackup;

/**
* Zone初始化方法
*
* @param upHost 默认上传服务器地址
* @param upHostBackup 备用上传服务器地址
* @param upIp 备用上传IP
*
* @return Zone实例
*/
- (instancetype)initWithUp:(QNServiceAddress *)up
upBackup:(QNServiceAddress *)upBackup;
- (QNServiceAddress *)upBackup:(QNUpToken*)token;

/**
* zone 0
Expand All @@ -132,6 +120,41 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
*/
+ (instancetype)zone1;

/**
* zone 2
*
* @return 实例
*/
+ (instancetype)zone2;

- (void)preQuery:(QNUpToken*)token
on:(QNPrequeryReturn)ret;

+ (void)addIpToDns:(QNDnsManager*)dns;

@end

@interface QNFixedZone : QNZone
/**
* Zone初始化方法
*
* @param upHost 默认上传服务器地址
* @param upHostBackup 备用上传服务器地址
* @param upIp 备用上传IP
*
* @return Zone实例
*/
- (instancetype)initWithUp:(QNServiceAddress *)up
upBackup:(QNServiceAddress *)upBackup;

@end

@interface QNAutoZone : QNZone

- (instancetype)initWithHttps:(BOOL)flag
dns:(QNDnsManager*)dns;


@end

@interface QNConfigurationBuilder : NSObject
Expand Down
Loading

0 comments on commit 0c3344a

Please sign in to comment.