/*
 * Copyright (c) 2016 Applivery
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.applivery.applvsdklib.network.api.interceptor;

import com.applivery.applvsdklib.AppliverySdk;
import java.io.IOException;
import java.util.Locale;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Sergio Martinez Rodriguez
 * Date 11/1/16.
 */
public class HeadersInterceptor implements Interceptor {

  public HeadersInterceptor() {

  }

  @Override public Response intercept(Chain chain) throws IOException {
    return chain.proceed(composeRequest(chain));
  }

  private Request composeRequest(Chain chain) {
    Request original = chain.request();
    return original.newBuilder()
        .url(chain.request().url())
        .header("Accept-Language", Locale.getDefault().getLanguage())
        .header("x_sdk_version", "ANDROID_" + AppliverySdk.getVersionName())
        .method(original.method(), original.body())
        .build();
  }
}

@@ -658,46 +658,157 @@
 ort 
-com.applivery.applvsdklib.AppliverySdk
+android.annotation.SuppressLint;%0Aimport android.os.Build;%0Aimport com.applivery.applvsdklib.AppliverySdk;%0Aimport com.applivery.applvsdklib.BuildConfig
 ;%0Aim
@@ -1385,25 +1385,28 @@
 ))%0A        .
-h
+addH
 eader(%22Accep
@@ -1462,17 +1462,20 @@
        .
-h
+addH
 eader(%22x
@@ -1529,24 +1529,73 @@
 sionName())%0A
+        .addHeader(%22User-Agent%22, getUserAgent())%0A
         .met
@@ -1655,11 +1655,243 @@
 d();%0A  %7D
+%0A%0A  @SuppressLint(%22DefaultLocale%22) private String getUserAgent() %7B%0A    return String.format(%22Android/%25s; vendor/%25s; model/%25s; build/%25d;%22, Build.VERSION.RELEASE,%0A        Build.MANUFACTURER, Build.MODEL, BuildConfig.VERSION_CODE);%0A  %7D
 %0A%7D%0A

Add User-Agent header.