Table of Contents

Class RestClient

Namespace
XeroxDev.YTMDesktop.Companion.Clients
Assembly
XeroxDev.YTMDesktop.Companion.dll

A REST client to communicate with the companion servers REST API

public class RestClient : IGenericClient
Inheritance
RestClient
Implements
Inherited Members

Constructors

RestClient(ConnectorSettings)

A REST client to communicate with the companion servers REST API

public RestClient(ConnectorSettings settings)

Parameters

settings ConnectorSettings

The settings to use for the client

Properties

Settings

The settings to use for the client

public ConnectorSettings Settings { get; set; }

Property Value

ConnectorSettings

Methods

ChangeVideo(string, string, string)

Change the video. Either videoId or playlistId or both have to be set. You can also set an url instead. Url is prioritized over videoId and playlistId

public Task ChangeVideo(string videoId = null, string playlistId = null, string url = null)

Parameters

videoId string

The video id from the video to play

playlistId string

The playlist id from the playlist to play

url string

The url to play

Returns

Task

Exceptions

ArgumentNullException

Thrown when videoId and playlistId are null

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

GetAuthCode()

Requests a code to exchange for an auth token

public Task<string> GetAuthCode()

Returns

Task<string>

The code to exchange for an auth token

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

GetAuthToken(string)

Get the authentication token that is required to access the API.

You should save this token safely and set it either:

  1. in the settings
  2. use the SetAuthToken(string) method in this class
  3. use the SetAuthToken(string) method in the CompanionConnector class
public Task<string> GetAuthToken(string code)

Parameters

code string

The code you got from the GetAuthCode() method

Returns

Task<string>

The authentication token that is required to access the API

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

GetMetadata()

Get the metadata from the API

public Task<MetadataOutput> GetMetadata()

Returns

Task<MetadataOutput>

The metadata from the API

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

GetPlaylists()

Get the playlists from the API

public Task<PlaylistOutput[]> GetPlaylists()

Returns

Task<PlaylistOutput[]>

The playlists from the API

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

GetState()

Get the state from the API

public Task<StateOutput> GetState()

Returns

Task<StateOutput>

The state from the API

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Mute()

Mute the volume

public Task Mute()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Next()

Skip to the next song

public Task Next()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Pause()

Pause the current song

public Task Pause()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Play()

Play the current song

public Task Play()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

PlayPause()

Play or pause the current song

public Task PlayPause()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

PlayQueueIndex(int)

Play a song from the queue

public Task PlayQueueIndex(int index)

Parameters

index int

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Previous()

Skip to the previous song

public Task Previous()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

SeekTo(int)

Seek to a specific time in the song

public Task SeekTo(int time)

Parameters

time int

The time to seek to

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

SetAuthToken(string)

Set the authentication token, so it can be used for further requests.
We recommend to use the SetAuthToken(string) method in the CompanionConnector class instead of this method because it also reconnects the socket client if the token changed.

public void SetAuthToken(string token)

Parameters

token string

The token to set

SetRepeatMode(ERepeatMode)

Set the repeat mode

public Task SetRepeatMode(ERepeatMode mode)

Parameters

mode ERepeatMode

The mode to set

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

SetVolume(int)

Set the volume

public Task SetVolume(int volume)

Parameters

volume int

The volume to set

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Shuffle()

Shuffle the queue

public Task Shuffle()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

ToggleDislike()

Toggle dislike the current song

public Task ToggleDislike()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

ToggleLike()

Toggle like the current song

public Task ToggleLike()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

Unmute()

Unmute the volume

public Task Unmute()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

VolumeDown()

Decrease the volume

public Task VolumeDown()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client

VolumeUp()

Increase the volume

public Task VolumeUp()

Returns

Task

Exceptions

ApiException

Thrown when an error occurred while sending the request. Error is either from the server or from the client