Skip to content

Commit

Permalink
add url method to language enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv committed Dec 13, 2023
1 parent 032dfab commit 7f27d71
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/FetchMeditation/EnglishJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://www.jftna.org/jft/');
$data = HttpUtility::httpGet(JFTLanguage::English->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/EnglishSPAD.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getLanguage(): SPADLanguage
public function fetch(): SPADEntry
{

$data = HttpUtility::httpGet('https://spadna.org');
$data = HttpUtility::httpGet(SPADLanguage::English->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/FrenchJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://jpa.narcotiquesanonymes.org/');
$data = HttpUtility::httpGet(JFTLanguage::French->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/GermanJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://narcotics-anonymous.de/artikel/nur-fuer-heute/');
$data = HttpUtility::httpGet(JFTLanguage::German->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/ItalianJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://na-italia.org/get-jft');
$data = HttpUtility::httpGet(JFTLanguage::Italian->url());
$data = json_decode($data, true)[0];
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
Expand Down
15 changes: 15 additions & 0 deletions src/FetchMeditation/JFTLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@ enum JFTLanguage
case Russian;
case Spanish;
case Swedish;

public function url(): string
{
return match ($this) {
JFTLanguage::English => 'https://www.jftna.org/jft/',
JFTLanguage::French => 'https://jpa.narcotiquesanonymes.org/',
JFTLanguage::German => 'https://narcotics-anonymous.de/artikel/nur-fuer-heute/',
JFTLanguage::Italian => 'https://na-italia.org/get-jft',
JFTLanguage::Japanese => 'https://najapan.org/just_for_today/',
JFTLanguage::Portuguese => 'https://www.na.org.br/meditacao/',
JFTLanguage::Russian => 'https://na-russia.org/eg',
JFTLanguage::Spanish => 'https://forozonalatino.org/wp-content/uploads/meditaciones/',
JFTLanguage::Swedish => 'https://www.nasverige.org/dagens-text/',
};
}
}
2 changes: 1 addition & 1 deletion src/FetchMeditation/JapaneseJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://najapan.org/just_for_today/');
$data = HttpUtility::httpGet(JFTLanguage::Japanese->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/PortugueseJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://www.na.org.br/meditacao/');
$data = HttpUtility::httpGet(JFTLanguage::Portuguese->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/RussianJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://na-russia.org/eg');
$data = HttpUtility::httpGet(JFTLanguage::Russian->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down
7 changes: 7 additions & 0 deletions src/FetchMeditation/SPADLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
enum SPADLanguage
{
case English;

public function url(): string
{
return match ($this) {
SPADLanguage::English => 'https://spadna.org',
};
}
}
2 changes: 1 addition & 1 deletion src/FetchMeditation/SpanishJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function fetch(): JFTEntry
{
$timezone = new \DateTimeZone('America/Mexico_City');
$date = new \DateTime('now', $timezone);
$data = HttpUtility::httpGet('https://forozonalatino.org/wp-content/uploads/meditaciones/' . $date->format('m/d') . '.html');
$data = HttpUtility::httpGet(JFTLanguage::Spanish->url() . $date->format('m/d') . '.html');
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="ISO-8859-1">' . $data);
Expand Down
2 changes: 1 addition & 1 deletion src/FetchMeditation/SwedishJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getLanguage(): JFTLanguage

public function fetch(): JFTEntry
{
$data = HttpUtility::httpGet('https://www.nasverige.org/dagens-text/');
$data = HttpUtility::httpGet(JFTLanguage::Swedish->url());
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8">' . $data);
Expand Down

0 comments on commit 7f27d71

Please sign in to comment.