From 844567b299de400fa12a0cf264878588c377cafc Mon Sep 17 00:00:00 2001 From: pineros <61841991+pineros@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:15:11 -0400 Subject: [PATCH 1/9] Managed by Terraform --- .github/workflows/thirteen.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/thirteen.yml b/.github/workflows/thirteen.yml index 34d48a1..f9b95d7 100644 --- a/.github/workflows/thirteen.yml +++ b/.github/workflows/thirteen.yml @@ -18,7 +18,7 @@ jobs: aws-region: "us-east-1" aws-access-key: ${{ secrets.DEV_AWS_CODEPIPELINE_ACCESS_KEY }} aws-secret-key: ${{ secrets.DEV_AWS_CODEPIPELINE_SECRET_KEY }} - pipeline-name: "Thirteen" + pipeline-name: "thirteen" - name: Trigger Thirteen PREPROD AWS CodePipeline uses: zulhfreelancer/aws-codepipeline-action@v1.0.7 if: github.ref == 'refs/heads/preprod' @@ -26,7 +26,7 @@ jobs: aws-region: "us-east-1" aws-access-key: ${{ secrets.PREPROD_AWS_CODEPIPELINE_ACCESS_KEY }} aws-secret-key: ${{ secrets.PREPROD_AWS_CODEPIPELINE_SECRET_KEY }} - pipeline-name: "Thirteen" + pipeline-name: "thirteen" - name: Trigger Thirteen PROD AWS CodePipeline uses: zulhfreelancer/aws-codepipeline-action@v1.0.7 if: github.ref == 'refs/heads/main' @@ -34,4 +34,4 @@ jobs: aws-region: "us-east-1" aws-access-key: ${{ secrets.PROD_AWS_CODEPIPELINE_ACCESS_KEY }} aws-secret-key: ${{ secrets.PROD_AWS_CODEPIPELINE_SECRET_KEY }} - pipeline-name: "Thirteen" \ No newline at end of file + pipeline-name: "thirteen" \ No newline at end of file From 6bacbf97f6a94c2dbba843350d6ce81641dbab0b Mon Sep 17 00:00:00 2001 From: pineros <61841991+pineros@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:33:03 -0400 Subject: [PATCH 2/9] Managed by Terraform --- .github/workflows/thirteen.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/thirteen.yml b/.github/workflows/thirteen.yml index 34d48a1..f9b95d7 100644 --- a/.github/workflows/thirteen.yml +++ b/.github/workflows/thirteen.yml @@ -18,7 +18,7 @@ jobs: aws-region: "us-east-1" aws-access-key: ${{ secrets.DEV_AWS_CODEPIPELINE_ACCESS_KEY }} aws-secret-key: ${{ secrets.DEV_AWS_CODEPIPELINE_SECRET_KEY }} - pipeline-name: "Thirteen" + pipeline-name: "thirteen" - name: Trigger Thirteen PREPROD AWS CodePipeline uses: zulhfreelancer/aws-codepipeline-action@v1.0.7 if: github.ref == 'refs/heads/preprod' @@ -26,7 +26,7 @@ jobs: aws-region: "us-east-1" aws-access-key: ${{ secrets.PREPROD_AWS_CODEPIPELINE_ACCESS_KEY }} aws-secret-key: ${{ secrets.PREPROD_AWS_CODEPIPELINE_SECRET_KEY }} - pipeline-name: "Thirteen" + pipeline-name: "thirteen" - name: Trigger Thirteen PROD AWS CodePipeline uses: zulhfreelancer/aws-codepipeline-action@v1.0.7 if: github.ref == 'refs/heads/main' @@ -34,4 +34,4 @@ jobs: aws-region: "us-east-1" aws-access-key: ${{ secrets.PROD_AWS_CODEPIPELINE_ACCESS_KEY }} aws-secret-key: ${{ secrets.PROD_AWS_CODEPIPELINE_SECRET_KEY }} - pipeline-name: "Thirteen" \ No newline at end of file + pipeline-name: "thirteen" \ No newline at end of file From ed6041dbd60466c6e040055d51f88e1b1377d79e Mon Sep 17 00:00:00 2001 From: William Tam Date: Mon, 25 Sep 2023 16:13:24 -0400 Subject: [PATCH 3/9] abstract listing the available callsigns --- classes/class-pbs-check-dma.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/classes/class-pbs-check-dma.php b/classes/class-pbs-check-dma.php index d93f335..e012bea 100644 --- a/classes/class-pbs-check-dma.php +++ b/classes/class-pbs-check-dma.php @@ -17,7 +17,7 @@ public function __construct() { $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; $this->assets_url = trailingslashit(plugin_dir_url( __DIR__ ) ) . 'assets'; $this->token = 'pbs_check_dma'; - $this->version = '0.93'; + $this->version = '0.94'; // Load public-facing style sheet and JavaScript. //add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); @@ -257,6 +257,20 @@ public function callsign_available_in_zipcode($zipcode, $desired_callsign = '') return false; } } + + $available_callsigns = $this->list_available_callsigns_in_zipcode($zipcode); + if (in_array($desired_callsign, $available_callsigns)) { + return true; + } + // no luck finding the desired callsign + return false; + } + + public function list_available_callsigns_in_zipcode($zipcode) { + if (empty($zipcode) || !(preg_match('/^(\d{5})?$/', $zipcode))) { + // zipcode is either empty or isn't 5 digits + return false; + } $callsign_url = "https://services.pbs.org/callsigns/zip/"; $combined_url = $callsign_url . $zipcode . '.json'; $call_sign = false; @@ -266,6 +280,7 @@ public function callsign_available_in_zipcode($zipcode, $desired_callsign = '') } $body = $response['body']; // use the content $parsed = json_decode($body, TRUE); + $available_callsigns = []; foreach($parsed['$items'] as $key) { foreach($key['$links'][0]['$links'] as $link) { if (isset( $link['$links'] )) { @@ -273,19 +288,17 @@ public function callsign_available_in_zipcode($zipcode, $desired_callsign = '') if($i['$relationship'] == "flagship"){ if( $key['confidence'] == 100 ){ $call_sign = $key['$links'][0]['callsign']; - if ( $call_sign == $desired_callsign ){ - return true; - } + array_push($available_callsigns, $call_sign); } } - } + } } } } - // no luck finding the desired callsign - return false; + return $available_callsigns; } + public function visitor_ip_is_in_dma() { $ip = $this->get_remote_ip_address(); $location = $this->get_location_from_ip($ip); From a3a0915e17540f46f49f0b30f624564c1ada2b05 Mon Sep 17 00:00:00 2001 From: William Tam Date: Tue, 26 Sep 2023 17:02:20 -0400 Subject: [PATCH 4/9] list_available_station_ids_in_zipcode --- classes/class-pbs-check-dma.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/classes/class-pbs-check-dma.php b/classes/class-pbs-check-dma.php index e012bea..561c238 100644 --- a/classes/class-pbs-check-dma.php +++ b/classes/class-pbs-check-dma.php @@ -298,6 +298,38 @@ public function list_available_callsigns_in_zipcode($zipcode) { return $available_callsigns; } + public function list_available_station_ids_in_zipcode($zipcode) { + if (empty($zipcode) || !(preg_match('/^(\d{5})?$/', $zipcode))) { + // zipcode is either empty or isn't 5 digits + return false; + } + $callsign_url = "https://services.pbs.org/callsigns/zip/"; + $combined_url = $callsign_url . $zipcode . '.json'; + $call_sign = false; + $response = wp_remote_get($combined_url, array()); + if (! is_array( $response ) || empty($response['body'])) { + return array('errors' => $response); + } + $body = $response['body']; // use the content + $parsed = json_decode($body, TRUE); + $available_station_ids = []; + foreach($parsed['$items'] as $key) { + foreach($key['$links'][0]['$links'] as $link) { + if (isset( $link['$links'] )) { + foreach($link['$links'] as $i) { + if($i['$relationship'] == "flagship"){ + if( $key['confidence'] == 100 ){ + $station_id = $link['pbs_id']; + array_push($available_station_ids, $station_id); + } + } + } + } + } + } + return $available_station_ids; + } + public function visitor_ip_is_in_dma() { $ip = $this->get_remote_ip_address(); From c0c8ca6e9399942fbe96013ff043dd9f6909bd3d Mon Sep 17 00:00:00 2001 From: William Tam Date: Thu, 5 Oct 2023 11:06:08 -0400 Subject: [PATCH 5/9] station attr and list by state --- classes/class-pbs-check-dma.php | 59 ++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/classes/class-pbs-check-dma.php b/classes/class-pbs-check-dma.php index 561c238..d867446 100644 --- a/classes/class-pbs-check-dma.php +++ b/classes/class-pbs-check-dma.php @@ -305,7 +305,6 @@ public function list_available_station_ids_in_zipcode($zipcode) { } $callsign_url = "https://services.pbs.org/callsigns/zip/"; $combined_url = $callsign_url . $zipcode . '.json'; - $call_sign = false; $response = wp_remote_get($combined_url, array()); if (! is_array( $response ) || empty($response['body'])) { return array('errors' => $response); @@ -330,6 +329,64 @@ public function list_available_station_ids_in_zipcode($zipcode) { return $available_station_ids; } + public function list_localization_states() { + $services_endpoint = "https://services.pbs.org/states.json"; + $response = wp_remote_get($services_endpoint, array()); + if (! is_array( $response ) || empty($response['body'])) { + return array('errors' => $response); + } + $body = $response['body']; // use the content + $parsed = json_decode($body, TRUE); + $states = []; + foreach($parsed['$items'] as $item) { + $states[$item['state']] = array('state_name' => $item['state_name'], 'station_list' => $item['$self']); + } + return $states; + } + + public function list_stations_in_state($state) { + // this function expects a 2-letter state. Besides the 50, PBS has stations in PR, AS, UM, MP, VI + if (empty($state)) { + return; + } + $services_endpoint = "https://services.pbs.org/states/"; + $response = wp_remote_get($services_endpoint . $state . "json", array()); + if (! is_array( $response ) || empty($response['body'])) { + return array('errors' => $response); + } + $body = $response['body']; // use the content + $parsed = json_decode($body, TRUE); + $stations = []; + foreach($parsed['$items'] as $item) { + if (isset($item['pbs_id'])) { + $stations[$item['pbs_id']] = array( + 'common_name'=>$item['common_name'], + 'mailing_city' => $item['mailing_city'], + 'mailing_state' => $item['mailing_state'], + 'callsign' => $item['$links'][1]['callsign'] + ); + } + } + return $stations; + } + + public function get_station_attributes($station_id) { + if (empty($station_id)) { + return; + } + $services_endpoint = "https://station.services.pbs.org/api/public/v1/stations/"; + $response = wp_remote_get($services_endpoint . $station_id . "/", array()); + if (! is_array( $response ) || empty($response['body'])) { + return array('errors' => $response); + } + $body = $response['body']; // use the content + $parsed = json_decode($body, TRUE); + if (isset($parsed['data']['attributes'])){ + return $parsed['data']['attributes']; + } + return false; + } + public function visitor_ip_is_in_dma() { $ip = $this->get_remote_ip_address(); From 8988649d00122b0a6e379fb0848c971cb9bddd76 Mon Sep 17 00:00:00 2001 From: pineros <61841991+pineros@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:11:01 -0400 Subject: [PATCH 6/9] Managed by Terraform From 1b72d0dcacf71e914ec15b1afba69ac84e3b7a1f Mon Sep 17 00:00:00 2001 From: pineros <61841991+pineros@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:41:17 -0500 Subject: [PATCH 7/9] Managed by Terraform From c5fb51c5c6b7f450f2408c678e5843b91729c0b2 Mon Sep 17 00:00:00 2001 From: pineros <61841991+pineros@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:43:18 -0500 Subject: [PATCH 8/9] Managed by Terraform From 278357755284e316e907d2539dc4b56323de937b Mon Sep 17 00:00:00 2001 From: pineros <61841991+pineros@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:43:15 -0500 Subject: [PATCH 9/9] Managed by Terraform