Eorzea Market Note Eorzea Market Note

EorzeaMarketNote Web API

EorzeaMarketNote Web API using PHP example

Overview

Here is a example to display information on the Mandragora server's potion.

All sources

Please clone the example source from the following git repository.

The example for PHP is contained in the php directory.

Premise

The example is based on the following tools and libraries.

How to run

The command to execute the example is as follow.

composer install
php example.php

Main source(example.php)

<?php
require 'vendor/autoload.php';

use Doctrine\Common\Cache\FilesystemCache;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage;
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;

$stack = HandlerStack::create();
$stack->push(
    new CacheMiddleware(
        new PrivateCacheStrategy(
            new DoctrineCacheStorage(
                new FilesystemCache(__DIR__ . '/cache/')
            )
        )
    ),
    'cache'
);
$client = new Client(['handler' => $stack]);
try {
    $response = $client->request('GET', 'https://ff14marketnoteapi.ownway.info/research/1/market_research', [
        'query' => ['dc' => 'Mana'],
    ]);

    if ($response->getStatusCode() == 200) {
        $aggregate_date = DateTime::createFromFormat(DATE_RFC2822, $response->getHeader('Last-Modified')[0]);
        echo "Aggregate date:", $aggregate_date->format(DATE_ISO8601), "\n";

        $data = json_decode($response->getBody(), true);
        $latest_market_researches = isset($data['Mandragora']['l']) ? $data['Mandragora']['l'] : null;
        $optional_infos = isset($data['Mandragora']['o']) ? $data['Mandragora']['o'] : null;

        # 7992765ec34: potion's item key
        $item_key = '7992765ec34';
        $potion_l = isset($latest_market_researches[$item_key]) ? $latest_market_researches[$item_key] : null;
        $potion_o = isset($optional_infos[$item_key]) ? $optional_infos[$item_key] : null;
        if (isset($potion_l)) {
            $price_nq = $potion_l[0];
            $price_hq = $potion_l[1];
            $stock_nq = $potion_l[2];
            $stock_hq = $potion_l[3];
            $circulation1_nq = $potion_l[4];
            $circulation1_hq = $potion_l[5];
            $circulation2_nq = $potion_l[6];
            $circulation2_hq = $potion_l[7];
            $circulation_nq = isset($circulation1_nq) && isset($circulation2_nq) ? round(24 * $circulation1_nq / (double)$circulation2_nq, 2) : null;
            $circulation_hq = isset($circulation1_hq) && isset($circulation2_hq) ? round(24 * $circulation1_hq / (double)$circulation2_hq, 2) : null;
            $researched_time = $potion_l[8];
            echo "Potion's price(NQ):", $price_nq, "\n";
            echo "Potion's price(HQ):", $price_hq, "\n";
            echo "Potion's stock(NQ):", $stock_nq, "\n";
            echo "Potion's stock(HQ):", $stock_hq, "\n";
            echo "Potion's circulation pieces/day (NQ):", $circulation_nq, "\n";
            echo "Potion's circulation pieces/day (HQ):", $circulation_hq, "\n";
            echo "Potion's researched time(HQ):", isset($researched_time) ? date(DATE_ISO8601, $researched_time) : "", "\n";
        } else {
            echo "No latest market research.";
        }

        if (isset($potion_l)) {
            $material_cost_hq_first = $potion_o[0];
            $material_cost_price_first = $potion_o[1];
            echo "Potion's material cost(HQ first):", $material_cost_hq_first, "\n";
            echo "Potion's material cost(Price first):", $material_cost_price_first, "\n";
        } else {
            echo "No optional info.";
        }
    } else {
        echo "Error StatusCode:" . $response->getStatusCode(), "\n";
    }
} catch (Exception $e) {
    echo "Error Message:" . $e->getMessage(), "\n";
}