Inherits from NSObject
Declared in CCHVault.h
CCHVault.m

Overview

The CCHVault is used to persist data on the ContextHub servers. This class provides methods for storing data on ContextHub servers. Data stored in the vault can be accessed inside the ContextRules. Once you persist data, you can retrieve it by Tag or id.

Note: It’s a good idea to tag similar items with a common tag. For example, employee objects could be tagged as employees. You can add multiple tags to an item.

Vault repsponses will contain a dictionary with a data key and a vault_info key. The data key contains the JSON data that was used to create the record. The value of the vault_info key is used by the Vault Service to manage the data.

Structure of vault_info

key value
id unique id of the vault item on the ContextHub server
created_on the date/time the item was created on the server
updated_on the date/time that the item was last modified
tags an array of tags assigned to the item

Class Methods

sharedInstance

Returns the singleton instance of the the Vault.

+ (instancetype)sharedInstance

Return Value

Returns the singleton instance of the the Vault.

Declared In

CCHVault.h

Instance Methods

createItem:tags:completionHandler:

Creates items in the Vault.

- (void)createItem:(id)item tags:(NSArray *)tags completionHandler:(void ( ^ ) ( NSDictionary *response , NSError *error ))completionHandler

Parameters

item

The item you want to persist. This item must be a valid JSON object. See NSJSONSerialization:isValidJSONObject.

tags

(optional) The tags to be applied to the item.

completionHandler

(optional) Called when the request completes. The block is passed an NSDictionary representation of the item. If an error occurs, the NSError will be passed to the block.

Discussion

Note: The dictionary that is returned will have a vault_info key. This object contains the id, tags, and other metadata that is used to work with the item on the ContextHub server.

Declared In

CCHVault.h

deleteItem:completionHandler:

Deletes an item from the Vault.

- (void)deleteItem:(NSDictionary *)item completionHandler:(void ( ^ ) ( NSDictionary *response , NSError *error ))completionHandler

Parameters

item

The item to be deleted;

completionHandler

(optional) Called when the request completes. If an error occurs, the NSError will be passed to the block.

Declared In

CCHVault.h

getItemWithId:completionHandler:

Gets an item from the Vault.

- (void)getItemWithId:(NSString *)vaultId completionHandler:(void ( ^ ) ( NSDictionary *response , NSError *error ))completionHandler

Parameters

vaultId

The vault id of the item. The id is found in the key path @“vault_info.id”.

completionHandler

Called when the request completes.

Declared In

CCHVault.h

getItemsWithTags:completionHandler:

Gets items stored in the Vault.

- (void)getItemsWithTags:(NSArray *)tags completionHandler:(void ( ^ ) ( NSArray *responses , NSError *error ))completionHandler

Parameters

tags

(optional) The tags to be applied to the item.

completionHandler

Called when the request completes. The block is passed an NSArray of dictionaries that represent the items. If an error occurs, the NSError will be passed to the block.

Declared In

CCHVault.h

getItemsWithTags:operator:keyPath:value:completionHandler:

Gets items stored in the Vault.

- (void)getItemsWithTags:(NSArray *)tags operator:(NSString *)tagOperator keyPath:(NSString *)keyPath value:(NSString *)value completionHandler:(void ( ^ ) ( NSArray *responses , NSError *error ))completionHandler

Parameters

tags

(optional) The tags to be applied to the item.

tagOperator

(optional) Operator used to build the query with the tags. Passing ANY will find all items that match any of the tags. Passing ALL will find items that have all of the tags provided. Passing nil will use the default ALL operator.

keyPath

(optional) The keyPath that you want to look for.

value

(optional) The value that you want to find for the keyPath.

completionHandler

Called when the request completes. The block is passed an NSArray of dictionaries that represent the items. If an error occurs, the NSError will be passed to the block.

Discussion

Note: If you pass a keyPath and a value, it will return all items that have the key path equal to the value. If you pass only a keyPath, it will return all items that conatin the keypath. If you do not pass a keyPath, then both the keypath and value are ignored.

Declared In

CCHVault.h

updateItem:completionHandler:

Updates an item in the Vault.

- (void)updateItem:(NSDictionary *)item completionHandler:(void ( ^ ) ( NSDictionary *response , NSError *error ))completionHandler

Parameters

item

The item to be updated.

completionHandler

(optional) Called when the request completes. The block is passed an NSDictionary representation of the item. If an error occurs, the NSError will be passed to the block.

Declared In

CCHVault.h