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
serverLoadURL
andloadFromDictionary:
if the object can beloadFromServer:
. - override
serverSaveURL
andsaveBody
if 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 *)suid
Parameters
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 *)serverLoadURL
Declared 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 *)dict
Parameters
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_handler
Parameters
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_handler
to return; if not callloadFromDictionary:
to fill properties and then callload_handler
to 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 *)serverSaveURL
Declared In
SHObject.h
– saveBody
The content post to server for saving this object, it must be an NSDictionary.
- (NSDictionary *)saveBody
Declared 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_handler
Discussion
- Send request to StreetHawk server, formatted by
serverSaveURL
. - Get the request’s response, process it. If meet error call
save_handler
to return; if not check whether it returns json, if so callloadFromDictionary:
to fill properties, and then callsave_handler
to return.
Declared In
SHObject.h