// Path: linkshortener-api/src/main/java/be/drissamri/config/safebrowsing/phishtank/PhishTankCondition.java
// public class PhishTankCondition implements Condition {
//   @Override
//   public boolean matches(
//     final ConditionContext context,
//     final AnnotatedTypeMetadata annotatedTypeMetadata) {
//     final String apiKey = context.getEnvironment().getProperty("provider.phishtank.key");
// 
//     return !StringUtils.isEmpty(apiKey);
//   }
// }
// 
// Path: linkshortener-api/src/main/java/be/drissamri/config/safebrowsing/phishtank/PhishTankConfig.java
// @Component
// @Conditional(PhishTankCondition.class)
// public class PhishTankConfig {
//   private static final Logger LOGGER = LoggerFactory.getLogger(PhishTankConfig.class);
//   private static final String PARAMETER_API_KEY = "app_key";
//   private static final String PARAMETER_FORMAT = "format";
//   private static final String RESPONSE_FORMAT = "json";
//   private final String apiUrl;
//   private final MultiValueMap<String, String> parameters;
// 
//   @Autowired
//   public PhishTankConfig(PhishTankSettings settings) {
//     this.apiUrl = settings.getEndpoint();
//     this.parameters = new LinkedMultiValueMap<>();
//     parameters.add(PARAMETER_API_KEY, settings.getCredential());
//     parameters.add(PARAMETER_FORMAT, RESPONSE_FORMAT);
// 
//     if (!StringUtils.isEmpty(parameters.getFirst(PARAMETER_API_KEY))
//       && !StringUtils.isEmpty(parameters.get(PARAMETER_FORMAT))) {
//       LOGGER.info("PhishTank API is configured with an API key");
//     }
//   }
// 
//   public final String getApiUrl() {
//     return apiUrl;
//   }
// 
//   public final MultiValueMap<String, String> getParameters() {
//     return new LinkedMultiValueMap<>(parameters);
//   }
// }


import org.springframework.context.annotation.Conditional;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import be.drissamri.config.safebrowsing.phishtank.PhishTankCondition;
import be.drissamri.config.safebrowsing.phishtank.PhishTankConfig;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Driss Amri
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package be.drissamri.service.verifier;


/**
 * Validate URL with the PhishTank API.
 * @author Driss Amri (drissamri@gmail.com)
 * @version $Id$
 */
@Component
@Conditional(PhishTankCondition.class)
public class PhishTankUrlVerifier implements UrlVerifier {
  private static final Logger LOGGER = LoggerFactory.getLogger(GoogleSafeBrowsingUrlVerifier.class);
  private static final String PARAMETER_URL = "url";
  private static final String IN_DATABASE_PARSE_EXPRESSION = "results.in_database";
  private final RestTemplate client;
// Path: linkshortener-api/src/main/java/be/drissamri/config/safebrowsing/phishtank/PhishTankCondition.java
// public class PhishTankCondition implements Condition {
//   @Override
//   public boolean matches(
//     final ConditionContext context,
//     final AnnotatedTypeMetadata annotatedTypeMetadata) {
//     final String apiKey = context.getEnvironment().getProperty("provider.phishtank.key");
// 
//     return !StringUtils.isEmpty(apiKey);
//   }
// }
// 
// Path: linkshortener-api/src/main/java/be/drissamri/config/safebrowsing/phishtank/PhishTankConfig.java
// @Component
// @Conditional(PhishTankCondition.class)
// public class PhishTankConfig {
//   private static final Logger LOGGER = LoggerFactory.getLogger(PhishTankConfig.class);
//   private static final String PARAMETER_API_KEY = "app_key";
//   private static final String PARAMETER_FORMAT = "format";
//   private static final String RESPONSE_FORMAT = "json";
//   private final String apiUrl;
//   private final MultiValueMap<String, String> parameters;
// 
//   @Autowired
//   public PhishTankConfig(PhishTankSettings settings) {
//     this.apiUrl = settings.getEndpoint();
//     this.parameters = new LinkedMultiValueMap<>();
//     parameters.add(PARAMETER_API_KEY, settings.getCredential());
//     parameters.add(PARAMETER_FORMAT, RESPONSE_FORMAT);
// 
//     if (!StringUtils.isEmpty(parameters.getFirst(PARAMETER_API_KEY))
//       && !StringUtils.isEmpty(parameters.get(PARAMETER_FORMAT))) {
//       LOGGER.info("PhishTank API is configured with an API key");
//     }
//   }
// 
//   public final String getApiUrl() {
//     return apiUrl;
//   }
// 
//   public final MultiValueMap<String, String> getParameters() {
//     return new LinkedMultiValueMap<>(parameters);
//   }
// }


// Path: linkshortener-api/src/main/java/be/drissamri/service/verifier/PhishTankUrlVerifier.java
import org.springframework.context.annotation.Conditional;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import be.drissamri.config.safebrowsing.phishtank.PhishTankCondition;
import be.drissamri.config.safebrowsing.phishtank.PhishTankConfig;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Driss Amri
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package be.drissamri.service.verifier;


/**
 * Validate URL with the PhishTank API.
 * @author Driss Amri (drissamri@gmail.com)
 * @version $Id$
 */
@Component
@Conditional(PhishTankCondition.class)
public class PhishTankUrlVerifier implements UrlVerifier {
  private static final Logger LOGGER = LoggerFactory.getLogger(GoogleSafeBrowsingUrlVerifier.class);
  private static final String PARAMETER_URL = "url";
  private static final String IN_DATABASE_PARSE_EXPRESSION = "results.in_database";
  private final RestTemplate client;
  private final PhishTankConfig config;