BasicsJava

Overview


Description : This rich framework provides the flexibility and simplicity you will need to connect with millions of MediaFire users around the world while also adding powerful features to your Android or Java app.


Getting Started

Download the MediaFire Java sdk
The Java SDK serves as a way to make API requests to MediaFire. There are 5 main packages:

  • com.mediafire.sdk.api_responses : Response classes used by Gson.
  • com.mediafire.sdk.clients:Client classes used to make API calls.
  • com.mediafire.sdk.config : Configuration classes, interfaces, and default implementations of interfaces used by the SDK.
  • com.mediafire.sdk.http : APIs, http handling, & http setup and teardown for requests.
  • com.mediafire.sdk.token : Tokens, Session Token handling, & Action Token Handling.

Additionally, for your convenience, there is a Runnable to manage resumable upload:
  • com.mediafire.sdk.uploader : Runnable, descriptors, config.

Using the SDK


Using the Java SDK is as simple as initializing a Configuration object.
Once a Configuration has been created, you can then create an ApiClient object (com.mediafire.sdk.clients).
After initializing the ApiClient you can begin making requests to MediaFire.

MF Configuration


Configuration uses the builder pattern for construction. Examples of creating an Configuration object follow:

Examples


Basic:
Configuration.Builder builder = new Configuration.Builder()
Configuration config = builder.build();
config.init();


Custom API Key:
Configuration.Builder builder = new Configuration.Builder();
Configuration config = builder.build();
config.getDeveloperCredentials().setCredentials();


Custom Implementations of Interfaces used by Configuration (RECOMMENDED):
Configuration.Builder builder = new Configuration.Builder();
builder.developerCredentials();
builder.userCredentials();
builder.developerCredentials();
builder.httpWorker();
builder.tokenManagers();
builder.logger();
builder.networkConnectivityMonitor();
Configuration config = builder.build();
config.init();

Making a Request


If the Configuration and ApiClient have been created, then you can make requests to the MediaFire API by passing a Request (com.mediafire.sdk.http.Request) to the ApiClient as follows:

yourApiClientObject.doRequest(yourRequestObject);

A Request object can be created using either a RequestGenerator or manually creating a Request object.

system/get_info

Request request = new RequestGenerator().generateRequestObject("system", "get_info.php"); yourApiClientObject.doRequest(request);

You will receive a Result object when the API request finishes which contains the Response and the original Request.

Basic Call Examples


file/get_links

Retrieves a file's link (whether it be view, download, etc.) :

Request request = new RequestGenerator().generateRequestObject("file", "get_links.php");
request.addQueryParameter("quick_key", "AbCd123Z");
yourApiClientObject.doRequest(request);

user/get_info

Retrieves a user's profile, and some account, information:

Request request = new RequestGenerator().generateRequestObject("user", "get_info.php");
yourApiClientObject.doRequest(request);

folder/move

Moves a folder:

Request request = new RequestGenerator().generateRequestObject("folder", "move.php");
request.addQueryParameter("folder_key_src", "abcdefgh");
request.addQueryParameter("folder_key_dst", "hgfedcba");
yourApiClientObject.doRequest(request);

Handling Result


doRequest() returns an '''Result''' object. The 'Result' object is a descriptor holding the Response and the original 'Request' used. The primary use of the Response object is to use the following methods:

public byte[] getBytes();
public int getStatus();

You are free to use any response type (xml or json) and any parser of your choice (Gson, Jackson, your own, etc.) to parse the byte[] portion of the response.

Gson response classes already exist in the API as well as a ResponseHelper class which will help convert 'Response' byte[] into json responses using Gson.