Last active
December 15, 2015 13:28
-
-
Save ChrisRisner/5267043 to your computer and use it in GitHub Desktop.
iOS Mobile Services Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) createContainer:(NSString *)containerName withPublicSetting:(BOOL)isPublic withCompletion:(CompletionBlock) completion { | |
NSDictionary *item = @{ @"containerName" : containerName }; | |
NSDictionary *params = @{ @"isPublic" : [NSNumber numberWithBool:isPublic] }; | |
[self.containersTable insert:item parameters:params completion:^(NSDictionary *result, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", result); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) createTable:(NSString *)tableName withCompletion:(CompletionBlock) completion { | |
NSDictionary *item = @{ @"tableName" : tableName }; | |
[self.tablesTable insert:item completion:^(NSDictionary *result, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", result); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) deleteBlob:(NSString *)blobName fromContainer:(NSString *)containerName withCompletion:(CompletionBlock) completion { | |
NSDictionary *idItem = @{ @"id" :@1 }; | |
NSDictionary *params = @{ @"containerName" : containerName, @"blobName" : blobName }; | |
[self.blobsTable delete:idItem parameters:params completion:^(NSNumber *itemId, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", itemId); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) deleteContainer:(NSString *)containerName withCompletion:(CompletionBlock) completion { | |
NSDictionary *idItem = @{ @"id" :@1 }; | |
NSDictionary *params = @{ @"containerName" : containerName }; | |
[self.containersTable delete:idItem parameters:params completion:^(NSNumber *itemId, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", itemId); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) deleteTable:(NSString *)tableName withCompletion:(CompletionBlock) completion { | |
NSDictionary *idItem = @{ @"id" :@1 }; | |
NSDictionary *params = @{ @"tableName" : tableName }; | |
[self.tablesTable delete:idItem parameters:params completion:^(NSNumber *itemId, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", itemId); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) deleteTableRow:(NSDictionary *)item withTableName:(NSString *)tableName withCompletion:(CompletionBlock) completion { | |
//Have to send over all three as params since Mobile Services | |
//will strip everything but the ID from the item dictionary | |
NSDictionary *params = @{ @"tableName" : tableName , | |
@"partitionKey" : [item objectForKey:@"PartitionKey"] , | |
@"rowKey" : [item objectForKey:@"RowKey"]}; | |
[self.tableRowsTable delete:item parameters:params completion:^(NSNumber *itemId, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", itemId); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) getSasUrlForNewBlob:(NSString *)blobName forContainer:(NSString *)containerName withCompletion:(CompletionWithSasBlock) completion { | |
NSDictionary *item = @{ }; | |
NSDictionary *params = @{ @"containerName" : containerName, @"blobName" : blobName }; | |
[self.blobsTable insert:item parameters:params completion:^(NSDictionary *item, NSError *error) { | |
NSLog(@"Item: %@", item); | |
completion([item objectForKey:@"sasUrl"]); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(StorageService *) init | |
{ | |
// Initialize the Mobile Service client with your URL and key | |
MSClient *newClient = [MSClient clientWithApplicationURLString:@"https://mobileserviceurl.azure-mobile.net/" | |
withApplicationKey:@"applicationkey"]; | |
// Add a Mobile Service filter to enable the busy indicator | |
self.client = [newClient clientwithFilter:self]; | |
self.tablesTable = [_client getTable:@"Tables"]; | |
self.tableRowsTable = [_client getTable:@"TableRows"]; | |
self.containersTable = [_client getTable:@"BlobContainers"]; | |
self.blobsTable = [_client getTable:@"BlobBlobs"]; | |
self.tables = [[NSMutableArray alloc] init]; | |
self.busyCount = 0; | |
return self; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) insertTableRow:(NSDictionary *)item withTableName:(NSString *)tableName withCompletion:(CompletionBlock) completion { | |
NSDictionary *params = @{ @"table" : tableName }; | |
[self.tableRowsTable insert:item parameters:params completion:^(NSDictionary *result, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", result); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) refreshBlobsOnSuccess:(NSString *)containerName withCompletion:(CompletionBlock) completion { | |
NSString *queryString = [NSString stringWithFormat:@"container=%@", containerName]; | |
[self.blobsTable readWithQueryString:queryString completion:^(NSArray *results, NSInteger totalCount, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
self.blobs = [results mutableCopy]; | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) refreshContainersOnSuccess:(CompletionBlock) completion{ | |
[self.containersTable readWithCompletion:^(NSArray *results, NSInteger totalCount, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
self.containers = [results mutableCopy]; | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) refreshTableRowsOnSuccess:(NSString *)tableName withCompletion:(CompletionBlock) completion { | |
NSString *queryString = [NSString stringWithFormat:@"table=%@", tableName]; | |
[self.tableRowsTable readWithQueryString:queryString completion:^(NSArray *results, NSInteger totalCount, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
self.tableRows = [results mutableCopy]; | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) refreshTablesOnSuccess:(CompletionBlock) completion{ | |
[self.tablesTable readWithCompletion:^(NSArray *results, NSInteger totalCount, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
self.tables = [results mutableCopy]; | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) updateTableRow:(NSDictionary *)item withTableName:(NSString *)tableName withCompletion:(CompletionBlock) completion { | |
NSDictionary *params = @{ @"table" : tableName }; | |
[self.tableRowsTable update:item parameters:params completion:^(NSDictionary *result, NSError *error) { | |
[self logErrorIfNotNil:error]; | |
NSLog(@"Results: %@", result); | |
// Let the caller know that we finished | |
completion(); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment