Skip to content

Commit

Permalink
add module demo
Browse files Browse the repository at this point in the history
  • Loading branch information
李杰 committed Sep 15, 2017
1 parent 4044106 commit 6af6bd7
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion JJNetwork/Demo/DomainModule.h
Expand Up @@ -9,6 +9,6 @@
#import <Foundation/Foundation.h>
#import "APIModule.h"

@interface DomainModule : NSObject<APIModule>
@interface DomainModule : NSObject<APIDominIPModule>

@end
2 changes: 1 addition & 1 deletion JJNetwork/Demo/DomainModule.m
Expand Up @@ -10,7 +10,7 @@

@implementation DomainModule

- (NSDictionary*)keyMap{
- (NSDictionary*)domainIPData{
return @{@"api.imemo8.com":@"218.244.140.1"};
}

Expand Down
2 changes: 1 addition & 1 deletion JJNetwork/Demo/HttpHeadModule.h
Expand Up @@ -9,6 +9,6 @@
#import <Foundation/Foundation.h>
#import "APIModule.h"

@interface HttpHeadModule : NSObject<APIModule>
@interface HttpHeadModule : NSObject<APIHttpHeadModule>

@end
2 changes: 1 addition & 1 deletion JJNetwork/Demo/HttpHeadModule.m
Expand Up @@ -10,7 +10,7 @@

@implementation HttpHeadModule

- (NSDictionary*)keyMap{
- (NSDictionary*)customerHttpHead{
return @{@"user-token":@"xxxxx",@"device-id":@"xxxxx"};
}

Expand Down
13 changes: 12 additions & 1 deletion JJNetwork/Source/APIService/APIModule.h
Expand Up @@ -11,7 +11,18 @@

@protocol APIModule <NSObject>

- (NSDictionary*)keyMap;
@end


@protocol APIDominIPModule <APIModule>

- (NSDictionary*)domainIPData;

@end

@protocol APIHttpHeadModule <APIModule>

- (NSDictionary*)customerHttpHead;

@end

Expand Down
4 changes: 2 additions & 2 deletions JJNetwork/Source/APIService/APIService.h
Expand Up @@ -74,7 +74,7 @@
@param module APIModuleDomainIp Delegate
*/
+ (void)registerDomainIP:(id<APIModule>)module;
+ (void)registerDomainIP:(id<APIDominIPModule>)module;


/**
Expand All @@ -83,7 +83,7 @@
@param module APIModuleHttpHead Delegate
*/
+ (void)registerHttpHeadField:(id<APIModule>)module;
+ (void)registerHttpHeadField:(id<APIHttpHeadModule>)module;


/**
Expand Down
10 changes: 5 additions & 5 deletions JJNetwork/Source/APIService/APIService.m
Expand Up @@ -38,13 +38,13 @@ @implementation APIService

#pragma mark - Register APIModule

+ (void)registerDomainIP:(id<APIModule>)module{
NSDictionary* dic = [module keyMap];
+ (void)registerDomainIP:(id<APIDominIPModule>)module{
NSDictionary* dic = [module domainIPData];
[APIServiceManager share].domainIPs = dic;
}

+ (void)registerHttpHeadField:(id<APIModule>)module{
NSDictionary* dic = [module keyMap];
+ (void)registerHttpHeadField:(id<APIHttpHeadModule>)module{
NSDictionary* dic = [module customerHttpHead];
[APIServiceManager share].httpHeadField = dic;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ - (NSString*)replaceDomainIPFromURL:(NSString*)url{
}
NSString* newURL = url;
for (NSString* key in ips) {
newURL = [newURL stringByReplacingOccurrencesOfString:ips[key] withString:key];
newURL = [newURL stringByReplacingOccurrencesOfString:key withString:ips[key]];
}
return newURL;
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -7,7 +7,7 @@

- [x] Sign the http parameter by your customer key
- [x] Customer cache for the GET and POST
- [x] Replace the domain to IP address improve performance
- [x] Replace the domain to IP address improve performance and change customer http head field

## Requirements

Expand Down

0 comments on commit 6af6bd7

Please sign in to comment.