adding poi route and endpoint. Using POST to send the lat lon to get poi by boundaries
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 18 Jul 2019 02:47:10 +0000 (22:47 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 18 Jul 2019 02:47:10 +0000 (22:47 -0400)
setup/routes.php
setup/routes/pointsOfInterest.php [new file with mode: 0644]

index 44fd9b7..de0f29c 100644 (file)
@@ -22,4 +22,5 @@ require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php';
  * Require the routes
  */
 require_once 'routes/dashboard.php';
-require_once 'routes/members.php';
\ No newline at end of file
+require_once 'routes/members.php';
+require_once 'routes/pointsOfInterest.php';
\ No newline at end of file
diff --git a/setup/routes/pointsOfInterest.php b/setup/routes/pointsOfInterest.php
new file mode 100644 (file)
index 0000000..950b1d4
--- /dev/null
@@ -0,0 +1,117 @@
+<?php 
+/**
+ * Gaslight Media Members Database
+ * GLM Members Misc Routes For API
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+/**
+ * Require the Contact Data Class.
+ */
+
+
+/**
+ * Documentation for Wordpress API and adding custom endpoints.
+ * https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
+ */
+class GLMA_POI_Rest_Controller
+{
+    /**
+     * __construct
+     *
+     * Class Constructor
+     *
+     * @param $wpdb   Wordpress wpdb Database Object
+     * @param $config GlmAssociate config array
+     */
+    public function __construct( $wpdb, $config )
+    {
+        $this->namespace     = 'glm/v1/';
+        $this->resource_name = 'poi';
+
+        // Setup wpdb and config
+        $this->wpdb   = $wpdb;
+        $this->config = $config;
+    }
+
+    /**
+     * register_routes
+     *
+     * Registers the routes for this class.
+     *
+     * @return void
+     */
+    public function register_routes()
+    {
+        // Members Route
+        register_rest_route(
+            $this->namespace,       // namespace
+            $this->resource_name ,  // resource_name
+            array(      // array of arrays for multiple methods. Add more arrays for different endpoints.
+                array(  // endpoint for getting members
+                    'methods'  => WP_REST_Server::CREATABLE,
+                    'callback' => function( $request ) {
+                        // Callback function can be a lot shorter.
+                        // You could just create a new model to get the results in an array
+                        // and use return rest_ensure_response( $data );
+      
+
+                        return rest_ensure_response( $request );
+                    },
+                )
+            )
+        );
+
+    }
+
+    public function get_collection_params(){
+        return array(
+            'page' => array(
+                'description'       => 'Current page of the collection',
+                'type'              => 'integer',
+                'default'           => 1,
+                'sanitize_callback' => 'absint',
+            ),
+            'per_page' => array(
+                'description'       => 'Maximum number of items to be returned in result set.',
+                'type'              => 'integer',
+                'default'           => 10,
+                'sanitize_callback' => 'absint',
+            ),
+            'search' => array(
+                'description'       => 'Limit results to those matching a string',
+                'type'              => 'string',
+                'sanitize_callback' => 'sanitize_text_field',
+            ),
+        );
+    }
+
+    public function authorization_status_code(){
+        $status = 401;
+
+        if ( is_user_logged_in() ) {
+            $status = 403;
+        }
+        return $status;
+    }
+
+}
+
+/**
+ * Create Action for the REST API Route.
+ */
+ add_action(
+     'rest_api_init',
+     function(){
+         $controller = new GLMA_POI_Rest_Controller( $this->wpdb, $this->config );
+         $controller->register_routes();
+     }
+ );