Other ModulesObjective C
MFCredentials
This is the basic credentials object. It conforms to the MFCredentialsDelegate protocol. It does not use persistent storage. You should subclass it and implement your own storage and encryption mechanisms.
Constants
- MFCRD_MF_EMAIL : The name of the "email" property in a MediaFire credential.
- MFCRD_MF_EKEY : The name of the "ekey" property in a MediaFire credential.
- MFCRD_MF_PASS : The name of the "password" property in a MediaFire credential.
- MFCRD_FB_TOKEN : The name of the "token" property in a Facebook credential.
- MFCRD_TW_SECRET : The name of the "secret" property in a Twitter credential.
- MFCRD_TW_TOKEN : The name of the "token" property in a Twitter credential.
- MFCRD_TYPE_FB : Indicates a "Facebook" credential type.
- MFCRD_TYPE_MF : Indicates a "MediaFire" credential type.
- MFCRD_TYPE_TW : Indicates a "Twitter" credential type.
- MFCRD_TYPE_EKEY : Indicates a "MediaFire ekey" credential type.
Class Methods
+ purgeCredentials
Empties all credentials and peripheral properties related to credentials.+ (BOOL)purgeCredentials;
+ getCredentials
Gets whatever credentials are stored, does not care which type. All credentials dictionaries will contain a @"type" value, and one or more type-specific values. In the case of MFCRD_TYPE_MF, the credential vaules are email and password. Type MFCRD_TYPE_FB will include only a token value. Type MFCRD_TYPE_EKEY will include an ekey and password. And type MFCRD_TYPE_TW will include a token and a secret.+ (NSDictionary*)getCredentials;
+ isValid
Checks if stored credentials have been validated.+ (BOOL)isValid;
+ validate
Marks stored credentials as validated.+ (BOOL)validate;
+ setMediaFire:withPassword:
Sets the credentials to a MediaFire credential set.+ (BOOL)setMediaFire:(NSString*)email withPassword:(NSString*)password;Parameters
- email : The email address associated with the user.
- password : The password associated with the user's email.
+ convertToEKey:
Converts an email credential set into an ekey credential set.+ (BOOL)convertToEKey:(NSString*)ekey;Parameters
- ekey : The ekey returned by a call to /api/user/get_session_token.php.
+ setFacebook:
Sets the credentials to a Facebook credential set.+ (BOOL)setFacebook:(NSString*)token;Parameters
- token : The login token generated by Facebook when connecting via the Facebook SDK.
+ setTwitter:withSecret:
Sets the credentials to a Twitter credential set.+ (BOOL)setTwitter:(NSString*)token withSecret:(NSString*)secret;Parameters
- token : The login token generated by Twitter when connecting via one of Twitter's OAuth interfaces.
- secret : The secret generated by Twitter when connecting via one of Twitter's OAuth interfaces.
MFHTTPClient
This is the base class for the NSURLSessionDelegate http client. It is NOT the default http client used by MFHTTP. It conforms to NSURLSessionDelegate, NSURLSessionTaskDelegate, and MFHTTPClientDelegate. If you need to implement your own custom HTTP client, it is sufficient to conform to the MFHTTPClient protocol. You can also subclass MFHTTPClient as all it's properties are public.
Properties
- session : The instance of the session that this client uses for all requests.
- appRequestData : Temporary storage for all pending/active requests.
- counter : Used to generate unique ids for tasks.
- opLock : A lock.
- defaultMethod
Instance Methods
- initWithConfig:
returns an instance of the MFHTTPClient initialized with a given configuration.
- (id)initWithConfig:(NSURLSessionConfiguration*)config;
Parameters
- config : The configuration for the http client.
- addRequest:
Adds a request to this client's queue.
- (void)addRequest:(MFURLRequestConfig*)config;
Parameters
- config : The configuration object for the request.
- getAppRequestDataForTask:
Returns a request bundle object from appRequestData identified by a unique name.
- (MFHTTPData*)getAppRequestDataForTask:(NSURLSessionTask*)task;Parameters
- task : The task associated with the original request.
- removeAppRequestDataForTask:
Returns a request bundle object from appRequestData identified by a unique name, and removes it from appRequestData.
- (MFHTTPData*)removeAppRequestDataForTask:(NSURLSessionTask*)task;
Parameters
- task : The task associated with the original request.
- constructTaskWithRequest:config:
Returns an NSURLSessionTask object initialized with a given request and configuration.
- (id)constructTaskWithRequest:(NSMutableURLRequest*)request config:(MFURLRequestConfig*)config;
Parameters
- request : A urlrequest set to the method and url of the original request.
- config : The configuration object for the original request.
- destroy
Destroys this client.
- (void)destroy;
MFRequestManager
This is the central dispatcher for all MFAPIURLRequest objects. The requests created by MFAPI subclasses will almost always go through the MFRequestManager. This is a singleton class that routes API requests to the appropriate manager.
Class Methods
+ instance
Returns the MFRequestManager shared instance.+ (MFRequestManager*)instance;
+ createRequest:callbacks:
Dispatches a request to an appropriate manager.+ (void)createRequest:(MFAPIURLRequestConfig*)options callbacks:(NSDictionary*)cb;Parameters
- options : The configuration object of the request.
- cb : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
+ startSession:withPassword:andCallbacks:
Establishes a session with the MediaFire API via email and password combination.+ (void)startSession:(NSString*)email withPassword:(NSString*)password andCallbacks:(NSDictionary*)callbacks;Parameters
- email : The user's email address.
- password : The user's password.
- callbacks : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
+ startSessionWithCallbacks:
Established a session with the MediaFire API via stored credentials.+ (void)startSessionWithCallbacks:(NSDictionary*)callbacks;Parameters
- callbacks : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
+ startFacebookSession:withCallbacks:
Establishes a session with the MediaFire API via facebook token.+ (void)startFacebookSession:(NSString*)authToken withCallbacks:(NSDictionary*)callbacks;Parameters
- authToken : The user's Facebook token, supplied by Facebook after a successful authentication thru facebook.com.
- callbacks : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
+ endSession
Purges all existing session tokens, disabling any further requests.+ (void)endSession;
+ hasSession
Returns true if 1 or more session tokens are available.+ (BOOL)hasSession;
+ destroy
Destroys the MFRequestManager shared instance.+ (void)destroy;
+ setSessionTokenAPI:
Overrides the MFSessionAPI instance used by the Serial Request Manager Delegate with a given instance.+ (void)setSessionTokenAPI:(MFSessionAPI*)sessionAPI;Parameters
- sessionAPI : A customized instance of the MFSessionAPI class.
+ setActionTokenAPI:forType:
Overrides the MFActionTokenAPI instance used by the Parallel Request Manager for a specific type with a given instance.+ (void)setActionTokenAPI:(MFActionTokenAPI*)actionAPI forType:(NSString*)type;Parameters
- actionAPI : A customized instance of the MFActionTokenAPI class.
- type : A string identifier for the Parallel Request Manager to modify. Can be set to @"upload" or @"image".
MFSerialRequestManager
The default request manager for MFAPIURLRequest objects. Conforms to the MFSerialRequestManagerDelegate protocol. Maintains a cache of 1 or more session tokens (serial tokens). Also serves as the endpoint for logins.
Properties
- sessionAPI : An instance of the MFSessionAPI class. Can be overidden to provide customized behaviors.
Class Methods
+ endSession
Terminates session, clearing session tokens, and attempts to abort any active network connections. Actively executing API calls may complete successfully or terminate with an error; an error category of ERRCAT_NET may simply refer to the interruption of the connection caused by endSession. API call requests waiting for an available session token will receive an error with code ERRCODE_SESSION_CLOSED.+ (void)endSession;
+ hasSession
Returns true if 1 or more tokens is available.+ (BOOL)hasSession;
+ login:(NSDictionary *)credentials callbacks:(NSDictionary *)callbacks
Establishes a session with the MediaFire API via given credentials. Should only be called once for an inactive session, once the first session token has been acquired, the SRM will automatically retrieve additional tokens up to the value in MFConfig.maxTokens.+ (void)login:(NSDictionary *)credentials callbacks:(NSDictionary *)callbacks;Parameters
- credentials : A dictionary containing a credentials set. See MFCredentials.
- callbacks : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
+ releaseToken:forResponse: response
Frees a session token up for use.+ (void)releaseToken:(NSString*)token forResponse:(NSDictionary*) response;Parameters
- token : The string hash of the token.
- response : The MediaFire API response.
+ createRequest:callbacks:(NSDictionary *)callbacks
Prepares a request and puts it into the queue.+ (void)createRequest:(MFAPIURLRequestConfig*)config callbacks:(NSDictionary *)callbacks;Parameters
- config : The configruation object for the request.
- callbacks : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
+ abandonToken:
Purges a session token from the pool.+ (void)abandonToken:(NSString*)token;
Instance Methods
- addRequest:callbacks:
Adds a wrapped request to the queue.- (void)addRequest:(MFAPIURLRequestConfig*)config callbacks:(NSDictionary*)callbacks;Parameters
- config : The configruation object for the request.
- callbacks : A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
MFParallelRequestManager
Handles 'parallel' requests for a specific request type. Conforms to the MFParallelRequestManagerDelegate protocol.
Properties
Instance Methods
- initWithType:
Returns an MFParallelRequestManager object initilialized with a given type. Type can be @"upload" or @"image".- (id)initWithType:(NSString*)type;
- createRequest:callbacks:
Puts a request into the queue for dispatching. If an action token is not set, will first acquire an action token before allowing any requests to proceed.- (void)createRequest:(MFAPIURLRequestConfig*)config callbacks:(NSDictionary*)callbacks;Parameters
- config : The configuration object for the request.
- callbacks :A dictionary containing an onload callback and onerror callback. See NSDictionary(Callbacks).
- askForNewToken
Causes the request manager to request a new active token. The request manager will automatically request a new active token when it detects that the current token has expired.- (void)askForNewToken;
MFAPIURLRequestConfig
The request config for MFAPI subclass requests. These requests rely on the request managers to fully construct the url, and provide the url/post parameters as a dictionary that can be augmented and later converted to a query string. See MFURLRequestConfig for more properties.
Properties
- tokenType : The type of token management associated with this request. Defaults to MFTOKEN_SERIAL. Other options are MFTOKEN_NONE, for API requests that do not require an active session token (anything in /api/system for example), MFTOKEN_PARALLEL_UPLOAD for uploads, and MFTOKEN_PARALLEL_IMAGE for image/document thumbnails.
- queryDict : A dictionary containing the parameters for the request.
- location : The base url of the request (/api/1.0/folder/get_info.php).
- host : The host to be used for the request. Leave this nil unless you need to explicitly override the API host name.
Instance Methods
- initWithOptions:query:
Returns an MFAPIURLRequestConfig object initialized with a given set of options and parameters.- (id)initWithOptions:(NSDictionary*)options query:(NSDictionary*)params;Parameters
- options : A dictionary of HTTP client options. See MFHTTPOptions for a list of valid keys.
- params : A dictionary of the request parameters.
- generateURL
Returns a fully qualified url based on the configuration.- (NSURL*)generateURL;
Uploads
MFUploadTransaction
This can be used to upload a file to the cloud. The desired file's path is passed as an NSString to MFUploadTransaction during initialization. If the file represented by the given file path is not existing or not readable by the app, the upload will fail. To start the upload process, call start or startWithCallbacks. To cancel, call cancel. Callbacks are represented by a NSDictionary with ONLOAD, ONERROR, ONPROGRESS, ONUPDATE blocks. Each block has a NSDictionary parameter that can expected nested NSDictionaries for following keys: "fileInfo" and "response". The "fileInfo" dictionary contains the following keys: UFILENAME, UFILEHASH, UFILEPATH, USTATUS, UUPLOADKEY, UQUICKKEY, UUNITCOUNT, UFILESIZE, UUNITSIZE, ULASTUNIT. The objects for these keys are NSNumbers or NSStrings. The "response" dictionary will be an MFErrorMessage or dictionary with key UEVENT (and UCHUNKID key if object for key UEVENT matches UECHUNK). These blocks are called on successful or failed uploads as well as multiple times for status changes. The same callback property may be used for multiple MFUploadTransactions.
Properties
- httpClientId : A unique http client name registered thru MFConfig.
Instance Methods
- initWithUploadAPI:
Returns an MFUploadTransaction object initialized with a given MFUploadAPI instance.- (id)initWithUploadAPI:(MFUploadAPI*)api;Parameters
- api : An preconfigured instance of the MFUploadAPI class. If left nil, a default-configured instance will be created.
- initWithFilePath:uploadAPI:
Returns an MFUploadTransaction object initialized with a given file path and MFUploadAPI instance.- (id)initWithFilePath:(NSString*)filePath uploadAPI:(MFUploadAPI*)api;Parameters
- filePath : The local path of the file to be uploaded.
- api : An preconfigured instance of the MFUploadAPI class. If left nil, a default-configured instance will be created.
- initWithFilePath:
Returns a MFUploadTransaction for a file.- (id)initWithFilePath:(NSString*)filePath;Parameters
- filePath : The desired file to be uploaded as a NSString file system path
- startWithCallbacks:
Starts the upload process with callbacks.- (void)startWithCallbacks:(NSDictionary*)callbacks;Parameters
- callbacks : A NSDictionary with ONLOAD, ONERROR, ONPROGRESS, ONUPDATE blocks to be called on successful or failed uploads as well as multiple times for status changes. Callback dictionary may be used for multiple MFUploadTransactions.
- start
Starts the upload process.- (void)start;
- cancel
Cancels the upload process. May be restarted with a call to start.- (void)cancel;
- checkUpload
Called by internal functions to begin a resumable upload.- (void)checkUpload;
- fail:
Called by internal functions when a failure happens.- (void)fail:(NSDictionary*)response;
- optionsForCheckUpload
Returns http client options for the check api call.- (NSDictionary*)optionsForCheckUpload;
- optionsForInstantUpload
Returns http client options for the instant api call.- (NSDictionary*)optionsForInstantUpload;
- optionsForResumableUpload
Returns http client options for the resumable api call.- (NSDictionary*)optionsForResumableUpload;
- parametersForResumableUpload
Returns additional parameters for the resumable api call.- (NSDictionary*)parametersForResumableUpload;
- optionsForPollUpload
Returns http client options for the poll_upload api call.- (NSDictionary*)optionsForPollUpload;
MFUploaderConstants
Constants
- UEVENT : The name of the "upload event" property in an upload callback response.
- UESETUP : The value of UEVENT when pre-upload/check is complete.
- UECHUNK : The value of UEVENT when a unit was uploaded successfully.
- UECHUNKS : The value of UEVENT when all units uploaded successfully.
- UEPOLL : The value of UEVENT when polling, no key yet.
- UEHANG : The value of UEVENT when a non-fatal error occurs during poll upload.
- UCHUNKID : The name of the "chunk id" property in an upload callback response.
- UQUICKKEY : The name of the "quickkey" property in a file properties dictionary.
- UFILENAME : The name of the "file name" property in a file properties dictionary.
- UFILEPATH : The name of the "file path" property in a file properties dictionary.
- UUPLOADDATA : The name of the "upload data" property in a file properties dictionary.
- UFILEHASH : The name of the "file hash" property in a file properties dictionary.
- UUPLOADKEY : The name of the "upload key" property in a file properties dictionary.
- UFOLDERKEY : The name of the "upload folder key" property in a file properties dictionary.
- USTATUS : The name of the "status" property in a file properties dictionary.
- UFILESIZE : The name of the "file size" property in a file properties dictionary.
- ULASTUNIT : The name of the "last unit" property in a file properties dictionary.
- UUNITSIZE : The name of the "unit size" property in a file properties dictionary.
- UUNITCOUNT : The name of the "total number of units" property in a file properties dictionary.