GithubHelp home page GithubHelp logo

isabella232 / amazon-hub-counter-sdk-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amzn/amazon-hub-counter-sdk-java

0.0 0.0 0.0 41 KB

The Amazon Hub Counter SDK for Java enables Java developers to easily work with the Amazon Hub Counter API and manage Amazon pickup locations.

License: MIT No Attribution

Java 100.00%

amazon-hub-counter-sdk-java's Introduction

Java SDK for Amazon Hub Counter API

This module implements all the logic to resolve the Amazon Hub Counter API requests used for manage access points locations. This includes the creation, update, activation and deactivation of the access points points.

Installation

Download the amazon-hub-counter-sdk-1.0.jar file from the releases or:

  1. Clone this repository.
  2. Run: cd amazon-hub-counter-sdk-java
  3. Compile the project: mvn clean compile assembly:single
  4. Add target/amazon-hub-counter-sdk-1.0-jar-with-dependencies.jar as a reference to your project or run mvn clean install if you want to install the package to your local Maven repository.

Usage

1. Import the package

import com.amazon.hub.counter.AmazonHubCounterFeedAPI;

2. Set your credentials

ClientCredentials clientCredentials = ClientCredentials.builder()
                .clientId("amzn1.application-oa2-client.xxxxx")
                .clientSecret("client_secret")
                .build();
  • clientId has to be filled with the clientId corresponding to the security profile created in the developer.amazon.com portal, use the clientId corresponding to the environment that you want to send the requests (sandbox/production).
  • clientSecret is the password for this security profile, this also can be found in the developer.amazon.com portal.

3. Instantiate the API handler

AmazonHubCounterFeedAPI api = new AmazonHubCounterFeedAPI(
									clientCredentials,
									"https://accesspoints-api-sandbox-eu.amazon.com",
									"https://api.amazon.com/auth/o2/token"
							);
  • Set the apiEndpoint to the corresponding url according to your region and environment.

4. Submit a store

AccessPoint[] accessPoints = new AccessPoint[1];

Address address = Address.builder()
        .addressFieldOne("1918 8th Ave, Seattle, WA 98101, USA")
        .city("Seattle")
        .postalCode("98101")
        .countryCode("US")
        .latitude("47.615564")
        .longitude("-122.335819")
        .build();

String[] capabilities = {"PICK_UP", "DROP_OFF"};

ExceptionalClosure[] exceptionalClosures = new ExceptionalClosure[1];
exceptionalClosures[0] = ExceptionalClosure.builder()
        .startDateTime("2038-01-19T00:00:00")
        .endDateTime("2038-01-20T00:00:00")
        .build();

CommunicationDetails communicationDetails = CommunicationDetails.builder()
        .phoneNumber("00 1 206-922-0880")
        .emailId("[email protected]")
        .build();

StandardHours[] standardHours = new StandardHours[6];

standardHours[0] = StandardHours.builder()
        .day("MONDAY")
        .openingTime("08:30:00")
        .closingTime("20:00:00")
        .build();
standardHours[1] = StandardHours.builder()
        .day("TUESDAY")
        .openingTime("08:30:00")
        .closingTime("20:00:00")
        .build();
standardHours[2] = StandardHours.builder()
        .day("WEDNESDAY")
        .openingTime("08:30:00")
        .closingTime("20:00:00")
        .build();
standardHours[3] = StandardHours.builder()
        .day("THURSDAY")
        .openingTime("08:30:00")
        .closingTime("20:00:00")
        .build();
standardHours[4] = StandardHours.builder()
        .day("FRIDAY")
        .openingTime("08:30:00")
        .closingTime("20:00:00")
        .build();
MidDayClosure[] midDayClosures = new MidDayClosure[1];
midDayClosures[0] = MidDayClosure.builder()
        .startTime("12:00:00")
        .endTime("13:00:00")
        .build();
standardHours[5] = StandardHours.builder()
        .day("SATURDAY")
        .openingTime("08:30:00")
        .closingTime("20:00:00")
        .midDayClosures(midDayClosures)
        .build();

accessPoints[0] = AccessPoint.builder()
        .accessPointId("AMAZON-US-HQ")
        .accessPointName("Amazon Hub Counter - Amazon US HQ")
        .isActive(true)
        .isRestrictedAccess(false)
        .timeZone("America/Los_Angeles")
        .address(address)
        .terminationDate("2199-12-31")
        .capabilities(capabilities)
        .standardHoursList(standardHours)
        .exceptionalClosures(exceptionalClosures)
        .communicationDetails(communicationDetails)
        .build();

AccessPointsFeedRequest accessPointsFeedRequest = AccessPointsFeedRequest.builder()
        .accessPoints(accessPoints)
        .build();

String accessToken = api.getAccessToken();

String feedId = api.postFeed(accessPointsFeedRequest,
        FeedType.STORE_FEED,
        accessToken);

5. Check the status of the feed submission

Feed feed = api.getFeedById(feedId, accessToken);
  • You can get the status of the feed calling the method feed.getStatus(), this can result in:
    • Processing the feed has not been processed yet, this task is asynchronous so you have to poll for updates, build a retry logic with a max retries/timeout break builtin.
    • Completed the feed processing is completed, an OutputDocument is generated with the processing details.
    • Failed the feed processing failed, no OutputDocument could be generated, if this occurs report the issue to your Amazon POC.

6. Check the processing results (OutputDocument)

OutputDocument doc= api.getOutputDocument(
											feed.getFeedId(),
											feed.getOutputDocuments()[0].getDocumentId(),
											accessToken
										);
  • Check if doc.getNoOfAccessPointsFailedToProcess() is greater than 0, if that's the case, you can retrieve the details of the errors calling the method doc.getFailedAccessPointProcessingDetails()_.
  • If doc.getNoOfAccessPointsProcessed() == doc.getNoOfAccessPointsSuccessfullyProcessed(), all access points were successfully processed.

NOTE: A sample code using this package exists this repository: amazon-hub-counter-api-samples/java.

Copyright and License

All content in this repository, unless otherwise stated, is Copyright © 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Except where otherwise noted, all examples in this collection are licensed under the MIT-0 license. The full license text is provided in the LICENSE file accompanying this repository.

amazon-hub-counter-sdk-java's People

Contributors

agaadit avatar amazon-auto avatar dependabot[bot] avatar janayus avatar righetl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.