package de.rheinfabrik.heimdalldroid.network.oauth2;

import de.rheinfabrik.heimdall2.OAuth2AccessToken;
import de.rheinfabrik.heimdall2.grants.OAuth2RefreshAccessTokenGrant;
import de.rheinfabrik.heimdalldroid.network.TraktTvApiFactory;
import de.rheinfabrik.heimdalldroid.network.models.RefreshTokenRequestBody;
import io.reactivex.Single;

/**
 * TraktTv refresh token grant as described in http://docs.trakt.apiary.io/#reference/authentication-oauth/token/exchange-refresh_token-for-access_token.
 */
public class TraktTvRefreshAccessTokenGrant extends OAuth2RefreshAccessTokenGrant<OAuth2AccessToken> {

    // Properties

    public String clientSecret;
    public String clientId;
    public String redirectUri;

    // OAuth2RefreshAccessTokenGrant

    @Override
    public Single<OAuth2AccessToken> grantNewAccessToken() {
        RefreshTokenRequestBody body = new RefreshTokenRequestBody(refreshToken, clientId, clientSecret, redirectUri, GRANT_TYPE);
        return TraktTvApiFactory.newApiService().refreshAccessToken(body).singleOrError();
    }
}

@@ -893,17 +893,20 @@
 estBody(
-r
+getR
 efreshTo
@@ -908,16 +908,18 @@
 eshToken
+()
 , client
@@ -949,16 +949,19 @@
 ectUri, 
+get
 GRANT_TY
@@ -962,16 +962,18 @@
 ANT_TYPE
+()
 );%0A     

Migrate usage of the TokenGrant in the sample