Skip to content

Commit

Permalink
Added new zones methods to the main API object; fixed a return type; …
Browse files Browse the repository at this point in the history
…added new enums and exceptions for future dev
  • Loading branch information
benjaminhansen committed Aug 2, 2024
1 parent 81133d6 commit c9f86ef
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use BenjaminHansen\NWS\Features\ObservationStation;
use BenjaminHansen\NWS\Features\ObservationStations;
use BenjaminHansen\NWS\Features\Glossary;
use BenjaminHansen\NWS\Features\ForecastZone;
use BenjaminHansen\NWS\Exceptions\ApiNotOkException;
use BenjaminHansen\NWS\Exceptions\CacheException;
use BenjaminHansen\NWS\Support\Carbon;
use Illuminate\Support\Collection;
use DateInterval;
use DateTimeZone;

Expand Down Expand Up @@ -294,4 +296,24 @@ public function glossary(): Glossary
$url = "{$this->baseUrl()}/glossary";
return new Glossary($this->get($url), $this);
}

/*
** Get a specific Forecast Zone
*/
public function zone(string $zone_id): ForecastZone
{
$zone_id = strtoupper($zone_id);
$url = "{$this->baseUrl()}/zones?id={$zone_id}";
$data = $this->get($url)->features[0];
return new ForecastZone($data, $this);
}

/*
** Get all available Forecast Zones
*/
public function zones(): Collection
{
$url = "{$this->baseUrl()}/zones";
return collect($this->get($url)->features);
}
}
138 changes: 138 additions & 0 deletions src/Enums/ForecastOffice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

namespace BenjaminHansen\NWS\Enums;

enum ForecastOffice
{
case AKQ;
case ALY;
case BGM;
case BOX;
case BTV;
case BUF;
case CAE;
case CAR;
case CHS;
case CLE;
case CTP;
case GSP;
case GYX;
case ILM;
case ILN;
case LWX;
case MHX;
case OKX;
case PBZ;
case PHI;
case RAH;
case RLX;
case RNK;
case ABQ;
case AMA;
case BMX;
case BRO;
case CRP;
case EPZ;
case EWX;
case FFC;
case FWD;
case HGX;
case HUN;
case JAN;
case JAX;
case KEY;
case LCH;
case LIX;
case LUB;
case LZK;
case MAF;
case MEG;
case MFL;
case MLB;
case MOB;
case MRX;
case OHX;
case OUN;
case SHV;
case SJT;
case SJU;
case TAE;
case TBW;
case TSA;
case ABR;
case APX;
case ARX;
case BIS;
case BOU;
case CYS;
case DDC;
case DLH;
case DMX;
case DTX;
case DVN;
case EAX;
case FGF;
case FSD;
case GID;
case GJT;
case GLD;
case GRB;
case GRR;
case ICT;
case ILX;
case IND;
case IWX;
case JKL;
case LBF;
case LMK;
case LOT;
case LSX;
case MKX;
case MPX;
case MQT;
case OAX;
case PAH;
case PUB;
case RIW;
case SGF;
case TOP;
case UNR;
case BOI;
case BYZ;
case EKA;
case FGZ;
case GGW;
case HNX;
case LKN;
case LOX;
case MFR;
case MSO;
case MTR;
case OTX;
case PDT;
case PIH;
case PQR;
case PSR;
case REV;
case SEW;
case SGX;
case SLC;
case STO;
case TFX;
case TWC;
case VEF;
case AER;
case AFC;
case AFG;
case AJK;
case ALU;
case GUM;
case HPA;
case HFO;
case PPG;
case STU;
case NH1;
case NH2;
case ONA;
case ONP;
}
13 changes: 13 additions & 0 deletions src/Enums/RegionalHeadquarters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace BenjaminHansen\NWS\Enums;

enum RegionalHeadquarters
{
case ARH;
case CRH;
case ERH;
case PRH;
case SRH;
case WRH;
}
10 changes: 10 additions & 0 deletions src/Exceptions/ForecastOfficeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace BenjaminHansen\NWS\Exceptions;

use Exception;

class ForecastOfficeException extends Exception
{
//
}
2 changes: 1 addition & 1 deletion src/Features/ForecastOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function email(): string
return $this->data->email;
}

public function address(): string
public function address(): object
{
return $this->data->address;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function term(string $term): null|object
return $this->get()->where('term', $term)->first();
}

public function definition(string $term): string|null
public function define(string $term): string|null
{
return $this->get()->where('term', $term)->first()?->definition;
}
Expand Down

0 comments on commit c9f86ef

Please sign in to comment.