mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-12-02 10:56:21 +00:00
update README.md
This commit is contained in:
parent
f7d2a22e44
commit
08b3786634
46
README.md
46
README.md
@ -1,10 +1,12 @@
|
||||
MediaBrowser.ApiClient.Java
|
||||
===========================
|
||||
|
||||
This library allows Android clients to easily access the Media Browser Rest API. It is built with Volley, OkHttp, Boon and Robolectric. The http stack can be swapped out if a pure Java version is needed.
|
||||
This library allows Android clients to easily access the Media Browser Rest API. It is built with Volley, OkHttp, Boon and Robolectric. The dependencies are modular and can easily be swapped out with alternate implementations, if needed.
|
||||
|
||||
# Single Server Example #
|
||||
|
||||
This is an example of connecting to a single server using a fixed, predictable address, from an app that has user-specific features.
|
||||
|
||||
Usage is very simple:
|
||||
|
||||
``` java
|
||||
|
||||
@ -14,7 +16,21 @@ Usage is very simple:
|
||||
// The underlying http stack. Developers can inject their own if desired
|
||||
IAsyncHttpClient volleyHttpClient = new VolleyHttpClient(logger, getApplicationContext());
|
||||
|
||||
apiClient = new ApiClient(volleyHttpClient, logger, "http://localhost:8096", "My app name", "My device", "My device id", "app version 123");
|
||||
ApiClient apiClient = new ApiClient(volleyHttpClient, logger, "http://localhost:8096", "My app name", "My device", "My device id", "app version 123", new ApiEventListener(), new ClientCapabilities());
|
||||
|
||||
apiClient.AuthenticateUserAsync("username", "password", new Response<AuthenticationResult>(){
|
||||
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
// Authentication succeeded
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
// Authentication failed
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
@ -33,23 +49,37 @@ If your app is some kind of service or utility (e.g. Sickbeard), you should cons
|
||||
IAsyncHttpClient volleyHttpClient = new VolleyHttpClient(logger, getApplicationContext());
|
||||
|
||||
// Services should just authenticate using their api key
|
||||
apiClient = new ApiClient(volleyHttpClient, logger, "http://localhost:8096", "My api key");
|
||||
ApiClient apiClient = new ApiClient(volleyHttpClient, logger, "http://localhost:8096", "My api key", new ApiEventListener(), new ClientCapabilities());
|
||||
|
||||
```
|
||||
|
||||
A complete [service example can be found here.](https://github.com/MediaBrowser/MediaBrowser.ApiClient.Java/blob/master/src/MediaBrowser/ApiInteraction/Sample/ExampleService.java "service example can be found here.")
|
||||
|
||||
|
||||
# Web Socket #
|
||||
|
||||
# Logging and Interfaces #
|
||||
|
||||
ApiClient and ApiWebSocket both have additional constructors available allowing you to pass in your own implementation of ILogger. The default implementation is ConsoleLogger, which provides logging using System.Out. In addition you can also pass in your own implementation of IJsonSerializer, or use ours which is currently based on Gson, although a switch to Jackson or Boon is planned.
|
||||
|
||||
Once you have an ApiClient instance, you can easily connect to the server's web socket using:
|
||||
|
||||
``` java
|
||||
|
||||
ApiClient.OpenWebSocket();
|
||||
```
|
||||
|
||||
This will open the connection in a background thread, and periodically check to ensure it's still connected. The web socket provides various events that can be used to receive notifications from the server. Simply override the methods in ApiEventListener:
|
||||
|
||||
|
||||
``` java
|
||||
|
||||
@Override
|
||||
public void onSetVolumeCommand(int value)
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
# Multi-Server Usage #
|
||||
|
||||
|
||||
The above examples are designed for cases when your app always connects to a single server, and you always know the address. An example is an app that will always run within a local network and only connect to one server at a time. If your app is designed to support multiple networks and/or multiple servers, then **IConnectionManager** should be used in place of the above example.
|
||||
|
||||
|
||||
|
||||
|
@ -10,9 +10,13 @@ import MediaBrowser.Model.Querying.ItemQuery;
|
||||
import MediaBrowser.Model.Querying.ItemSortBy;
|
||||
import MediaBrowser.Model.Querying.QueryResult;
|
||||
import MediaBrowser.Model.Session.ClientCapabilities;
|
||||
import MediaBrowser.Model.Users.AuthenticationResult;
|
||||
import android.app.Application;
|
||||
import com.android.volley.toolbox.ImageLoader;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class ExampleApp extends Application {
|
||||
|
||||
ApiClient apiClient;
|
||||
@ -41,6 +45,25 @@ public class ExampleApp extends Application {
|
||||
return apiClient.getImageLoader();
|
||||
}
|
||||
|
||||
public void Authenticate() throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
|
||||
apiClient.AuthenticateUserAsync("username", "password", new Response<AuthenticationResult>(){
|
||||
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void GetItems(){
|
||||
|
||||
ItemQuery query = new ItemQuery();
|
||||
|
@ -5,6 +5,7 @@ import MediaBrowser.ApiInteraction.Http.VolleyHttpClient;
|
||||
import MediaBrowser.Model.Logging.ILogger;
|
||||
import MediaBrowser.Model.Session.ClientCapabilities;
|
||||
import MediaBrowser.Model.System.PublicSystemInfo;
|
||||
import MediaBrowser.Model.Users.AuthenticationResult;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -65,4 +66,23 @@ public class PublicMethodTests {
|
||||
});
|
||||
}
|
||||
|
||||
public void testLogin() throws Exception {
|
||||
|
||||
apiClient.AuthenticateUserAsync("username", "password", new Response<AuthenticationResult>(){
|
||||
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user