Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Adicionado funcionalidade para trabalhar com proxy, modificado LabelR… #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ rebel.xml
.project
/.settings
/target
*.orig
*.orig
.idea
.factorypath
9 changes: 6 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>br.com.intelipost</groupId>
<artifactId>sdk-java</artifactId>
<version>0.0.8</version>
<version>0.0.13</version>
<packaging>jar</packaging>

<name>Intelipost Java SDK</name>
Expand Down Expand Up @@ -113,8 +113,8 @@
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>RELEASE</version>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -171,6 +171,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/br/com/intelipost/sdk/client/IntelipostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import br.com.intelipost.sdk.response.TrackingCodeResponse;
import br.com.intelipost.sdk.response.TrackingDataResponse;
import br.com.intelipost.sdk.response.ZipCodeResponse;
import org.apache.http.HttpHost;

import java.util.List;


public class IntelipostClient {

private ZipCodeResource zipCodeResource;
Expand All @@ -36,14 +38,26 @@ public class IntelipostClient {
private LabelResource labelResource;

public IntelipostClient(String apiKey) {
zipCodeResource = new ZipCodeResource(apiKey);
trackingCodeResource = new TrackingCodeResource(apiKey);
trackingDataResource = new TrackingDataResource(apiKey);
shipmentOrderResource = new ShipmentOrderResource(apiKey);
shipmentOrderStatusResource = new ShipmentOrderStatusResource(apiKey);
quoteResource = new QuoteResource(apiKey);
plpResource = new PlpResource(apiKey);
labelResource = new LabelResource(apiKey);
zipCodeResource = new ZipCodeResource(apiKey, null);
trackingCodeResource = new TrackingCodeResource(apiKey, null);
trackingDataResource = new TrackingDataResource(apiKey, null);
shipmentOrderResource = new ShipmentOrderResource(apiKey, null);
shipmentOrderStatusResource = new ShipmentOrderStatusResource(apiKey, null);
quoteResource = new QuoteResource(apiKey, null);
plpResource = new PlpResource(apiKey, null);
labelResource = new LabelResource(apiKey, null);
}


public IntelipostClient(String apiKey, HttpHost httpHost) {
zipCodeResource = new ZipCodeResource(apiKey, httpHost);
trackingCodeResource = new TrackingCodeResource(apiKey, httpHost);
trackingDataResource = new TrackingDataResource(apiKey, httpHost);
shipmentOrderResource = new ShipmentOrderResource(apiKey, httpHost);
shipmentOrderStatusResource = new ShipmentOrderStatusResource(apiKey, httpHost);
quoteResource = new QuoteResource(apiKey, httpHost);
plpResource = new PlpResource(apiKey, httpHost);
labelResource = new LabelResource(apiKey, httpHost);
}

public ZipCodeResponse getZipCodeInfo(String zipCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public ShipmentOrderCustomerDSL phone(String phone){
return this;
}

public ShipmentOrderCustomerDSL cellPhone(String cellPhone){
customer.setCellphone(cellPhone);
return this;
}

public ShipmentOrderCustomerDSL federalTaxPayerId(String federalTaxPayerId){
customer.setTaxPayerId(federalTaxPayerId);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ShipmentOrderCustomerResquest {

private String email;
private String phone;
private String cellphone;

@JsonProperty("first_name")
private String firstName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.com.intelipost.sdk.resource;

import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,6 +14,9 @@ public class LabelResource extends Resource<String, LabelResponse> {
public LabelResource(String apiKey) {
super(apiKey);
}
public LabelResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}

public LabelResponse getLabel(String orderNumber, Integer shipmentOrderVolumeNumber) {
try {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/br/com/intelipost/sdk/resource/PlpResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import br.com.intelipost.sdk.request.PlpRequest;
import br.com.intelipost.sdk.response.Response;
import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,6 +13,9 @@ public class PlpResource extends Resource<PlpRequest, Object> {
public PlpResource(String apiKey) {
super(apiKey);
}
public PlpResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}

public Response send(PlpRequest requestBody) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import br.com.intelipost.sdk.request.QuoteRequest;
import br.com.intelipost.sdk.response.QuoteResponse;
import br.com.intelipost.sdk.response.Response;
import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,6 +14,9 @@ public class QuoteResource extends Resource<QuoteRequest, QuoteResponse> {
public QuoteResource(String apiKey) {
super(apiKey);
}
public QuoteResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}

public QuoteResponse doShippingQuote(QuoteRequest requestBody) {
try {
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/br/com/intelipost/sdk/resource/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import br.com.intelipost.sdk.response.Response;
import org.apache.http.HttpHost;
import org.apache.http.client.fluent.Request;
import org.apache.http.entity.ContentType;

Expand All @@ -15,9 +16,19 @@ public abstract class Resource<REQUEST, RESPONSE> {

protected ObjectMapper objectMapper;
protected String apiKey;
private HttpHost httpHost;
private String apiUrl;

public Resource(String apiKey) {
this.init(apiKey);
}

public Resource(String apiKey, HttpHost httpHost) {
this.init(apiKey);
this.httpHost = httpHost;
}

private void init(String apiKey) {
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new JavaTimeModule());
this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
Expand All @@ -27,12 +38,15 @@ public Resource(String apiKey) {
this.apiUrl = "https://api.intelipost.com.br/api/v1";
}


protected Response doGetRequest(String path) throws Exception {


JsonNode json = Request.Get(apiUrl + path)
.addHeader("api_key", apiKey)
.execute()
.handleResponse(httpResponse -> objectMapper.readTree(httpResponse.getEntity().getContent()));
.addHeader("api_key", apiKey)
.viaProxy(this.httpHost)
.execute()
.handleResponse(httpResponse -> objectMapper.readTree(httpResponse.getEntity().getContent()));

return processResponse(json);
}
Expand All @@ -42,6 +56,7 @@ protected Response doPostRequest(String path, REQUEST requestBody) throws Except

JsonNode json = Request.Post(apiUrl + path)
.addHeader("api_key", apiKey)
.viaProxy(this.httpHost)
.bodyString(objectMapper.writeValueAsString(requestBody), ContentType.APPLICATION_JSON)
.execute()
.handleResponse(httpResponse -> objectMapper.readTree(httpResponse.getEntity().getContent()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import br.com.intelipost.sdk.request.ShipmentOrderRequest;
import br.com.intelipost.sdk.response.Response;
import br.com.intelipost.sdk.response.ShipmentOrderResponse;
import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -16,6 +17,10 @@ public ShipmentOrderResource(String apiKey) {
super(apiKey);
}

public ShipmentOrderResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}

public ShipmentOrderResponse getShipmentOrder(String orderNumber) {
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import br.com.intelipost.sdk.request.ShipmentOrderStatusRequest;
import br.com.intelipost.sdk.response.Response;
import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -17,6 +18,10 @@ public ShipmentOrderStatusResource(String apiKey) {
super(apiKey);
}

public ShipmentOrderStatusResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}

public Response setAsReadyToShip(List<ShipmentOrderStatusRequest> shipmentOrders) {
try {
JsonNode requestBody = objectMapper.valueToTree(shipmentOrders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import br.com.intelipost.sdk.request.TrackingCodeRequest;
import br.com.intelipost.sdk.response.Response;
import br.com.intelipost.sdk.response.TrackingCodeResponse;
import org.apache.http.HttpHost;
import org.apache.http.client.methods.HttpPost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,6 +16,10 @@ public TrackingCodeResource(String apiKey) {
super(apiKey);
}

public TrackingCodeResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}

public TrackingCodeResponse getTrackingCode(TrackingCodeRequest trackingCodeRequest) {
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import br.com.intelipost.sdk.request.TrackingDataRequest;
import br.com.intelipost.sdk.response.Response;
import br.com.intelipost.sdk.response.TrackingDataResponse;
import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,6 +15,11 @@ public TrackingDataResource(String apiKey) {
super(apiKey);
}

public TrackingDataResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}


public TrackingDataResponse updateTrackingData(TrackingDataRequest trackingDataRequest) {
try {
Response<TrackingDataResponse> response = doPostRequest("/shipment_order/set_tracking_data", trackingDataRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import br.com.intelipost.sdk.response.Response;
import br.com.intelipost.sdk.response.ZipCodeResponse;
import org.apache.http.HttpHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,6 +14,11 @@ public ZipCodeResource(String apiKey) {
super(apiKey);
}

public ZipCodeResource(String apiKey, HttpHost httpHost) {
super(apiKey, httpHost);
}


public ZipCodeResponse getZipCodeInfo(String zipCode) {
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class LabelResponse {

@JsonProperty("order_number")
private Long orderNumber;
private String orderNumber;

@JsonProperty("shipment_order_volume_number")
private Long shipmentOrderVolumeNumber;
Expand Down