Skip to content

Commit

Permalink
Merge pull request #3 from conekta/feature/customers
Browse files Browse the repository at this point in the history
Feature/customers
  • Loading branch information
afalla-conekta authored Aug 5, 2022
2 parents e8dd1ac + 8f164d3 commit 34d688e
Show file tree
Hide file tree
Showing 38 changed files with 1,288 additions and 2 deletions.
201 changes: 201 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# Created by https://www.toptal.com/developers/gitignore/api/intellij,visualstudiocode,java,maven,gradle,intellij+iml,intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,visualstudiocode,java,maven,gradle,intellij+iml,intellij+all

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
/.idea/
.vscode/

# CMake
cmake-build-*/

# IntelliJ
out/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties


### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# *.ipr


### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff

# AWS User-specific

# Generated files

# Sensitive or high-churn files



# CMake

# Mongo Explorer plugin

# File-based project format

# IntelliJ

# mpeltonen/sbt-idea plugin

# JIRA plugin

# Cursive Clojure plugin

# SonarLint plugin

# Crashlytics plugin (for Android Studio and IntelliJ)

# Editor-based Rest Client

# Android studio 3.1+ serialized cache file

### Intellij+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff

# AWS User-specific

# Generated files

# Sensitive or high-churn files


# CMake

# Mongo Explorer plugin

# File-based project format

# IntelliJ

# mpeltonen/sbt-idea plugin

# JIRA plugin

# Cursive Clojure plugin

# SonarLint plugin

# Crashlytics plugin (for Android Studio and IntelliJ)

# Editor-based Rest Client

# Android studio 3.1+ serialized cache file

### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
*.ipr

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# Support for Project snippet scope
.vscode/*.code-snippets

# Ignore code-workspaces
*.code-workspace

### Gradle ###
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
# JDT-specific (Eclipse Java Development Tools)

### Gradle Patch ###
# Java heap dump
*.hprof

# End of https://www.toptal.com/developers/gitignore/api/intellij,visualstudiocode,java,maven,gradle,intellij+iml,intellij+all
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# conekta-empty-template
Conekta empty repository - Used as template
# ct-conekta-java

## Upgraded Conekta JAVA Library

El objetivo principal de esta libreria es conectarse con el cliente principal de Conekta y facilitar su uso desde Java, evitando la manipulacion de JSON innecesarios, la documentacion del mismo se encuentra en:

https://developers.conekta.com/reference/autenticaci%C3%B3n

## Features:

### JAVA 11

Se upgradeo la libreria a JAVA 11 debido a que la anterior estaba en Java 7, permitiendo mas optimalidad en los clientes HTTP y facilidad de escritura de la misma.

### Nuevo cliente HttpClient

La documentacion del mismo se encuentra en:
https://openjdk.org/groups/net/httpclient/intro.html

### JacksonMapper para el manejo de JSON de manera optima.

https://github.com/FasterXML/jackson

### Nueva estructura mas ordenada.

Basada en carpetas y teniendo en cuenta las estructuras que generalmente se usan en los proyectos actuales de microservicios.
98 changes: 98 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>conekta.io</groupId>
<artifactId>ct-conekta-java</artifactId>
<version>1.0-SNAPSHOT</version>

<name>ct-conekta-java</name>
<description>This is a java library that allows interaction with https://api.conekta.io API.</description>
<url>https://www.conekta.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
59 changes: 59 additions & 0 deletions src/main/java/conekta/io/client/ConektaRequestor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package conekta.io.client;

import conekta.io.config.ConektaAuthenticator;
import conekta.io.config.ConektaObjectMapper;
import conekta.io.config.Constants;
import conekta.io.model.ConektaObject;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public abstract class ConektaRequestor {

private String environment = Constants.API_BASE.TEST.getUrl();

public void setEnvironment(String environment) {
this.environment = environment;
}

private HttpResponse<String> send(HttpRequest request) throws IOException, InterruptedException {
ConektaAuthenticator.getInstance();
return HttpClient.newBuilder()
.authenticator(ConektaAuthenticator.getBasicAuthenticator())
.connectTimeout(Duration.ofSeconds(Constants.HTTP_CLIENT_TIMEOUT))
.build()
.send(request, HttpResponse.BodyHandlers.ofString());
}

public HttpResponse<String> doRequest(ConektaObject conektaObject, String path, String method) throws IOException, InterruptedException {
HttpRequest.Builder builder = HttpRequest.newBuilder();
String jsonBody = ConektaObjectMapper.getInstance().conektaObjectToString(conektaObject);
switch (method) {
case Constants.POST:
builder = builder.POST(HttpRequest.BodyPublishers.ofString(jsonBody));
break;
case Constants.GET:
builder = builder.GET();
break;
case Constants.PUT:
builder = builder.PUT(HttpRequest.BodyPublishers.ofString(jsonBody));
break;
case Constants.DELETE:
builder = builder.DELETE();
break;
default:
throw new IllegalArgumentException("Invalid method: " + method);
}

HttpRequest request = builder
.uri(URI.create(environment + path))
.setHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON_CHARSET_UTF_8)
.setHeader(Constants.ACCEPT, Constants.APPLICATION_VND_CONEKTA_V_2_0_0_JSON)
.build();
return send(request);
}
}
Loading

0 comments on commit 34d688e

Please sign in to comment.