Skip to content

keepacom/api_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keepa API Framework

This framework is intended for users of the Keepa API.

Features

  • Retrieves content from the API asynchronously and in parallel via Deferred callbacks (Java 8 Lambda friendly)
  • Parses API response to easy to use Java objects
  • Provides methods that facilitate the work with price history data

Maven

<repositories>
	<repository>
		<id>Keepa</id>
		<name>Keepa Repository</name>
        <url>https://keepa.com/maven/</url>
    </repository>
	...
</repositories>

<dependencies>
	<dependency>
		<groupId>com.keepa.api</groupId>
		<artifactId>backend</artifactId>
		<version>LATEST</version>
	</dependency>
	...
</dependencies>

Gradle

repositories {
  ...
  maven { url 'https://keepa.com/maven/' }
}
dependencies {
  ...
  compile 'com.keepa.api:backend:latest.release'
}

Also consider to add

configurations.all {
    resolutionStrategy {
        cacheDynamicVersionsFor 0, 'seconds'
        cacheChangingModulesFor 0, 'seconds'
    }
}

Which makes sure that the newest version from our servers is pulled during build.

Quick Example

Make an API request

KeepaAPI api = new KeepaAPI("YOUR_API_KEY");
Request r = Request.getProductRequest(AmazonLocale.US, 90, null, "B001GZ6QEC");

api.sendRequest(r)
		.done(result -> {
			switch (result.status) {
				case OK:
					// iterate over received product information
					for (Product product : result.products){
						// System.out.println(product);
						if (product.productType == Product.ProductType.STANDARD.code || product.productType == Product.ProductType.DOWNLOADABLE.code) {

							//get basic data of product and print to stdout
							int currentAmazonPrice = ProductAnalyzer.getLast(product.csv[Product.CsvType.AMAZON.index], Product.CsvType.AMAZON);

							//check if the product is in stock -1 -> out of stock
							if (currentAmazonPrice == -1) {
								System.out.println(product.asin + " " + product.title + " is currently out of stock!");
							} else {
								System.out.println(product.asin + " " + product.title + " Current Amazon Price: " + currentAmazonPrice);
							}
							
							// get weighted mean of the last 90 days for Amazon
							int weightedMean90days = ProductAnalyzer.calcWeightedMean(product.csv[Product.CsvType.AMAZON.index], KeepaTime.nowMinutes(), 90, Product.CsvType.AMAZON);

							...
						} else {
							...
						}
					}
					break;
				default:
					System.out.println(result);
			}
		})
		.fail(failure -> System.out.println(failure));