SHObject Class Reference
| Inherits from | NSObject |
|---|---|
| Declared in | SHObject.h |
Overview
Base class of StreetHawk objects, such as SHInstall, SHAlertSettings. It provides basic properties and common functions. If would like to create a new StreetHawk object, inherit from this base class and do:
- add properties for the object itself.
- override
serverLoadURLandloadFromDictionary:if the object can beloadFromServer:. - override
serverSaveURLandsaveBodyif the object can besaveToServer:.
Creator
– initWithSuid:
Create a SHObject with suid, which is unique id of the object in server. suid is mandatory for a StreetHawk object, but other properties are not ready when initWithSuid:. If would like to get other properties, either there is a dictionary from server so call loadFromDictionary:, or request from server by loadFromServer:.
- (id)initWithSuid:(NSString *)suidParameters
suid |
Unique primary key match to StreetHawk server. This cannot be empty. |
|---|
Declared In
SHObject.h
Properties
Communicate With Server
– serverLoadURL
The URL that is used to load this object from the server. It’s relative path to main host url, and no need to include parameter such as installid. A sample for load install details is @“installs/details/”.
- (NSString *)serverLoadURLDeclared In
SHObject.h
– loadFromDictionary:
Normally the object is requested from server. Server returns json and parsed to be dictionary, use this method to fill properties from dictionary.
- (void)loadFromDictionary:(NSDictionary *)dictParameters
dict |
Server return json information. |
|---|
Declared In
SHObject.h
– loadFromServer:
Send a request to StreetHawk server and fill the properties of this object. The process is common, normally child class should not override this function. It does:
- (void)loadFromServer:(SHCallbackHandler)load_handlerParameters
load_handler |
Asynchronous callback for handling. |
|---|
Discussion
- Send request to StreetHawk server, formatted by
serverLoadURL. - Get the request’s response, process it. If meet error call
load_handlerto return; if not callloadFromDictionary:to fill properties and then callload_handlerto return.
Declared In
SHObject.h
– serverSaveURL
The URL that is used to post save request to server. It’s relative path to main host url, and no need to include paramter such as installid. A sample for save install is @“installs/update/”.
- (NSString *)serverSaveURLDeclared In
SHObject.h
– saveBody
The content post to server for saving this object, it must be an NSDictionary.
- (NSDictionary *)saveBodyDeclared In
SHObject.h
– saveToServer:
Send a request to StreetHawk server and post the content of this object to save. The process is common, normally child class should not override this function. It does:
- (void)saveToServer:(SHCallbackHandler)save_handlerDiscussion
- Send request to StreetHawk server, formatted by
serverSaveURL. - Get the request’s response, process it. If meet error call
save_handlerto return; if not check whether it returns json, if so callloadFromDictionary:to fill properties, and then callsave_handlerto return.
Declared In
SHObject.h