PHPackages                             seanja/stats-can-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. seanja/stats-can-api

ActiveLibrary[API Development](/categories/api)

seanja/stats-can-api
====================

api client to interact with the stats can api

0.6.0(1y ago)06LGPL-3.0-or-laterPHPPHP ^8.3

Since May 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SeanJA/stats-can-api)[ Packagist](https://packagist.org/packages/seanja/stats-can-api)[ RSS](/packages/seanja-stats-can-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (6)Used By (0)

Implementation of the [Web Data Service (WDS)](https://www.statcan.gc.ca/en/developers/wds/user-guide) api

Example of usage to retrieve the latest average price of gas for all of Canada:
===============================================================================

[](#example-of-usage-to-retrieve-the-latest-average-price-of-gas-for-all-of-canada)

```
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\RequestOptions;
use SeanJA\StatsCanAPI\Client;
use SeanJA\StatsCanAPI\ValueObjects\Coordinate;
use SeanJA\StatsCanAPI\ValueObjects\Dimensions\Member;
use SeanJA\StatsCanAPI\ValueObjects\Enums\GeographyEnum;
use SeanJA\StatsCanAPI\ValueObjects\Enums\ProductIdEnum;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

require __DIR__ . '/vendor/autoload.php';

// setup the client
$client = new Client(
    guzzle: new GuzzleClient([
        // unclear if this is an issue with windows or the api endpoints
        RequestOptions::VERIFY => false
    ]),
    cache: new FilesystemAdapter('', 0, __DIR__ . '/cache')
);

class StatsCanLatestAverageGasPriceService
{
    public function __construct(
        readonly private Client $client
    )
    {
    }

    public function getLatestGasPriceForArea(GeographyEnum $geography): int
    {
        $productId = ProductIdEnum::MONTHLY_AVERAGE_RETAIL_PRICES_FOR_GASOLINE_AND_FUEL_OIL_BY_GEOGRAPHY;
        // get the data for this specific product
        $data = $this->client->getCubeMetadata($productId->value);

        // get the area that was specified
        $areaMemberDimensionPosition = $data->dimension[0]->dimensionPositionId;
        $areaMember = null;
        /** @var Member $member */
        foreach($data->dimension[0]->member as $member){
            if($member->memberId === $geography->value){
                $areaMember = $member->memberId;
                break;
            }
        }

        // get the second coordinate, which is fuel type:
        $fuelTypeDimensionPosition = $data->dimension[1]->dimensionPositionId;
        $fuelTypeMember = null;
        foreach($data->dimension[1]->member as $member){
            if($member->memberNameEn === 'Regular unleaded gasoline at self service filling stations'){
                $fuelTypeMember = $member->memberId;
                break;
            }
        }

        //setup the coordinate you want to query for
        $coordinate = new Coordinate();
        // the first dimension is the area
        $coordinate->setDimension($areaMemberDimensionPosition, $areaMember);

        $coordinate->setDimension($fuelTypeDimensionPosition, $fuelTypeMember);

        $data2 = $this->client->getDataFromCubePidCoordinateAndLatestNPeriods(
            $productId->value,
            $coordinate,
            // only get the latest row
            1
        );

        return $data2->vectorDataPoints[0]->value;
    }
}

$service = new StatsCanLatestAverageGasPriceService($client);

echo $service->getLatestGasPriceForArea(GeographyEnum::CANADA);
```

todo:
=====

[](#todo)

- more tests
- figure out some of the ambiguous data in the enums (hundredweight shows up so many times, but it is different in french, product id names are repeated)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Total

4

Last Release

594d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff15689f27b27a07694e517237c8d494f930240eec7763cc1fac08136a550c9b?d=identicon)[seanja](/maintainers/seanja)

---

Top Contributors

[![SeanJA](https://avatars.githubusercontent.com/u/102889?v=4)](https://github.com/SeanJA "SeanJA (36 commits)")

---

Tags

canadastatscanWeb Data Servicestats-canwdswds canada

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/seanja-stats-can-api/health.svg)

```
[![Health](https://phpackages.com/badges/seanja-stats-can-api/health.svg)](https://phpackages.com/packages/seanja-stats-can-api)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[commercetools/commercetools-sdk

The official PHP SDK for the commercetools Composable Commerce APIs

19281.5k](/packages/commercetools-commercetools-sdk)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
