Plugin Directory

Changeset 1437341


Ignore:
Timestamp:
06/15/2016 09:06:37 PM (10 years ago)
Author:
ppohler
Message:

add custom api endpoint

Location:
rets-rabbit/trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • rets-rabbit/trunk/composer.json

    r1102919 r1437341  
    11{
    22    "require": {
    3       "anecka/retsrabbit": "dev-master"
     3      "anecka/retsrabbit": "1.3"
    44    }
    55}
  • rets-rabbit/trunk/composer.lock

    r1263335 r1437341  
    55        "This file is @generated automatically"
    66    ],
    7     "hash": "16eaf1beb807f58c3e11f63147ee2159",
    8     "content-hash": "63ec7e4368a0fc755eb9e953a4124e37",
     7    "hash": "8543c88d4bff4c80c4da2baece7b69a5",
     8    "content-hash": "8f80d37d8cb62ca415e8f1e0d07d2745",
    99    "packages": [
    1010        {
    1111            "name": "anecka/retsrabbit",
    12             "version": "dev-master",
     12            "version": "1.3",
    1313            "source": {
    1414                "type": "git",
    1515                "url": "https://github.com/patpohler/retsrabbit-php-sdk.git",
    16                 "reference": "3c4e4f2ff917e52d85dbeb10ec39745f51f82ef7"
     16                "reference": "d8408734d2757440009a5c6b1d4312d7d0e61fff"
    1717            },
    1818            "dist": {
    1919                "type": "zip",
    20                 "url": "https://api.github.com/repos/patpohler/retsrabbit-php-sdk/zipball/3c4e4f2ff917e52d85dbeb10ec39745f51f82ef7",
    21                 "reference": "3c4e4f2ff917e52d85dbeb10ec39745f51f82ef7",
     20                "url": "https://api.github.com/repos/patpohler/retsrabbit-php-sdk/zipball/d8408734d2757440009a5c6b1d4312d7d0e61fff",
     21                "reference": "d8408734d2757440009a5c6b1d4312d7d0e61fff",
    2222                "shasum": ""
    2323            },
     
    3939            "notification-url": "https://packagist.org/downloads/",
    4040            "description": "This is the PHP SDK for RetsRabbit",
    41             "time": "2015-10-02 19:57:43"
     41            "time": "2016-05-31 18:18:51"
    4242        },
    4343        {
     
    163163    "aliases": [],
    164164    "minimum-stability": "stable",
    165     "stability-flags": {
    166         "anecka/retsrabbit": 20
    167     },
     165    "stability-flags": [],
    168166    "prefer-stable": false,
    169167    "prefer-lowest": false,
  • rets-rabbit/trunk/docs/rets_rabbit_for_wordpress_user_guide.md

    r1263744 r1437341  
    33*Author:* Patrick Pohler
    44
    5 *Version:* 1.0.6
     5*Version:* 1.0.7
    66
    77*URL:* <http://retsrabbit.com>
     
    65652. A Rets Rabbit account with a Client ID & Client Secret. To signup for an account, visit *RetsRabbit.com*.
    6666
    67 Once you have your Rets Rabbit Client ID & Client Secret, click the Rets Rabbit section in the Wordpress Dashboard and enter them in the "Rets Rabbit Settings" page.
     67Once you have your Rets Rabbit Client ID & Client Secret, click the Rets Rabbit section in the Wordpress Dashboard and enter them in the "Rets Rabbit Settings" page. Optionally you might have a custom API endpoint (https://domain.retsrabbit.com/api), you can enter that into the "Rets Rabbit Settings" as well.
    6868
    6969Once that's saved, you can confirm your access is working by click on "Metadata" under the Rets Rabbit admin to view your local MLS's metadata.
  • rets-rabbit/trunk/readme.txt

    r1263744 r1437341  
    44Requires at least: 3.0.1
    55Tested up to: 4.3
    6 Stable tag: 1.0.6
     6Stable tag: 1.0.7
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    103103== Changelog ==
    104104
     105 = 1.0.7 - Add custom API endpoint
     106
    105107 = 1.0.6 - Add caching options
    106108
  • rets-rabbit/trunk/retsrabbit.php

    r1263744 r1437341  
    2222add_filter( 'query_vars', 'add_retsrabbit_query_vars' );
    2323
     24include_once(dirname(__FILE__).'/rr_install.php');
    2425require_once(dirname(__FILE__).'/rr_adapter.php');
    2526require_once(dirname(__FILE__).'/rr_shortcodes.php');
     
    2728include_once(dirname(__FILE__).'/settings.php');
    2829
    29 
     30register_activation_hook(__FILE__, 'retsrabbit_update_check' );
    3031
    3132?>
  • rets-rabbit/trunk/rr_actions.php

    r1263744 r1437341  
    55
    66function retsrabbit_handle_search() {
     7    global $wpdb;
    78    $params = array();
    89    if(isset($_POST)) {
     
    1314                $new_key = str_replace('rets:', '', $key);
    1415
    15                 $val = $value;//sanitize_text_field($value);
     16                if(is_array($value)) {
     17                    $val = implode("|", $value);
     18                } else {
     19                    $val = $value;//sanitize_text_field($value);
     20                }
    1621
    1722                //even though we don't send blank values to the RR API, save them anyway so
     
    2934        $sort_option = ((isset($_POST['sort_option']) && $_POST['sort_option'] != '') ? $_POST['sort_option'] : "");
    3035
     36        $data = array(
     37            'params'         => $params,
     38            'limit'          => $limit,
     39            'result_page'    => $results_page,
     40            'orderby'        => $orderby,
     41            'sort_order'     => $sort_order,
     42            'sort_option'    => $sort_option,
     43            'page'           => 1
     44        );
     45
     46        $key = md5(serialize($data));
     47
    3148        if(sizeof($params) > 0) {
    32             set_transient('rr-search-query', null);
    33             $data = array(
    34                 'params'         => $params,
    35                 'limit'          => $limit,
    36                 'result_page'    => $results_page,
    37                 'orderby'        => $orderby,
    38                 'sort_order'     => $sort_order,
    39                 'sort_option'    => $sort_option,
    40                 'page'           => 1
     49            $table_name = $wpdb->prefix . 'retsrabb_search';
     50            $wpdb->insert(
     51                $table_name,
     52                array(
     53                    'search_key' => "$key",
     54                    'search_value' => serialize($data),
     55                )
    4156            );
    42             set_transient('rr-search-query', $data);
    43 
    4457            //we save the search parameters and redirect to the results page
    4558            //the results page actually hits the RR API and runs the search
    4659
    47             wp_redirect($results_page);
     60            wp_redirect($results_page."?key=".$key);
    4861            exit;
    4962        }
     
    5467    if($option == "rr-client-id"){
    5568        delete_transient('retsrabbit-access-code');
    56         delete_transient('rr-metadata');       
     69        delete_transient('rr-metadata');
    5770    }
    5871}
  • rets-rabbit/trunk/rr_adapter.php

    r1263744 r1437341  
    1919            $client_secret = get_option('rr-client-secret');
    2020
     21            $this->_getAPIEndpoint($client);
     22
    2123            if($client_id && $client_secret) {
    2224                $client->getAccessCode($client_id, $client_secret);
     
    3133    public function metadata() {
    3234        $client = new Client($this->access_token);
     35        $this->_getAPIEndpoint($client);
    3336
    3437        if($this->access_token) {
     
    5558    public function get_listing($mls_id, $num_photos = -1, $cache = false, $cache_duration = 4) {
    5659        $client = new Client($this->access_token, true);
     60        $this->_getAPIEndpoint($client);
     61
    5762        $servers = $client->getServers();
    5863        $server_hash = $servers[0]['server_hash']; //dangerous, need to adjust this
     
    9297    public function run_search($params, $limit, $num_photos, $orderby = "", $sort_order = "", $sort_option = "", $cache = false, $cache_duration = 4) {
    9398        $client = new Client($this->access_token, true);
     99        $this->_getAPIEndpoint($client);
     100
    94101        $servers = $client->getServers();
    95102        $server_hash = $servers[0]['server_hash']; //dangerous, need to adjust this
     
    118125        $this->total_records = $response['total_records'];
    119126
    120         foreach($response['results'] as $listing) {
    121             $fields = array();
    122             $variable = array();
    123 
    124             $variable['mls_id'] = $listing['mls_id'];
    125             foreach($listing['fields'] as $key => $field) {
    126                 $variable[$key] = $field;
    127             }
    128 
    129            $variable = $this->_photo_array_builder($listing, $variable, $num_photos);
    130            $variables[] = $variable;
     127        $variables['total_records'] = $this->total_records;
     128        $variables['params'] = $params;
     129
     130        if (is_array($response['results']) || is_object($response['results'])){
     131            foreach($response['results'] as $listing) {
     132                $fields = array();
     133                $variable = array();
     134
     135                $variable['mls_id'] = $listing['mls_id'];
     136                foreach($listing['fields'] as $key => $field) {
     137                    $variable[$key] = $field;
     138                }
     139
     140               $variable = $this->_photo_array_builder($listing, $variable, $num_photos);
     141               $variables[] = $variable;
     142            }
    131143        }
    132144
     
    166178
    167179            foreach($query_params['params'] as $param => $value) {
    168                 $form_data[$param] = $value;
     180                if(strpos($value, "|") !== FALSE) {
     181                    $form_data[$param] = explode("|", $value);
     182                } else {
     183                    $form_data[$param] = $value;
     184                }
    169185            }
    170186        }
     
    229245    }
    230246
     247    private function _getAPIEndpoint(&$client) {
     248        $api_endpoint = get_option('rr-api-endpoint');
     249        if($api_endpoint != '' && $api_endpoint != null) {
     250            if(substr($api_endpoint, -1) != '/')
     251                $api_endpoint .= '/';
     252
     253            $client->setEndpoint($api_endpoint);
     254        }
     255    }
    231256
    232257    private function _pagination($total_pages) {
  • rets-rabbit/trunk/rr_shortcodes.php

    r1263744 r1437341  
    3838    }
    3939
     40    static function breadcrumb_search ($atts, $content = null, $tag) {
     41        global $wp_query;
     42        $city = get_query_var('city', '');
     43        $subdivision = get_query_var('subdivision', '');
     44
     45        $params = [];
     46
     47        if($city !== ''){
     48            $city = urldecode($city);
     49            $params['LIST_39'] = $city;
     50        }
     51
     52        if($subdivision !== ''){
     53            $subdivision = urldecode($subdivision);
     54            if(strpos($subdivision, '-') !== false){
     55                $subdivision = "\'".$subdivision."\'";
     56            }
     57            $params['LIST_131:startswith'] = $subdivision;
     58        }
     59
     60        $atts['params'] = json_encode($params);
     61
     62        return self::listings($atts, $content, $tag);
     63    }
     64
    4065    static function search_form($atts, $content = null, $tag = null) {
    41         global $wp_query;
     66        global $wp_query, $wpdb;
     67        //global $wpdb;
    4268        $template = (isset($atts['template']) ? $atts['template'] : 'search-form.php');
    4369        $rr_adapter = new rr_adapter();
    44         $query_params = get_transient('rr-search-query');
     70
     71        $key = (isset($_GET['key']) ? $_GET['key'] : '');
     72        $query_params = "";
     73        if($key != "") {
     74            $query_params = $wpdb->get_var("SELECT search_value FROM {$wpdb->prefix}retsrabb_search WHERE search_key = '$key'");
     75            $query_params = unserialize($query_params);
     76        }
     77
    4578        return $rr_adapter->generate_form($template, $query_params);
    4679    }
    4780
    4881    static function search_results($atts, $content = null, $tag = null) {
    49         global $wp_query;
     82        global $wp_query, $wpdb;
    5083        $template = (isset($atts['template']) ? $atts['template'] : 'results.php');
    5184        $limit = (isset($atts['limit']) ? $atts['limit'] : get_option('rr-results-per-page', 10));
     
    5588        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
    5689
    57         $query_params = get_transient('rr-search-query');
     90        $key = (isset($_GET['key']) ? $_GET['key'] : '');
     91        $query_params = "";
     92        if($key != "") {
     93            $query_params = $wpdb->get_var("SELECT search_value FROM {$wpdb->prefix}retsrabb_search WHERE search_key = '$key'");
     94            $query_params = unserialize($query_params);
     95        }
     96
    5897        $params = $query_params['params'];
    5998        $orderby = $query_params['orderby'];
     
    80119
    81120add_shortcode("retsrabbit-search-results", array("retsrabbit_shortcodes", "search_results"));
     121
     122add_shortcode("retsrabbit-breadcrumb-search", array("retsrabbit_shortcodes", "breadcrumb_search"));
    82123?>
  • rets-rabbit/trunk/settings.php

    r1102922 r1437341  
    1010
    1111    add_action('admin_init', 'retsrabbit_register_settings');
     12
     13    add_action('wp_loaded', 'retsrabbit_build_pills');
    1214}
    1315
    1416function retsrabbit_register_settings() {
     17    register_setting('rr-settings-group', 'rr-api-endpoint');
    1518    register_setting('rr-settings-group', 'rr-client-id');
    1619    register_setting('rr-settings-group', 'rr-client-secret');
     
    4548                <th scope="row">Client Secret</th>
    4649                <td><input type="text" class="regular-text" name="rr-client-secret" value="<?php echo get_option('rr-client-secret'); ?>"></td>
     50            </tr>
     51            <tr valign="top">
     52                <th scope="row">Custom API Endpoint (optional)</th>
     53                <td><input type="text" class="regular-text" name="rr-api-endpoint" value="<?php echo get_option('rr-api-endpoint'); ?>"></td>
    4754            </tr>
    4855            <tr valign="top">
     
    157164    <?php
    158165}
     166
     167function build_pills($params) {
     168    $pills = '';
     169
     170    if(sizeof($params)){
     171        $rr_adapter = new rr_adapter();
     172        $table_data = array();
     173
     174        $types = $rr_adapter->metadata();
     175
     176        if(sizeof($types)){
     177            //go through all the search params
     178            foreach($params as $key => $value){
     179                if($value !== ''){
     180                    $key = str_replace(":startswith", "", $key);
     181                    $key = str_replace(":indexof", "", $key);
     182                    //go through all types
     183                    foreach ($types as $type) {
     184                        //only hit property type
     185                        if($type->Resource == "Property") {
     186                            //go through the classes
     187                            foreach ($type->Data as $class) {
     188                                $fields = $class->Fields;
     189                                if($fields && sizeof($fields) > 0) {
     190                                    //go through all fields of the class
     191                                    foreach ($fields as $field) {
     192                                        if($field->SystemName === $key){
     193                                            $pills .= '<div class="search-pill">';
     194
     195                                            //get rid of escaped quotes due to hyphen in string
     196                                            if($value[0] === '\\'){
     197                                                $value = substr($value, 0, -2);
     198                                                $value = substr($value, 2, strlen($value));
     199                                            }
     200                                            $pills .= $field->LongName.': '.$value;
     201                                            $pills .= '</div>';
     202                                            break 3;
     203                                        }
     204                                    }
     205                                }
     206                            }
     207                        }
     208                    }
     209                }
     210            }
     211        }
     212    }
     213
     214    return $pills;
     215}
    159216?>
  • rets-rabbit/trunk/vendor/anecka/retsrabbit/README.md

    r1102919 r1437341  
    88    //New instance of the client
    99    $client = new Anecka\retsrabbit\RetsRabbitClient($access_token);
     10
     11    //If using a custom API endpoint (ex. https://<domain>.retsrabbit.com/api)
     12    //If your endpoint is https//api.retsrabbit.com you don't need to set this
     13    $client->setEndpoint($endpoint_url);
    1014   
    1115    //Get a listing from the MLS w/ an id of '5456655'
     
    3539### Authentication
    3640
    37 In order to use the libary, you need to have valid client credentials to Rets Rabbit. You'll need the credentials to create an access token in order to sender requests to the API.
     41In order to use the libary, you need to have valid client credentials to Rets Rabbit and an API endpoint URL (usually in the form of https://<domain>.retrabbit.com/api). You'll need the credentials to create an access token in order to sender requests to the API.
    3842
    3943    $client = new Anecka\retsrabbit\RetsRabbitClient;
     44
     45    //If using a custom API endpoint (ex. https://<domain>.retsrabbit.com/api)
     46    //If your endpoint is https//api.retsrabbit.com you don't need to set this
     47    $client->setEndpoint($endpoint_url);
    4048   
    4149    $client->getAccessCode($client_id, $client_secret);
     
    4654    /* instantiating the client by passing an access_token */
    4755   
    48     $client = new Anecka\retsrabbit\RetsRabbitClient($_SESSION['access_token']);
     56    $client = new Anecka\retsrabbit\RetsRabbitClient($_SESSION['access_token'], $endpoint_url);
    4957   
    5058### Getting a list of servers
     
    110118*****
    111119
    112 &copy;2014 Anecka, LLC All rights reserved.
     120&copy;2016 Anecka, LLC All rights reserved.
    113121   
  • rets-rabbit/trunk/vendor/anecka/retsrabbit/src/Anecka/retsrabbit/RetsRabbitClient.php

    r1263335 r1437341  
    1010class RetsRabbitClient {
    1111
     12  /* if you're using a custom domain: ex https://<domain>.retsrabbit.com, you'll need to set this to https://<domain>.retsrabbit.com/api/
     13  using setEndpoint() */
    1214  var $endpoint = "https://api.retsrabbit.com/";
    1315  var $access_token = "";
     
    2325    if($access_token != "") $this->setAccessToken($access_token);
    2426  }
     27
    2528
    2629  public function _obj($response) {
     
    7578  }
    7679
    77   public function getAccessCode($client_id, $client_secret, $scope = "scope1") {
     80  public function getAccessCode($client_id, $client_secret, $scope = "") {
    7881
    7982    $response = $this->client->post($this->endpoint."oauth/access_token", [
     
    125128    return $this->_obj($response);
    126129  }
     130
     131  public function getOpenHousesForListing($server_hash, $listing_id) {
     132      $response = $this->_get("v1/$server_hash/open_house/$listing_id");
     133
     134      return $this->_obj($response);
     135  }
     136
     137  public function getSearchOpenHouses($server_hash, $search) {
     138      $response = $this->_get("v1/$server_hash/open_house/search", $search);
     139
     140      return $this->_obj($response);
     141  }
    127142}
  • rets-rabbit/trunk/vendor/composer/ClassLoader.php

    r1102919 r1437341  
    1414
    1515/**
    16  * ClassLoader implements a PSR-0 class loader
    17  *
    18  * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
     16 * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
    1917 *
    2018 *     $loader = new \Composer\Autoload\ClassLoader();
     
    4038 * @author Fabien Potencier <fabien@symfony.com>
    4139 * @author Jordi Boggiano <j.boggiano@seld.be>
     40 * @see    http://www.php-fig.org/psr/psr-0/
     41 * @see    http://www.php-fig.org/psr/psr-4/
    4242 */
    4343class ClassLoader
     
    148148     *
    149149     * @param string       $prefix  The prefix/namespace, with trailing '\\'
    150      * @param array|string $paths   The PSR-0 base directories
     150     * @param array|string $paths   The PSR-4 base directories
    151151     * @param bool         $prepend Whether to prepend the directories
    152152     *
  • rets-rabbit/trunk/vendor/composer/autoload_files.php

    r1102919 r1437341  
    77
    88return array(
    9     $vendorDir . '/guzzlehttp/streams/src/functions.php',
    10     $vendorDir . '/guzzlehttp/guzzle/src/functions.php',
     9    'fad373d645dd668e85d44ccf3c38fbd6' => $vendorDir . '/guzzlehttp/streams/src/functions.php',
     10    '154e0d165f5fe76e8e9695179d0a7345' => $vendorDir . '/guzzlehttp/guzzle/src/functions.php',
    1111);
  • rets-rabbit/trunk/vendor/composer/autoload_real.php

    r1102919 r1437341  
    2424        spl_autoload_unregister(array('ComposerAutoloaderInit622f64cd02c5d1abe8bd9e50d8c9eb39', 'loadClassLoader'));
    2525
    26         $map = require __DIR__ . '/autoload_namespaces.php';
    27         foreach ($map as $namespace => $path) {
    28             $loader->set($namespace, $path);
    29         }
     26        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
     27        if ($useStaticLoader) {
     28            require_once __DIR__ . '/autoload_static.php';
    3029
    31         $map = require __DIR__ . '/autoload_psr4.php';
    32         foreach ($map as $namespace => $path) {
    33             $loader->setPsr4($namespace, $path);
    34         }
     30            call_user_func(\Composer\Autoload\ComposerStaticInit622f64cd02c5d1abe8bd9e50d8c9eb39::getInitializer($loader));
     31        } else {
     32            $map = require __DIR__ . '/autoload_namespaces.php';
     33            foreach ($map as $namespace => $path) {
     34                $loader->set($namespace, $path);
     35            }
    3536
    36         $classMap = require __DIR__ . '/autoload_classmap.php';
    37         if ($classMap) {
    38             $loader->addClassMap($classMap);
     37            $map = require __DIR__ . '/autoload_psr4.php';
     38            foreach ($map as $namespace => $path) {
     39                $loader->setPsr4($namespace, $path);
     40            }
     41
     42            $classMap = require __DIR__ . '/autoload_classmap.php';
     43            if ($classMap) {
     44                $loader->addClassMap($classMap);
     45            }
    3946        }
    4047
    4148        $loader->register(true);
    4249
    43         $includeFiles = require __DIR__ . '/autoload_files.php';
    44         foreach ($includeFiles as $file) {
    45             composerRequire622f64cd02c5d1abe8bd9e50d8c9eb39($file);
     50        if ($useStaticLoader) {
     51            $includeFiles = Composer\Autoload\ComposerStaticInit622f64cd02c5d1abe8bd9e50d8c9eb39::$files;
     52        } else {
     53            $includeFiles = require __DIR__ . '/autoload_files.php';
     54        }
     55        foreach ($includeFiles as $fileIdentifier => $file) {
     56            composerRequire622f64cd02c5d1abe8bd9e50d8c9eb39($fileIdentifier, $file);
    4657        }
    4758
     
    5061}
    5162
    52 function composerRequire622f64cd02c5d1abe8bd9e50d8c9eb39($file)
     63function composerRequire622f64cd02c5d1abe8bd9e50d8c9eb39($fileIdentifier, $file)
    5364{
    54     require $file;
     65    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
     66        require $file;
     67
     68        $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
     69    }
    5570}
  • rets-rabbit/trunk/vendor/composer/installed.json

    r1263335 r1437341  
    124124    {
    125125        "name": "anecka/retsrabbit",
    126         "version": "dev-master",
    127         "version_normalized": "9999999-dev",
     126        "version": "1.3",
     127        "version_normalized": "1.3.0.0",
    128128        "source": {
    129129            "type": "git",
    130130            "url": "https://github.com/patpohler/retsrabbit-php-sdk.git",
    131             "reference": "3c4e4f2ff917e52d85dbeb10ec39745f51f82ef7"
     131            "reference": "d8408734d2757440009a5c6b1d4312d7d0e61fff"
    132132        },
    133133        "dist": {
    134134            "type": "zip",
    135             "url": "https://api.github.com/repos/patpohler/retsrabbit-php-sdk/zipball/3c4e4f2ff917e52d85dbeb10ec39745f51f82ef7",
    136             "reference": "3c4e4f2ff917e52d85dbeb10ec39745f51f82ef7",
     135            "url": "https://api.github.com/repos/patpohler/retsrabbit-php-sdk/zipball/d8408734d2757440009a5c6b1d4312d7d0e61fff",
     136            "reference": "d8408734d2757440009a5c6b1d4312d7d0e61fff",
    137137            "shasum": ""
    138138        },
     
    143143            "phpunit/phpunit": "4.1.3"
    144144        },
    145         "time": "2015-10-02 19:57:43",
     145        "time": "2016-05-31 18:18:51",
    146146        "type": "library",
    147147        "installation-source": "source",
Note: See TracChangeset for help on using the changeset viewer.