LayerVaultAPI 3.0.4

LayerVaultAPI 3.0.4

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
Released最新发布2014年12月

Matt Thomas 维护。



 
依赖
AFNetworking~> 1.3.4
Mantle~> 1.3
AFOAuth2Client~> 0.1.1
 

  • 作者
  • Matt Thomas

使用方法

认证

LVCAuthenticatedClient 是 LayerVault API 的主要接口,基于 AFOAuth2Client 进行认证。您可以将 AFOAuthCredential 保存到钥匙串中,这样您就不需要保存用户名或密码。

LVCAuthenticatedClient *client = [[LVCAuthenticatedClient alloc] initWithClientID:LVClientID
                                                                           secret:LVClientSecret];
// Authenticate with a username & password
[self.client loginWithEmail:userName password:password];

可以观察认证状态。由于 OAuth 令牌会过期,用户将需要重新进行认证。

[self.client addObserver:self
              forKeyPath:@"authenticationState"
                 options:NSKeyValueObservingOptionNew
                 context:kMyContext];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (context == kMyContext) {
        if ([keyPath isEqualToString:@"authenticationState"]) {
            LVCAuthenticationState authenticationState = (LVCAuthenticationState)[change[@"new"] integerValue];
            if (authenticationState == LVCAuthenticationStateTokenExpired) {
                [self.client loginWithEmail:self.email password:self.password];
            }
        }
    }
    else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

获取用户信息

LVCUser 包含了有关用户的所有信息,包括他们所属的组织以及他们可以访问的项目。《LVCAuthenticatedClient》完成认证后会自动设置用户属性

NSLog(@"%@’s Projects: %@", client.user.firstName, client.user.projects);

获取项目信息

LVCProject 包含了有关项目的所有信息,包括所有文件夹、文件和修订版本。《LVCAuthenticatedClient》可以像这样获取您的用户信息

[client getProjectWithName:@"My Awesome App"
     organizationPermalink:@"fancy-company"
                completion:^(LVCProject *project,
                             NSError *error,
                             AFHTTPRequestOperation *operation) {
    NSLog(@"Look at my files: %@", project.files);
}];

上传图片

以上就是如何上传图片的方法

NSURL *fileURL = [NSURL fileURLWithPath:@"/Users/alex/Desktop/hi.jpg"];
[client uploadLocalFile:fileURL
                 toPath:@"fancy-company/My Awesome App"
             completion:^(LVCFile *file,
                          NSError *error,
                          AFHTTPRequestOperation *operation) {
    if (file) {
        NSLog(@"file uploaded successfully: %@", file);
    }
}];

要求

安装

作者

Matt Thomas, [email protected]

许可

LayerVaultAPI 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。