<commit_before>package eu.fayder.restcountries.v2.rest;

import com.google.gson.Gson;
import com.stripe.Stripe;
import com.stripe.exception.*;
import com.stripe.model.Charge;
import eu.fayder.restcountries.domain.ResponseEntity;
import eu.fayder.restcountries.v2.domain.Contribution;
import org.apache.log4j.Logger;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by fayder on 24/02/2017.
 */
@Provider
@Path("/contribute")
@Consumes("application/json;charset=utf-8")
public class StripeRest {

    private static final Logger LOG = Logger.getLogger(StripeRest.class);

    @POST
    public Object contribute(Contribution contribution) {
        if (contribution == null || contribution.getToken() == null || contribution.getAmount() < 500) {
            return getResponse(Response.Status.BAD_REQUEST);
        }

        LOG.debug("Contribute: " + contribution.toString());

        Stripe.apiKey = "";
        Map<String, Object> params = new HashMap<>();
        params.put("amount", contribution.getAmount());
        params.put("currency", "eur");
        params.put("description", "REST Countries");
        params.put("source", contribution.getToken());

        try {
            Charge.create(params);
        } catch (AuthenticationException | InvalidRequestException | CardException | APIConnectionException | APIException e) {
            LOG.error(e.getMessage(), e);
            return getResponse(Response.Status.BAD_REQUEST);
        }

        return getResponse(Response.Status.ACCEPTED);
    }

    private Response getResponse(Response.Status status) {
        Gson gson = new Gson();
        return Response
                .status(status)
                .entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
                        status.getReasonPhrase()))).build();
    }
}
<commit_msg>Minor changes to StripeRest<commit_after>package eu.fayder.restcountries.v2.rest;

import com.google.gson.Gson;
import com.stripe.Stripe;
import com.stripe.exception.*;
import com.stripe.model.Charge;
import eu.fayder.restcountries.domain.ResponseEntity;
import eu.fayder.restcountries.v2.domain.Contribution;
import org.apache.http.util.TextUtils;
import org.apache.log4j.Logger;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by fayder on 24/02/2017.
 */
@Provider
@Path("/contribute")
@Consumes("application/json;charset=utf-8")
public class StripeRest {

    private static final Logger LOG = Logger.getLogger(StripeRest.class);

    @POST
    public Object contribute(Contribution contribution) {
        if (contribution == null || TextUtils.isBlank(contribution.getToken())) {
            return getResponse(Response.Status.BAD_REQUEST);
        }

        LOG.debug("Contribute: " + contribution.toString());

        Stripe.apiKey = "";
        Map<String, Object> params = new HashMap<>();
        params.put("amount", contribution.getAmount());
        params.put("currency", "eur");
        params.put("description", "REST Countries");
        params.put("source", contribution.getToken());

        try {
            Charge.create(params);
        } catch (AuthenticationException | InvalidRequestException | CardException | APIConnectionException | APIException e) {
            LOG.error(e.getMessage(), e);
            return getResponse(Response.Status.BAD_REQUEST);
        }

        return getResponse(Response.Status.ACCEPTED);
    }

    private Response getResponse(Response.Status status) {
        Gson gson = new Gson();
        return Response
                .status(status)
                .entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
                        status.getReasonPhrase()))).build();
    }
}

{'fraction_non_alphanumeric': 0.1275, 'fraction_numerical': 0.00675, 'mean_word_length': 3.124742268041237, 'pattern_counts': {'":': 0, '<': 8, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1216851', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1148, 'n_words': 216}