Search in sources :

Example 1 with TickerUnserializer

use of se.oort.diplicity.apigen.TickerUnserializer in project android-diplicity by zond.

the class MessagingService method decodeDataPayload.

public static DiplicityJSON decodeDataPayload(String diplicityJSON) {
    if (diplicityJSON == null) {
        return null;
    }
    try {
        byte[] compressedJSON = Base64.decode(diplicityJSON, Base64.DEFAULT);
        Inflater decompresser = new Inflater();
        decompresser.setInput(compressedJSON, 0, compressedJSON.length);
        byte[] result = new byte[8192];
        int resultLength = decompresser.inflate(result);
        decompresser.end();
        byte[] actualResult = Arrays.copyOfRange(result, 0, resultLength);
        Gson gson = new GsonBuilder().registerTypeAdapter(Ticker.class, new TickerUnserializer()).create();
        return gson.fromJson(new String(actualResult, "UTF-8"), DiplicityJSON.class);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeExecutionException(e);
    } catch (DataFormatException e) {
        throw new RuntimeException(e);
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) GsonBuilder(com.google.gson.GsonBuilder) Ticker(se.oort.diplicity.apigen.Ticker) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inflater(java.util.zip.Inflater) TickerUnserializer(se.oort.diplicity.apigen.TickerUnserializer) RuntimeExecutionException(com.google.android.gms.tasks.RuntimeExecutionException)

Example 2 with TickerUnserializer

use of se.oort.diplicity.apigen.TickerUnserializer in project android-diplicity by zond.

the class RetrofitActivity method recreateServices.

protected void recreateServices() {
    AuthenticatingCallAdapterFactory adapterFactory = new AuthenticatingCallAdapterFactory();
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request toIssue = chain.request().newBuilder().addHeader("Accept", "application/json; charset=UTF-8").addHeader("X-Diplicity-API-Level", "" + DIPLICITY_API_LEVEL).build();
            if (getLocalDevelopmentMode() && !getLocalDevelopmentModeFakeID().equals("")) {
                HttpUrl url = toIssue.url().newBuilder().addQueryParameter("fake-id", getLocalDevelopmentModeFakeID()).build();
                toIssue = toIssue.newBuilder().url(url).build();
            } else if (!getAuthToken().equals("")) {
                toIssue = toIssue.newBuilder().addHeader("Authorization", "bearer " + getAuthToken()).build();
            }
            Log.d("Diplicity", "" + toIssue.method() + "ing " + toIssue.url());
            return chain.proceed(toIssue);
        }
    });
    builder.connectTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS);
    Gson gson = new GsonBuilder().registerTypeAdapter(Ticker.class, new TickerUnserializer()).registerTypeAdapter(Game.class, new GameUnserializer(this)).create();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseURL()).addConverterFactory(GsonConverterFactory.create(gson)).addCallAdapterFactory(adapterFactory).client(builder.build()).build();
    gameService = retrofit.create(GameService.class);
    userStatsService = retrofit.create(UserStatsService.class);
    memberService = retrofit.create(MemberService.class);
    rootService = retrofit.create(RootService.class);
    variantService = retrofit.create(VariantService.class);
    optionsService = retrofit.create(OptionsService.class);
    orderService = retrofit.create(OrderService.class);
    phaseService = retrofit.create(PhaseService.class);
    channelService = retrofit.create(ChannelService.class);
    messageService = retrofit.create(MessageService.class);
    phaseResultService = retrofit.create(PhaseResultService.class);
    gameResultService = retrofit.create(GameResultService.class);
    phaseStateService = retrofit.create(PhaseStateService.class);
    gameStateService = retrofit.create(GameStateService.class);
    userConfigService = retrofit.create(UserConfigService.class);
    banService = retrofit.create(BanService.class);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) PhaseService(se.oort.diplicity.apigen.PhaseService) GameStateService(se.oort.diplicity.apigen.GameStateService) PhaseResultService(se.oort.diplicity.apigen.PhaseResultService) BanService(se.oort.diplicity.apigen.BanService) Interceptor(okhttp3.Interceptor) GsonBuilder(com.google.gson.GsonBuilder) MemberService(se.oort.diplicity.apigen.MemberService) Request(okhttp3.Request) UserConfigService(se.oort.diplicity.apigen.UserConfigService) IOException(java.io.IOException) TickerUnserializer(se.oort.diplicity.apigen.TickerUnserializer) GameResultService(se.oort.diplicity.apigen.GameResultService) UserStatsService(se.oort.diplicity.apigen.UserStatsService) HttpUrl(okhttp3.HttpUrl) MessageService(se.oort.diplicity.apigen.MessageService) PhaseStateService(se.oort.diplicity.apigen.PhaseStateService) Response(okhttp3.Response) Retrofit(retrofit2.Retrofit) Game(se.oort.diplicity.apigen.Game) GameService(se.oort.diplicity.apigen.GameService) OrderService(se.oort.diplicity.apigen.OrderService)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 TickerUnserializer (se.oort.diplicity.apigen.TickerUnserializer)2 RuntimeExecutionException (com.google.android.gms.tasks.RuntimeExecutionException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 DataFormatException (java.util.zip.DataFormatException)1 Inflater (java.util.zip.Inflater)1 HttpUrl (okhttp3.HttpUrl)1 Interceptor (okhttp3.Interceptor)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 Retrofit (retrofit2.Retrofit)1 BanService (se.oort.diplicity.apigen.BanService)1 Game (se.oort.diplicity.apigen.Game)1 GameResultService (se.oort.diplicity.apigen.GameResultService)1 GameService (se.oort.diplicity.apigen.GameService)1 GameStateService (se.oort.diplicity.apigen.GameStateService)1 MemberService (se.oort.diplicity.apigen.MemberService)1