Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guyi-maple committed Jul 28, 2017
1 parent d9f8fc0 commit 56b107f
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@
<version>1.5.2.RELEASE</version>
</dependency>

<dependency>
<groupId>com.amazonservices.mws</groupId>
<artifactId>upload-data</artifactId>
<version>2009-01-01</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>com.amazonservices.mws</groupId>
<artifactId>report</artifactId>
<version>2016-09-21</version>
<version>2009-01-01</version>
<type>pom</type>
</dependency>

<dependency>
Expand All @@ -62,6 +70,12 @@
<version>2011-10-01</version>
</dependency>

<dependency>
<groupId>com.amazonservices.mws</groupId>
<artifactId>orders</artifactId>
<version>2013-09-01</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import top.guyi.amazon.mws.client.AmazonClientFactory
import top.guyi.amazon.mws.client.SuperAmazonClient
import top.guyi.amazon.mws.client.impl.OrdersClient
import top.guyi.amazon.mws.client.impl.ProductsClient
import top.guyi.amazon.mws.client.impl.ReportClient
import top.guyi.amazon.mws.conf.AmazonConfigFactory
Expand All @@ -28,6 +29,11 @@ class AmazonMWSAutoConfigure {
return new ProductsClient()
}

@Bean
OrdersClient ordersClient(){
return new OrdersClient()
}

@Bean
AmazonConfigFactory amazonConfigFactory(List<AmazonConfigProvider> providers){
AmazonConfigFactory factory = new AmazonConfigFactory()
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/top/guyi/amazon/mws/client/impl/OrdersClient.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package top.guyi.amazon.mws.client.impl

import com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersClient
import com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersConfig
import top.guyi.amazon.mws.client.SuperAmazonClient
import top.guyi.amazon.mws.conf.AmazonConfigProvider

/**
* Created by 古逸 on 2017-07-28.
*/
class OrdersClient implements SuperAmazonClient<MarketplaceWebServiceOrdersConfig,MarketplaceWebServiceOrdersClient>{

@Override
MarketplaceWebServiceOrdersClient create(AmazonConfigProvider provider) {
MarketplaceWebServiceOrdersConfig config = this.newConfig(provider)
return this.createByConfig(provider,config)
}

@Override
MarketplaceWebServiceOrdersClient createByConfig(AmazonConfigProvider provider, MarketplaceWebServiceOrdersConfig config) {
MarketplaceWebServiceOrdersClient client = new MarketplaceWebServiceOrdersClient(provider.accessKey(),provider.secretKey(),config)
return client
}

@Override
MarketplaceWebServiceOrdersConfig newConfig(AmazonConfigProvider provider) {
MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig()
config.serviceURL = provider.server()
return config
}
}
30 changes: 30 additions & 0 deletions src/main/java/top/guyi/amazon/mws/helper/DateHelper.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package top.guyi.amazon.mws.helper

import javax.xml.datatype.DatatypeFactory
import javax.xml.datatype.XMLGregorianCalendar

/**
* Created by 古逸 on 2017-07-28.
*/
class DateHelper {

static XMLGregorianCalendar convertToXMLGregorianCalendar(Date date) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
XMLGregorianCalendar gc = null;
try {
gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
} catch (Exception e) {
e.printStackTrace();
}
return gc;
}

static Date toDate(XMLGregorianCalendar calendar){
if(calendar == null) {
return null;
}
return calendar.toGregorianCalendar().getTime();
}

}
17 changes: 17 additions & 0 deletions src/main/java/top/guyi/amazon/mws/request/enums/OrderStatus.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package top.guyi.amazon.mws.request.enums

/**
* Created by 古逸 on 2017-07-28.
*/
enum OrderStatus {

PendingAvailability,
Pending,
Unshipped,
PartiallyShipped,
Shipped,
InvoiceUnconfirmed,
Canceled,
Unfulfillable

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package top.guyi.amazon.mws.request.impl.orders

import com.amazonservices.mws.orders._2013_09_01.model.ListOrderItemsRequest
import top.guyi.amazon.mws.client.SuperAmazonClient
import top.guyi.amazon.mws.client.impl.OrdersClient
import top.guyi.amazon.mws.request.SuperRequestPackers
import top.guyi.amazon.mws.response.impl.orders.ListOrderItemsHandler

/**
* Created by 古逸 on 2017-07-28.
*/
class ListOrderItemsPackers extends SuperRequestPackers<ListOrderItemsPackers,ListOrderItemsRequest,ListOrderItemsHandler>{

private ListOrderItemsRequest request

@Override
Class<? extends SuperAmazonClient> clientClass() {
return OrdersClient.class
}

@Override
String method() {
return 'listOrderItems'
}

ListOrderItemsPackers must(String amazonOrderId){
this.amazonRequest().amazonOrderId = amazonOrderId
return this
}

@Override
ListOrderItemsRequest amazonRequest() {
if(request == null){
request = new ListOrderItemsRequest()
request.sellerId = this.config().current().sellerId()
}
return request
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package top.guyi.amazon.mws.request.impl.orders

import com.amazonservices.mws.orders._2013_09_01.model.ListOrdersByNextTokenRequest
import top.guyi.amazon.mws.client.SuperAmazonClient
import top.guyi.amazon.mws.client.impl.OrdersClient
import top.guyi.amazon.mws.request.SuperRequestPackers
import top.guyi.amazon.mws.response.impl.orders.ListOrdersByNextTokenHandler

/**
* Created by 古逸 on 2017-07-28.
*/
class ListOrdersByNextTokenPackers extends SuperRequestPackers<ListOrdersByNextTokenPackers,ListOrdersByNextTokenRequest,ListOrdersByNextTokenHandler> {

private ListOrdersByNextTokenRequest request

@Override
Class<? extends SuperAmazonClient> clientClass() {
return OrdersClient.class
}

@Override
String method() {
return 'listOrdersByNextToken'
}

ListOrdersByNextTokenPackers must(String nextToken){
this.amazonRequest().nextToken = nextToken
return this
}

@Override
ListOrdersByNextTokenRequest amazonRequest() {
if(request == null){
request = new ListOrdersByNextTokenRequest()
request.sellerId = this.config().current().sellerId()
}
return request
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package top.guyi.amazon.mws.request.impl.orders

import com.amazonservices.mws.orders._2013_09_01.model.ListOrdersRequest
import top.guyi.amazon.mws.client.SuperAmazonClient
import top.guyi.amazon.mws.client.impl.OrdersClient
import top.guyi.amazon.mws.helper.DateHelper
import top.guyi.amazon.mws.request.SuperRequestPackers
import top.guyi.amazon.mws.response.impl.orders.ListOrdersHandler

/**
* Created by 古逸 on 2017-07-28.
*/
class ListOrdersPackers extends SuperRequestPackers<ListOrdersPackers,ListOrdersRequest,ListOrdersHandler>{

private ListOrdersRequest request

@Override
Class<? extends SuperAmazonClient> clientClass() {
return OrdersClient.class
}

@Override
String method() {
return 'listOrders'
}

ListOrdersPackers after(Date date){
this.amazonRequest().createdAfter = DateHelper.convertToXMLGregorianCalendar(date)
return this
}

ListOrdersPackers before(Date date){
this.amazonRequest().createdBefore = DateHelper.convertToXMLGregorianCalendar(date)
return this
}

ListOrdersPackers status(List<String> status){
this.amazonRequest().orderStatus = status
return this
}

@Override
ListOrdersRequest amazonRequest() {
if(request == null){
request = new ListOrdersRequest()
request.sellerId = this.config().current().sellerId()
request.marketplaceId = [this.config().current().marketplaceId()]
}
return request
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ abstract class SuperResponseHandler<P,R> {

abstract List<EntityData> pattern();

void over(){

}

SuperResponseHandler init(P response,R request,AmazonConfigProvider config){
String xml = this.getXML(response)
Expand All @@ -63,7 +66,7 @@ abstract class SuperResponseHandler<P,R> {
}
}
}

this.over()
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package top.guyi.amazon.mws.response.impl.orders

import com.amazonservices.mws.orders._2013_09_01.model.ListOrderItemsRequest
import com.amazonservices.mws.orders._2013_09_01.model.ListOrderItemsResponse
import top.guyi.amazon.mws.response.SuperResponseHandler

/**
* Created by 古逸 on 2017-07-28.
*/
class ListOrderItemsHandler extends SuperResponseHandler<ListOrderItemsResponse,ListOrderItemsRequest>{

@Override
String getXML(ListOrderItemsResponse response) {
return response.toXML()
}

@Override
List<EntityData> pattern() {
return null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package top.guyi.amazon.mws.response.impl.orders

import com.amazonservices.mws.orders._2013_09_01.model.ListOrdersByNextTokenRequest
import com.amazonservices.mws.orders._2013_09_01.model.ListOrdersByNextTokenResponse
import top.guyi.amazon.mws.response.SuperResponseHandler

/**
* Created by 古逸 on 2017-07-28.
*/
class ListOrdersByNextTokenHandler extends SuperResponseHandler<ListOrdersByNextTokenResponse,ListOrdersByNextTokenRequest>{

@Override
String getXML(ListOrdersByNextTokenResponse response) {
return response.toXML()
}

String nextToken

@Override
List<EntityData> pattern() {
return null
}

@Override
void over() {
this.nextToken = this.response().listOrdersByNextTokenResult.nextToken
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package top.guyi.amazon.mws.response.impl.orders

import com.amazonservices.mws.orders._2013_09_01.model.ListOrdersRequest
import com.amazonservices.mws.orders._2013_09_01.model.ListOrdersResponse
import top.guyi.amazon.mws.response.SuperResponseHandler

/**
* Created by 古逸 on 2017-07-28.
*/
class ListOrdersHandler extends SuperResponseHandler<ListOrdersResponse,ListOrdersRequest>{

@Override
String getXML(ListOrdersResponse response) {
return response.toXML()
}

String nextToken

@Override
List<EntityData> pattern() {
return null
}

@Override
void over() {
this.nextToken = this.response().listOrdersResult.nextToken
}
}

0 comments on commit 56b107f

Please sign in to comment.