Giter Club home page Giter Club logo

php_api's Introduction

Keepa API Framework

This framework is intended for users of the Keepa API.

Features

  • Parses API response to easy to use PHP objects
  • Provides methods that facilitate the work with price history data

Composer

composer require keepa/php_api:*

Quick Example

Make an API request

<?php

/* maybe required - depends if youre using a framework which automaticly loading this file
require_once "vendor/autoload.php";
*/ 

use Keepa\API\Request;
use Keepa\API\ResponseStatus;
use Keepa\helper\CSVType;
use Keepa\helper\CSVTypeWrapper;
use Keepa\helper\KeepaTime;
use Keepa\helper\ProductAnalyzer;
use Keepa\helper\ProductType;
use Keepa\KeepaAPI;
use Keepa\objects\AmazonLocale;

        $api = new KeepaAPI("YOUR_API_KEY");
        $r = Request::getProductRequest(AmazonLocale::DE, 0, "2015-12-31", "2018-01-01", 0, true, ['B001G73S50']);

        $response = $api->sendRequestWithRetry($r);

			switch ($response->status) {
                case ResponseStatus::OK:
                    // iterate over received product information
                    foreach ($response->products as $product){
                        if ($product->productType == ProductType::STANDARD || $product->productType == ProductType::DOWNLOADABLE) {

                            //get basic data of product and print to stdout
                            $currentAmazonPrice = ProductAnalyzer::getLast($product->csv[CSVType::AMAZON], CSVTypeWrapper::getCSVTypeFromIndex(CSVType::AMAZON));

							//check if the product is in stock -1 -> out of stock
							if ($currentAmazonPrice == -1) {
                                echo sprintf("%s %s is currently not sold by Amazon (out of stock) %s",$product->asin,$product->title,PHP_EOL);
                            } else {
                                echo sprintf("%s %s Current Amazon Price: %s %s",$product->asin,$product->title,$currentAmazonPrice,PHP_EOL);
                            }

							// get weighted mean of the last 90 days for Amazon
							$weightedMean90days = ProductAnalyzer::calcWeightedMean($product->csv[CSVType::AMAZON], KeepaTime::nowMinutes(),90, CSVTypeWrapper::getCSVTypeFromIndex(CSVType::AMAZON));

						} else {

                        }
                    }
					break;
				default:
					print_r($response);
			}

php_api's People

Contributors

keepacom avatar minsooj avatar saschaarthur avatar tomlankhorst avatar

Watchers

 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.