Skip to content

Commit 55cd86b

Browse files
author
Qiming Yuan
committed
Expose DBRoute host as an enum
1 parent d734a46 commit 55cd86b

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

Source/ObjectiveDropboxOfficial/Shared/Handwritten/Networking/DBTransportBaseClient.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "DBStoneBase.h"
1414
#import "DBTransportBaseClient.h"
1515
#import "DBTransportBaseConfig.h"
16+
#import "DBTransportBaseHostnameConfig.h"
1617

1718
#pragma mark - Internal serialization helpers
1819

@@ -130,7 +131,7 @@ + (NSMutableURLRequest *)requestWithHeaders:(NSDictionary *)httpHeaders
130131
}
131132

132133
- (NSURL *)urlWithRoute:(DBRoute *)route {
133-
NSString *routePrefix = [_hostnameConfig apiV2PrefixWithRouteType:route.attrs[@"host"]];
134+
NSString *routePrefix = [_hostnameConfig apiV2PrefixWithRoute:route];
134135
return [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@", routePrefix, route.namespace_, route.name]];
135136
}
136137

Source/ObjectiveDropboxOfficial/Shared/Handwritten/Networking/DBTransportBaseHostnameConfig.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@
33
///
44

55
#import <Foundation/Foundation.h>
6+
#import "DBStoneBase.h"
7+
8+
/// Enum of Dropbox API hosts.
9+
typedef NS_ENUM(NSUInteger, DBRouteHost) {
10+
DBRouteHostUnknown = 0,
11+
DBRouteHostApi,
12+
DBRouteHostContent,
13+
DBRouteHostNotify,
14+
};
615

716
NS_ASSUME_NONNULL_BEGIN
817

18+
@interface DBRoute (DropboxHost)
19+
20+
/// @return which host this route points to
21+
@property (nonatomic, readonly) DBRouteHost host;
22+
23+
@end
24+
925
///
1026
/// Configuration class that defines the different hostnames that the Dropbox SDK uses
1127
///
@@ -38,12 +54,12 @@ NS_ASSUME_NONNULL_BEGIN
3854
///
3955
/// Returns the prefix to use for API calls to the given route type.
4056
///
41-
/// @param routeType the type of route to get a prefix for.
42-
/// Currently the valid values are: "api", "content", and "notify".
57+
/// @param route the type of route to get a prefix for.
58+
/// Currently the valid hosts are: "api", "content", and "notify".
4359
///
4460
/// @return An absolute URL prefix, typically "https://<hostname>/2" or nil if an invalid route type is provided.
4561
///
46-
- (nullable NSString *)apiV2PrefixWithRouteType:(NSString *)routeType;
62+
- (nullable NSString *)apiV2PrefixWithRoute:(DBRoute *)route;
4763

4864
@end
4965

Source/ObjectiveDropboxOfficial/Shared/Handwritten/Networking/DBTransportBaseHostnameConfig.m

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44

55
#import "DBTransportBaseHostnameConfig.h"
66
#import "DBSDKConstants.h"
7+
#import "DBStoneBase.h"
8+
9+
@implementation DBRoute (DropboxHost)
10+
11+
- (DBRouteHost)host {
12+
NSString *routeHost = self.attrs[@"host"];
13+
if ([routeHost isEqualToString:@"api"]) {
14+
return DBRouteHostApi;
15+
}
16+
if ([routeHost isEqualToString:@"content"]) {
17+
return DBRouteHostContent;
18+
}
19+
if ([routeHost isEqualToString:@"notify"]) {
20+
return DBRouteHostNotify;
21+
}
22+
return DBRouteHostUnknown;
23+
}
24+
25+
@end
726

827
@implementation DBTransportBaseHostnameConfig
928

@@ -35,15 +54,16 @@ - (instancetype)initWithMeta:(NSString *)meta
3554
return self;
3655
}
3756

38-
- (nullable NSString *)apiV2PrefixWithRouteType:(NSString *)routeType {
39-
if ([routeType isEqualToString:@"api"]) {
40-
return [NSString stringWithFormat:@"https://%@/2", _api];
41-
} else if ([routeType isEqualToString:@"content"]) {
42-
return [NSString stringWithFormat:@"https://%@/2", _content];
43-
} else if ([routeType isEqualToString:@"notify"]) {
44-
return [NSString stringWithFormat:@"https://%@/2", _notify];
45-
} else {
46-
return nil;
57+
- (nullable NSString *)apiV2PrefixWithRoute:(DBRoute *)route {
58+
switch (route.host) {
59+
case DBRouteHostApi:
60+
return [NSString stringWithFormat:@"https://%@/2", _api];
61+
case DBRouteHostContent:
62+
return [NSString stringWithFormat:@"https://%@/2", _content];
63+
case DBRouteHostNotify:
64+
return [NSString stringWithFormat:@"https://%@/2", _notify];
65+
case DBRouteHostUnknown:
66+
return nil;
4767
}
4868
}
4969

Source/ObjectiveDropboxOfficial/Shared/Handwritten/Networking/DBTransportDefaultClient.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "DBStoneBase.h"
1010
#import "DBTasksImpl.h"
1111
#import "DBTransportBaseClient+Internal.h"
12+
#import "DBTransportBaseHostnameConfig.h"
1213
#import "DBTransportDefaultConfig.h"
1314

1415
@implementation DBTransportDefaultClient {
@@ -98,7 +99,7 @@ - (DBRpcTaskImpl *)requestRpc:(DBRoute *)route arg:(id<DBSerializable>)arg {
9899
NSURLSession *sessionToUse = _session;
99100

100101
// longpoll requests have a much longer timeout period than other requests
101-
if ([route.attrs[@"host"] isEqualToString:@"notify"]) {
102+
if (route.host == DBRouteHostNotify) {
102103
sessionToUse = _longpollSession;
103104
}
104105

0 commit comments

Comments
 (0)