Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/customers #3

Merged
merged 26 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
babfce7
First Commit
matiasrosemberg Jun 28, 2022
146d4d6
Refactor and principal HTTPCLIENT
matiasrosemberg Jul 1, 2022
eb6f24b
gitIgnore
matiasrosemberg Jul 1, 2022
37349d0
Main readme
matiasrosemberg Jul 1, 2022
8877bc4
Delete target/classes/conekta/io directory
matiasrosemberg Jul 1, 2022
eab59ad
Delete .idea directory
matiasrosemberg Jul 1, 2022
25ce739
attributes
matiasrosemberg Jul 28, 2022
7997eb3
attributes
matiasrosemberg Jul 28, 2022
c19ad2d
Merge remote-tracking branch 'origin/initial-structure' into initial-…
matiasrosemberg Jul 28, 2022
f28673b
Delete target/classes/conekta/io directory
matiasrosemberg Jul 28, 2022
d208f12
requestor and auth singleton updated
matiasrosemberg Aug 1, 2022
b21ba5e
Merge remote-tracking branch 'origin/initial-structure' into initial-…
matiasrosemberg Aug 1, 2022
dfaabca
Algunos cambios
afalla-conekta Aug 1, 2022
1930e4c
headers modified
matiasrosemberg Aug 1, 2022
f8ec37a
cleaning code.
matiasrosemberg Aug 1, 2022
644e00e
Create customer service
afalla-conekta Aug 2, 2022
b04f742
Ajustes ObjectMapper
afalla-conekta Aug 2, 2022
5ded182
Prueba Obejto customer
afalla-conekta Aug 2, 2022
68963f5
customer methods added
matiasrosemberg Aug 2, 2022
2882d9f
Ajustes para pegadas
afalla-conekta Aug 2, 2022
7575f5f
Test unitario y Modificaciones List
afalla-conekta Aug 3, 2022
e1e8c2c
Test Customer
afalla-conekta Aug 3, 2022
7be91fb
refactor and cleanup
matiasrosemberg Aug 3, 2022
59cb3c6
Testing the libraries with httpclient mock server
matiasrosemberg Aug 4, 2022
1fc5128
Ajustes comentarios PR
afalla-conekta Aug 4, 2022
8f164d3
Ajustes comentarios PR2
afalla-conekta Aug 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
agatto-conekta marked this conversation as resolved.
Show resolved Hide resolved

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