// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/BaseRate.java
// public abstract class BaseRate implements IConvertable, IRate {
// 
//     public String type;
// 
//     @RateDef
//     protected int rateType;
// 
//     BaseRate() {
//     }
// 
//     @Override
//     public int getRateType() {
//         return rateType;
//     }
// 
//     public String getFormatted(float val) {
//         return RateUtils.valueToUI(val, rateType);
//     }
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/EnparaRate.java
// public class EnparaRate extends BuySellRate {
// 
//     @Override
//     public void toRateType() {
//         int rateType = UNKNOWN;
//         String plain_type = type.replace("\n", "");
//         plain_type = plain_type.toLowerCase();
//         if (plain_type.contains("parite")) {
//             rateType = EUR_USD;
//         } else if (plain_type.contains("usd")) {
//             rateType = USD;
//         } else if (plain_type.contains("eur")) {
//             rateType = EUR;
//         } else if (plain_type.contains("altın (gram)")) {
//             rateType = ONS_TRY;
//         }
//         this.rateType = rateType;
//     }
// 
//     @Override
//     public void setRealValues() {
//         String val = valueSell.replace(" TL", "").replace(",", ".").trim();
//         valueSellReal = Float.valueOf(val);
// 
//         val = valueBuy.replace(" TL", "").replace(",", ".").trim();
//         valueBuyReal = Float.valueOf(val);
//     }
// }


import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import dynoapps.exchange_rates.model.rates.BaseRate;
import dynoapps.exchange_rates.model.rates.EnparaRate;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
package dynoapps.exchange_rates.converters;





/**
 * Copyright 2016 Erdem OLKUN
 *
 * 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.
 *
 * Created by erdemmac on 24/11/2016.
 */

public class EnparaConverter implements Converter<ResponseBody, List<BaseRate>> {

    private static final EnparaConverter INSTANCE = new EnparaConverter();
    private static final String HOST = "https://www.qnbfinansbank.enpara.com";

    private EnparaConverter() {
    }

    @Override
    public List<BaseRate> convert(@NonNull ResponseBody value) throws IOException {

        ArrayList<BaseRate> rates = new ArrayList<>();
        String responseBody = value.string();

        final Elements shotElements = Jsoup.parse(responseBody, HOST).getElementsByClass("enpara-gold-exchange-rates__table-item");
        for (Element element : shotElements) {
            BaseRate rate = parseRate(element);
            rates.add(rate);
        }
        return rates;
    }

// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/BaseRate.java
// public abstract class BaseRate implements IConvertable, IRate {
// 
//     public String type;
// 
//     @RateDef
//     protected int rateType;
// 
//     BaseRate() {
//     }
// 
//     @Override
//     public int getRateType() {
//         return rateType;
//     }
// 
//     public String getFormatted(float val) {
//         return RateUtils.valueToUI(val, rateType);
//     }
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/EnparaRate.java
// public class EnparaRate extends BuySellRate {
// 
//     @Override
//     public void toRateType() {
//         int rateType = UNKNOWN;
//         String plain_type = type.replace("\n", "");
//         plain_type = plain_type.toLowerCase();
//         if (plain_type.contains("parite")) {
//             rateType = EUR_USD;
//         } else if (plain_type.contains("usd")) {
//             rateType = USD;
//         } else if (plain_type.contains("eur")) {
//             rateType = EUR;
//         } else if (plain_type.contains("altın (gram)")) {
//             rateType = ONS_TRY;
//         }
//         this.rateType = rateType;
//     }
// 
//     @Override
//     public void setRealValues() {
//         String val = valueSell.replace(" TL", "").replace(",", ".").trim();
//         valueSellReal = Float.valueOf(val);
// 
//         val = valueBuy.replace(" TL", "").replace(",", ".").trim();
//         valueBuyReal = Float.valueOf(val);
//     }
// }


// Path: app/src/main/java/dynoapps/exchange_rates/converters/EnparaConverter.java
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import dynoapps.exchange_rates.model.rates.BaseRate;
import dynoapps.exchange_rates.model.rates.EnparaRate;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

package dynoapps.exchange_rates.converters;





/**
 * Copyright 2016 Erdem OLKUN
 *
 * 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.
 *
 * Created by erdemmac on 24/11/2016.
 */

public class EnparaConverter implements Converter<ResponseBody, List<BaseRate>> {

    private static final EnparaConverter INSTANCE = new EnparaConverter();
    private static final String HOST = "https://www.qnbfinansbank.enpara.com";

    private EnparaConverter() {
    }

    @Override
    public List<BaseRate> convert(@NonNull ResponseBody value) throws IOException {

        ArrayList<BaseRate> rates = new ArrayList<>();
        String responseBody = value.string();

        final Elements shotElements = Jsoup.parse(responseBody, HOST).getElementsByClass("enpara-gold-exchange-rates__table-item");
        for (Element element : shotElements) {
            BaseRate rate = parseRate(element);
            rates.add(rate);
        }
        return rates;
    }

    private EnparaRate parseRate(Element element) {