<commit_before>package lt.vilnius.tvarkau.dagger.module

import android.app.Application
import ca.mimic.oauth2library.OAuth2Client
import com.google.gson.Gson
import dagger.Module
import dagger.Provides
import io.reactivex.Scheduler
import lt.vilnius.tvarkau.R
import lt.vilnius.tvarkau.api.ApiEndpoint
import lt.vilnius.tvarkau.dagger.Api
import lt.vilnius.tvarkau.dagger.IoScheduler
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Named
import javax.inject.Qualifier
import javax.inject.Singleton

@Module
class RestAdapterModule {

    @Provides
    @Named(HOST)
    fun provideHost(): String {
        return "https://api.tvarkaumiesta.lt"
    }

    @Provides
    @ApiOAuth
    fun provideOAuthEndpoint(
            application: Application,
            @Named(HOST) host: String
    ): ApiEndpoint {
        return ApiEndpoint(application.getString(R.string.api_root_oauth).format(host))
    }

    @Provides
    @Api
    fun provideApiV2Endpoint(
            @Named(HOST) host: String
    ): ApiEndpoint {
        return ApiEndpoint(host.plus("/"))
    }

    @Provides
    @GuestToken
    fun provideGuestTokenOAuthBuilder(
            @ApiOAuth endpoint: ApiEndpoint,
            @RawOkHttpClient client: OkHttpClient
    ): OAuth2Client.Builder {
        return OAuth2Client.Builder(
                OAUTH_CLIENT_ID,
                "",
                endpoint.url + OAUTH_TOKEN_ENDPOINT
        )
                .grantType("password")
                .username("guest")
                .password("<PASSWORD>")
                .scope("user")
                .okHttpClient(client)
    }

    @Provides
    @RefreshToken
    fun provideRefreshTokenOAuthBuilder(
            @ApiOAuth endpoint: ApiEndpoint,
            @RawOkHttpClient client: OkHttpClient
    ): OAuth2Client.Builder {
        return OAuth2Client.Builder(
                OAUTH_CLIENT_ID,
                "",
                endpoint.url + OAUTH_TOKEN_ENDPOINT
        )
                .grantType("refresh_token")
                .okHttpClient(client)
    }

    @Provides
    @Api
    @Singleton<commit_msg>Replace guest user login with client credentials grant (#226)<commit_after>package lt.vilnius.tvarkau.dagger.module

import android.app.Application
import ca.mimic.oauth2library.OAuth2Client
import com.google.gson.Gson
import dagger.Module
import dagger.Provides
import io.reactivex.Scheduler
import lt.vilnius.tvarkau.R
import lt.vilnius.tvarkau.api.ApiEndpoint
import lt.vilnius.tvarkau.dagger.Api
import lt.vilnius.tvarkau.dagger.IoScheduler
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Named
import javax.inject.Qualifier
import javax.inject.Singleton

@Module
class RestAdapterModule {

    @Provides
    @Named(HOST)
    fun provideHost(): String {
        return "https://api.tvarkaumiesta.lt"
    }

    @Provides
    @ApiOAuth
    fun provideOAuthEndpoint(
            application: Application,
            @Named(HOST) host: String
    ): ApiEndpoint {
        return ApiEndpoint(application.getString(R.string.api_root_oauth).format(host))
    }

    @Provides
    @Api
    fun provideApiV2Endpoint(
            @Named(HOST) host: String
    ): ApiEndpoint {
        return ApiEndpoint(host.plus("/"))
    }

    @Provides
    @GuestToken
    fun provideGuestTokenOAuthBuilder(
            @ApiOAuth endpoint: ApiEndpoint,
            @RawOkHttpClient client: OkHttpClient
    ): OAuth2Client.Builder {
        return OAuth2Client.Builder(
                OAUTH_CLIENT_ID,
                "",
                endpoint.url + OAUTH_TOKEN_ENDPOINT
        )
                .grantType("client_credentials")
                .scope("user")
                .okHttpClient(client)
    }

    @Provides
    @RefreshToken
    fun provideRefreshTokenOAuthBuilder(
            @ApiOAuth endpoint: ApiEndpoint,
            @RawOkHttpClient client: OkHttpClient
    ): OAuth2Client.Builder {
        return OAuth2Client.Builder(
                OAUTH_CLIENT_ID,
                "",
                endpoint.url + OAUTH_TOKEN_ENDPOINT
        )
                .grantType("refresh_token")
                .okHttpClient(client)
    }

    @Provides
    @Api
    @Singleton
{'fraction_non_alphanumeric': 0.08278817956237311, 'fraction_numerical': 0.006541845251522671, 'mean_word_length': 2.4186584425597535, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2654802', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1305, 'n_words': 225}