<commit_before>package com.github.jaccek.weatherapp.network.retrofit;

import com.github.jaccek.weatherapp.actualweather.interactor.network.ConnectorActualWeather;
import com.github.jaccek.weatherapp.network.ExceptionNetwork;
import com.github.jaccek.weatherapp.network.data.RawCitiesList;
import com.github.jaccek.weatherapp.network.data.RawCity;
import com.github.jaccek.weatherapp.network.data.RawWeatherData;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jacek on 8/21/16.
 */
public class NetworkConnectorRetrofit implements
        ConnectorActualWeather
{
    private WebServiceInterface mWsInterface;

    public NetworkConnectorRetrofit()
    {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://pogoda.wp.pl/api/o2/mobile/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        mWsInterface = retrofit.create(WebServiceInterface.class);
    }

    // TODO: this should return list of cities!!!
    @Override
    public RawCity downloadCity(int pCityId) throws ExceptionNetwork
    {
        try
        {
            Call<RawCitiesList> call = mWsInterface.downloadCities();
            Response<RawCitiesList> response = call.execute();
            if (response.code() != 200)
            {
                throw new ExceptionNetwork(response.code());
            }

            RawCitiesList data = response.body();
            if (data == null || data.getCities() == null || data.getCities().size() == 0)
            {
                throw new ExceptionNetwork("Empty response");
            }

            for (RawCity city : data.getCities())
            {
                if (city.getId() == pCityId)
                {
                    return city;
                }
            }
            throw new ExceptionNetwork("City with id=" + pCityId + " not found");
        }
        catch(IOException pException)
        {
            throw new ExceptionNetwork(pException);<commit_msg>TODO comment added<commit_after>package com.github.jaccek.weatherapp.network.retrofit;

import com.github.jaccek.weatherapp.actualweather.interactor.network.ConnectorActualWeather;
import com.github.jaccek.weatherapp.network.ExceptionNetwork;
import com.github.jaccek.weatherapp.network.data.RawCitiesList;
import com.github.jaccek.weatherapp.network.data.RawCity;
import com.github.jaccek.weatherapp.network.data.RawWeatherData;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jacek on 8/21/16.
 */
public class NetworkConnectorRetrofit implements
        ConnectorActualWeather
{
    private WebServiceInterface mWsInterface;

    public NetworkConnectorRetrofit()
    {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://pogoda.wp.pl/api/o2/mobile/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        mWsInterface = retrofit.create(WebServiceInterface.class);
    }

    // TODO: this should return list of cities!!!
    @Override
    public RawCity downloadCity(int pCityId) throws ExceptionNetwork
    {
        // TODO: refactor - broken SRP
        try
        {
            Call<RawCitiesList> call = mWsInterface.downloadCities();
            Response<RawCitiesList> response = call.execute();
            if (response.code() != 200)
            {
                throw new ExceptionNetwork(response.code());
            }

            RawCitiesList data = response.body();
            if (data == null || data.getCities() == null || data.getCities().size() == 0)
            {
                throw new ExceptionNetwork("Empty response");
            }

            for (RawCity city : data.getCities())
            {
                if (city.getId() == pCityId)
                {
                    return city;
                }
            }
            throw new ExceptionNetwork("City with id=" + pCityId + " not found");
        }
        catch(IOException pException)
        {
            throw new ExceptionNetwork(pException);
{'fraction_non_alphanumeric': 0.10079328044797013, 'fraction_numerical': 0.006532897806812879, 'mean_word_length': 2.292626728110599, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6444940', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1194, 'n_words': 223}