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:

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

  suid

Unique primary Id.

@property (nonatomic, strong) NSString *suid

Declared In

SHObject.h

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

  1. Send request to StreetHawk server, formatted by serverLoadURL.
  2. Get the request’s response, process it. If meet error call load_handler to return; if not call loadFromDictionary: to fill properties and then call load_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

  1. Send request to StreetHawk server, formatted by serverSaveURL.
  2. Get the request’s response, process it. If meet error call save_handler to return; if not check whether it returns json, if so call loadFromDictionary: to fill properties, and then call save_handler to return.

Declared In

SHObject.h