Skip to content

huhk345/LAFramework

Repository files navigation

LAFramework

CI Status codecov.io

Base framework for iOS, inspired by Retrofit、Restless、JSPatch、Weex ...

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

LAFramework is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LAFramework' , :git => 'git@github.com:huhk345/LAFramework.git’

post_install do |installer|
    require File.expand_path('runscript.rb', './Pods/LAFramework/LAFramework')
    RunScriptConfigurator::post_install(installer)
end

Introduction

###LANetworking###

Just define a protocol that inherits from LAWebService.

@GET("/users/{:user}/repos")
@Cache("1D")
- (LANSignal(GithubRepo))listRepos:(NSString*)user;


@GET("/repos/{:owner}/{:repo}")
@Headers({"Token":"AABB-CCDD-EE"})
- (LANSignal(void))listRepository:(NSString *)owner repo:(Part("repo") NSString *)arg;

The LANetworkingBuilder class generates an implementation of the GitHubService protocol.

id<GitHubService> service = [[LANetworkingBuilder initBuilderWithBlock:^(LANetworkingBuilder *builder) {
    builder.baseURL = [NSURL URLWithString:@"https://api.github.com"];
}] create:@protocol(GitHubService)];

Each RACSignal returned from the created GitHubService can make an asynchronous HTTP request to the remote webserver.

[[service listRepos:@"huhk345"] subscribeNext:^(LAURLResponse *response) {
    NSLog(@"reponse %@",response.responseObject);
}];


[[service listRepository:@"huhk345" repo:@"LAFramework"] subscribeNext:^(LAURLResponse *response) {
    NSLog(@"reponse %@",response.responseObject);
}];

###LAJsonKit### Create a new Objective-C class for your data model and make it inherit the LAJsonObject class. Declare properties in your header file with the name of the JSON keys:

@interface GithubRepo : LAJsonObject

@property (nonatomic,copy) NSString *archive_url;
@property (nonatomic,copy) NSString *assignees_url;

@end

Use annotations to modify the property

#undef  __CLASS__
#define __CLASS__ LAJsonTestObject

@interface LAJsonTestObject : LAJsonObject

@property (nonatomic,copy) NSString *aString;

@JsonMap("aMapString")
@property (nonatomic,copy) NSString *mapProperty;

@JsonIgnore
@property (nonatomic,copy) NSString *ignore;

@property (nonatomic,strong) NSDate *aDate;

@JsonFormat("LADate")
@JsonMap("aDate2")
@property (nonatomic,strong) NSDate *aDateTow;

@JsonTypeReference("GithubRepo")
@property (nonatomic,strong) NSArray *repos;

@property (nonatomic,assign) NSInteger aInteger;

@end

Custom data transformers

@implementation JSONValueTransformer (LAValueTransFormer)

- (NSDate *)LADateFromNSString:(NSString *)string{
    NSDateFormatter *formatter = [NSDateFormatter new];
    formatter.dateFormat = @"yyyy/MM/dd:HH/mm/ss";
    return [formatter dateFromString:string];
}

- (NSString *)JSONObjectFromLADate:(NSDate *)date{
    NSDateFormatter *formatter = [NSDateFormatter new];
    formatter.dateFormat = @"yyyy/MM/dd:HH/mm/ss";
    return [formatter stringFromDate:date];
}
@end

Author

LakeR,njlaker@gmail.com

License

LAFramework is available under the MIT license. See the LICENSE file for more info.

About

Base framework for iOS, inspired by Retrofit、Restless、JSPatch...

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors