Skip to content

Commit

Permalink
Merge pull request #54 from resohead/sitemap
Browse files Browse the repository at this point in the history
support sitemap report
  • Loading branch information
mattiasgeniar authored Dec 18, 2024
2 parents c728a75 + fcb2a5d commit 83ba4ff
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Actions/ManagesSitemaps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace OhDear\PhpSdk\Actions;

use OhDear\PhpSdk\Resources\SitemapResult;
use OhDear\PhpSdk\Resources\SitemapIndex;
use OhDear\PhpSdk\Resources\SitemapIssue;
use OhDear\PhpSdk\Resources\Sitemap;

trait ManagesSitemaps
{
public function sitemap(int $siteId)
{
$response = $this->get("sitemap/{$siteId}") ?? [];

$issues = $this->transformCollection($response['issues'], SitemapIssue::class);
$sitemapIndexes = $this->transformCollection($response['sitemapIndexes'], SitemapIndex::class);
$sitemaps = $this->transformCollection($response['sitemaps'], Sitemap::class);

$response['issues'] = $issues;
$response['sitemapIndexes'] = $sitemapIndexes;
$response['sitemaps'] = $sitemaps;

return new SitemapResult($response);
}
}
2 changes: 2 additions & 0 deletions src/OhDear.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OhDear\PhpSdk\Actions\ManagesStatusPageUpdates;
use OhDear\PhpSdk\Actions\ManagesUptime;
use OhDear\PhpSdk\Actions\ManagesUsers;
use OhDear\PhpSdk\Actions\ManagesSitemaps;

class OhDear
{
Expand All @@ -41,6 +42,7 @@ class OhDear
use ManagesSites;
use ManagesStatusPages;
use ManagesStatusPageUpdates;
use ManagesSitemaps;
use ManagesUptime;
use ManagesUsers;

Expand Down
19 changes: 19 additions & 0 deletions src/Resources/Sitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace OhDear\PhpSdk\Resources;

class Sitemap extends ApiResource
{
public string $url;

public int $urlCount;

public bool $checkedReachabilityOfAllUrls;

public int $issuesCount;

/**
* @var array<SitemapIssue>
*/
public array $issues;
}
13 changes: 13 additions & 0 deletions src/Resources/SitemapIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace OhDear\PhpSdk\Resources;

class SitemapIndex extends ApiResource
{
public string $url;

/**
* @var array<SitemapIssue>
*/
public array $issues;
}
17 changes: 17 additions & 0 deletions src/Resources/SitemapIssue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace OhDear\PhpSdk\Resources;

class SitemapIssue extends ApiResource
{
public string $name;

public ?string $url;

public ?int $responseCode;

public function __construct(mixed $attributes, $ohDear = null)
{
parent::__construct($attributes, $ohDear);
}
}
49 changes: 49 additions & 0 deletions src/Resources/SitemapResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace OhDear\PhpSdk\Resources;

class SitemapResult extends ApiResource
{
/*
* The url that is checked.
*/
public string $checkUrl;

/*
* The total number of issues found.
*/
public int $totalIssuesCount;

/*
* The total number of urls found.
*/
public int $totalUrlCount;

/*
* Whether there are issues found.
*/
public bool $hasIssues;

/*
* A list of issues found.
* @return array<int, SitemapIssue>
*/
public array $issues;

/*
* The sitemap indexes found along with any issues.
* @return array<int, SitemapIndex>
*/
public array $sitemapIndexes;

/*
* The sitemaps found.
* @return array<int, Sitemap>
*/
public array $sitemaps;

public function __construct(mixed $attributes, $ohDear = null)
{
parent::__construct($attributes, $ohDear);
}
}

0 comments on commit 83ba4ff

Please sign in to comment.