Latest 3.0.4
Homepage https://github.com/layervault/LayerVaultAPI.objc
License MIT
Platforms ios 5.0, osx 10.7, requires ARC
Dependencies AFNetworking, Mantle, AFOAuth2Client
Authors

LayerVaultAPI License

Version
Platform

Usage

Authenticating

LVCAuthenticatedClient is the main interface to the LayerVault API and is based on AFOAuth2Client for authentication. You can save an AFOAuthCredential to the keychain so you do not need to save the username or password.

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

The authentication state can be observed. Because OAuth tokens expire, users will need to be re-authenticated

[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];
    }
}

Getting User Information

LVCUser contains all the information for a user including the organizations they are a part of and the projects they have access to. LVCAuthenticatedClient has a user property that is set automatically when authentication completes:

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

Getting Project Information

LVCProject contains all the information for a project all the folders, files, and revisions. LVCAuthenticatedClient can get your user information like so:

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

Uploading an Image

This is how you would upload an image:

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);
    }
}];

Requirements

Installation

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

pod "LayerVaultAPI"

Author

Matt Thomas, [email protected]

License

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

Latest podspec

{
    "name": "LayerVaultAPI",
    "version": "3.0.4",
    "summary": "The LayerVaultAPI pod helps you get going quickly with the LayerVault API.",
    "description": "                    The LayerVault API pod helps you get going quickly with the n                    [LayerVault API](https://developers.layervault.com). It requiresn                    ARC and is iOS and OS X compatible.n",
    "homepage": "https://github.com/layervault/LayerVaultAPI.objc",
    "license": "MIT",
    "authors": {
        "Matt Thomas": "[email protected]"
    },
    "source": {
        "git": "https://github.com/layervault/LayerVaultAPI.objc.git",
        "tag": "3.0.4"
    },
    "platforms": {
        "ios": "5.0",
        "osx": "10.7"
    },
    "ios": {
        "frameworks": [
            "MobileCoreServices",
            "SystemConfiguration",
            "Security"
        ],
        "exclude_files": "Classes/osx"
    },
    "osx": {
        "frameworks": [
            "CoreServices",
            "SystemConfiguration",
            "Security"
        ],
        "exclude_files": "Classes/ios"
    },
    "requires_arc": true,
    "source_files": "Classes",
    "public_header_files": "Classes/**/*.h",
    "dependencies": {
        "AFNetworking": [
            "~> 1.3.4"
        ],
        "Mantle": [
            "~> 1.3"
        ],
        "AFOAuth2Client": [
            "~> 0.1.1"
        ]
    }
}

Pin It on Pinterest

Share This