HJI WP Membership Code Reference
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Slipstream API Docs

Namespaces

  • hji
    • AgentRoster
      • controllers
      • models
      • utils
    • common
      • factories
      • interfaces
      • models
      • utils
    • construction
      • admin
        • controllers
        • models
      • core
      • front
        • controllers
      • interfaces
      • models
        • listings
        • subdivisions
      • views
    • geofarms
      • common
      • controllers
      • models
      • widgets
    • homevalue
      • controllers
      • core
        • abstracts
      • models
    • lifestylefinder
    • listingstoblog
      • controllers
    • membership
      • abstracts
      • controllers
      • entities
      • extension
        • abstracts
        • interfaces
      • factories
      • includes
      • interfaces
      • models
        • data
        • webservice
          • abstracts
          • actions
          • interfaces
      • observers
      • services
    • recentsales
      • controllers
      • tinymce
      • widgets
    • ResponsiveIDX
      • abstracts
      • adapters
      • controllers
      • core
        • abstracts
      • entities
      • models
      • services
      • tinymce
      • utils
      • widgets
    • schools
      • controllers
      • tinymce
      • widgets
    • users
      • abstracts
      • admin
        • controllers
        • models
      • controllers
      • core
        • abstracts
      • entities
      • models
      • utils
  • None
  • REL
    • controllers
    • Models
    • Taxonomies
    • Utils
      • Convert
    • widgets

Classes

  • hji\AgentRoster\AgentRoster
  • hji\AgentRoster\controllers\AgentRosterAdmin
  • hji\AgentRoster\controllers\Testimonials
  • hji\AgentRoster\models\TestimonialsModel
  • hji\AgentRoster\utils\ContactForm
  • hji\common\factories\mcePluginFactory
  • hji\common\factories\WidgetTrioFactory
  • hji\common\interfaces\AbstractSettingsModel
  • hji\common\interfaces\Shortcode
  • hji\common\interfaces\Widget
  • hji\common\interfaces\WidgetShortcode
  • hji\common\models\Alerts
  • hji\common\models\GForms
  • hji\common\models\JsVars
  • hji\common\models\mcePluginModel
  • hji\common\models\Notices
  • hji\common\models\PluginJsVars
  • hji\common\utils\APIClient
  • hji\common\utils\Cookies
  • hji\common\utils\GFHelper
  • hji\common\utils\HTTP
  • hji\common\utils\ipAddress
  • hji\common\utils\MetaBoxes
  • hji\common\utils\Modal
  • hji\common\utils\Paths
  • hji\common\utils\SiteInfo
  • hji\common\utils\String
  • hji\common\utils\Updater
  • hji\common\utils\Validator
  • hji\common\utils\View
  • hji\common\utils\Views
  • hji\common\utils\WPCache
  • hji\common\utils\WPHelper
  • hji\construction\admin\AdminController
  • hji\construction\admin\controllers\GeneralPageController
  • hji\construction\admin\models\GeneralPageModel
  • hji\construction\App
  • hji\construction\core\Component
  • hji\construction\core\Controller
  • hji\construction\core\DataModel
  • hji\construction\core\DataObjectPostView
  • hji\construction\core\Model
  • hji\construction\core\Paths
  • hji\construction\core\PostModel
  • hji\construction\core\WebService
  • hji\construction\core\Widget
  • hji\construction\front\controllers\ListingsController
  • hji\construction\front\controllers\SubdivisionsController
  • hji\construction\front\FrontController
  • hji\construction\models\Images
  • hji\construction\models\Labels
  • hji\construction\models\listings\ListingModel
  • hji\construction\models\listings\ListingsGetFilters
  • hji\construction\models\listings\ListingsModel
  • hji\construction\models\listings\ListingsSearchFilters
  • hji\construction\models\NCSearchWidget
  • hji\construction\models\NCSearchWidgetViewModel
  • hji\construction\models\Pagination
  • hji\construction\models\Settings
  • hji\construction\models\subdivisions\SubdivisionModel
  • hji\construction\models\subdivisions\SubdivisionsGetFilters
  • hji\construction\models\subdivisions\SubdivisionsGetOptions
  • hji\construction\models\subdivisions\SubdivisionsModel
  • hji\construction\models\subdivisions\SubdivisionsSearchFilters
  • hji\construction\models\subdivisions\SubdivisionsSearchOptions
  • hji\construction\NewConstruction
  • hji\construction\ServiceContainer
  • hji\construction\views\ListingsView
  • hji\construction\views\SubdivisionsView
  • hji\geofarms\common\ImageResize
  • hji\geofarms\common\RewriteRules
  • hji\geofarms\controllers\AreaCache
  • hji\geofarms\controllers\CMB
  • hji\geofarms\controllers\CPT
  • hji\geofarms\controllers\FrontEnd
  • hji\geofarms\controllers\Settings
  • hji\geofarms\controllers\Shortcodes
  • hji\geofarms\controllers\Slipstream
  • hji\geofarms\controllers\Taxonomy
  • hji\geofarms\controllers\TinyMCE
  • hji\geofarms\controllers\UpdateNeighborhoods
  • hji\geofarms\GeoFarms
  • hji\geofarms\models\CMB
  • hji\geofarms\models\CPT
  • hji\geofarms\models\Settings
  • hji\geofarms\models\Slipstream
  • hji\geofarms\models\Taxonomy
  • hji\geofarms\models\TinyMCE
  • hji\geofarms\widgets\Display
  • hji\geofarms\widgets\Map
  • hji\homevalue\controllers\HomeValueTinyMCE
  • hji\homevalue\controllers\HomeValueWidget
  • hji\homevalue\controllers\Settings
  • hji\homevalue\controllers\Shortcodes
  • hji\homevalue\core\abstracts\Component
  • hji\homevalue\core\Controller
  • hji\homevalue\core\Model
  • hji\homevalue\HomeValue
  • hji\homevalue\models\Settings
  • hji\lifestylefinder\LifestyleFinder
  • hji\listingstoblog\controllers\ImportListings
  • hji\listingstoblog\controllers\Settings
  • hji\listingstoblog\ListingsToBlog
  • hji\membership\abstracts\Component
  • hji\membership\abstracts\Controller
  • hji\membership\abstracts\Model
  • hji\membership\controllers\APIClient
  • hji\membership\controllers\CommonScripts
  • hji\membership\controllers\Dependency
  • hji\membership\controllers\DependencyResolver
  • hji\membership\controllers\Dispatcher
  • hji\membership\controllers\Downloads
  • hji\membership\controllers\GForms
  • hji\membership\controllers\ProductManager
  • hji\membership\controllers\ProductRegistrar
  • hji\membership\controllers\RegistryEntry
  • hji\membership\controllers\RequireJs
  • hji\membership\controllers\Settings
  • hji\membership\controllers\UpdateManager
  • hji\membership\entities\Event
  • hji\membership\entities\UserActionEvent
  • hji\membership\extension\abstracts\Component
  • hji\membership\factories\ProductFactory
  • hji\membership\includes\CustomerInfoSynchronizer
  • hji\membership\interfaces\Product
  • hji\membership\Membership
  • hji\membership\models\APIClientModel
  • hji\membership\models\Customer
  • hji\membership\models\data\Address
  • hji\membership\models\data\Image
  • hji\membership\models\data\Images
  • hji\membership\models\data\Paging
  • hji\membership\models\data\Sorting
  • hji\membership\models\DependencyEntity
  • hji\membership\models\DependencyModel
  • hji\membership\models\PluginEntity
  • hji\membership\models\ProductDependencies
  • hji\membership\models\Settings
  • hji\membership\models\ThemeEntity
  • hji\membership\models\UserActionLogger
  • hji\membership\models\UserSession
  • hji\membership\models\webservice\abstracts\QueryProperties
  • hji\membership\models\webservice\abstracts\WebService
  • hji\membership\models\webservice\abstracts\WebServiceFilters
  • hji\membership\models\webservice\actions\ActionsSearchFilters
  • hji\membership\models\webservice\actions\ActionsWebService
  • hji\membership\models\webservice\WebServiceOptions
  • hji\membership\models\WpCatalog
  • hji\membership\observers\EventDispatcher
  • hji\membership\observers\EventLogger
  • hji\membership\services\CPT_Router
  • hji\membership\services\DependencyInjector
  • hji\membership\services\DependencyInjectorInterface
  • hji\membership\services\Request
  • hji\membership\services\Route
  • hji\membership\services\Router
  • hji\membership\services\ServiceContainer
  • hji\membership\services\SocialGraph
  • hji\recentsales\controllers\Shortcodes
  • hji\recentsales\RecentSales
  • hji\recentsales\tinymce\RecentSales
  • hji\recentsales\widgets\RecentSales
  • hji\ResponsiveIDX\abstracts\FilterSchema
  • hji\ResponsiveIDX\adapters\IdxAdapter
  • hji\ResponsiveIDX\adapters\LegalAdapter
  • hji\ResponsiveIDX\adapters\ListingAdapter
  • hji\ResponsiveIDX\controllers\BaseController
  • hji\ResponsiveIDX\controllers\IdxApp
  • hji\ResponsiveIDX\controllers\Pagination
  • hji\ResponsiveIDX\controllers\RecentlyViewed
  • hji\ResponsiveIDX\controllers\RegistrationForm
  • hji\ResponsiveIDX\controllers\Settings
  • hji\ResponsiveIDX\controllers\Upgrader
  • hji\ResponsiveIDX\core\abstracts\Component
  • hji\ResponsiveIDX\core\Controller
  • hji\ResponsiveIDX\core\Model
  • hji\ResponsiveIDX\entities\ComplianceRule
  • hji\ResponsiveIDX\entities\ListingEntity
  • hji\ResponsiveIDX\models\ComplianceModel
  • hji\ResponsiveIDX\models\ComplianceViewModel
  • hji\ResponsiveIDX\models\FieldLabels
  • hji\ResponsiveIDX\models\HashMap
  • hji\ResponsiveIDX\models\IdxSearchModel
  • hji\ResponsiveIDX\models\MarketMetadata
  • hji\ResponsiveIDX\models\PaginationViewModel
  • hji\ResponsiveIDX\models\QuickSearchViewModel
  • hji\ResponsiveIDX\models\SearchFilters
  • hji\ResponsiveIDX\models\SearchParams
  • hji\ResponsiveIDX\models\SearchResultsViewModel
  • hji\ResponsiveIDX\models\ShortcodesModel
  • hji\ResponsiveIDX\models\SpatialMatchModel
  • hji\ResponsiveIDX\ResponsiveIDX
  • hji\ResponsiveIDX\services\ServiceContainer
  • hji\ResponsiveIDX\tinymce\FeaturedListings
  • hji\ResponsiveIDX\utils\ArrayFormat
  • hji\ResponsiveIDX\utils\PluginDependency
  • hji\ResponsiveIDX\utils\StringFormat
  • hji\ResponsiveIDX\utils\View
  • hji\ResponsiveIDX\widgets\FeaturedListings_TinyMCE
  • hji\ResponsiveIDX\widgets\FeaturedListings_Widget
  • hji\ResponsiveIDX\widgets\QuickSearch_Widget
  • hji\schools\controllers\Shortcodes
  • hji\schools\Schools
  • hji\schools\tinymce\Schools
  • hji\schools\widgets\Schools
  • hji\users\abstracts\AdminPageModel
  • hji\users\abstracts\UserAdminTable
  • hji\users\admin\AdminController
  • hji\users\admin\BaseController
  • hji\users\admin\controllers\ActionsPageController
  • hji\users\admin\controllers\UsersPageController
  • hji\users\admin\models\ActionsPageModel
  • hji\users\admin\models\UsersPageModel
  • hji\users\controllers\GravityForms
  • hji\users\controllers\GravityFormsAdmin
  • hji\users\controllers\RegistrationPrompter
  • hji\users\controllers\Settings
  • hji\users\controllers\SocialAuth
  • hji\users\controllers\User
  • hji\users\controllers\UserPanel
  • hji\users\core\abstracts\Component
  • hji\users\core\Controller
  • hji\users\core\Model
  • hji\users\entities\GFEntry
  • hji\users\entities\User
  • hji\users\entities\UserProfile
  • hji\users\models\ActionsSearchFilters
  • hji\users\models\ActionsWebServiceOptions
  • hji\users\models\FavoritesViewModel
  • hji\users\models\FrontEndNotices
  • hji\users\models\RegistrationNotificationViewModel
  • hji\users\models\Request
  • hji\users\models\Settings
  • hji\users\models\SettingsTab
  • hji\users\models\User
  • hji\users\models\UserActionsModel
  • hji\users\models\UserFactory
  • hji\users\models\UsersSearchModel
  • hji\users\Users
  • hji\users\utils\GravityFormsHelper
  • hji\users\utils\UserActionsTable
  • hji\users\utils\UserAuth
  • hji\users\utils\UserFavoritesTable
  • hji\users\utils\UserFormEntriesTable
  • hji\users\utils\UserListTable
  • hji\users\utils\UserSearchesTable
  • hji\users\utils\UserSessionsTable
  • REL\controllers\Admin
  • REL\controllers\FSBO
  • REL\controllers\PocketListings
  • REL\controllers\rIDXImport
  • REL\Models\ListingViewModel
  • REL\Models\rIDXImport
  • REL\Models\Upgrades
  • REL\RealEstateListings
  • REL\Taxonomies\CustomTaxonomies
  • REL\Utils\Convert\ListingConverter
  • REL\widgets\PocketListingsSearchWidget
  • REL\widgets\PocketListingsWidget
  • SM_API_Client

Interfaces

  • hji\construction\interfaces\IPost
  • hji\membership\extension\interfaces\ExtensionInterface
  • hji\membership\interfaces\CRUD
  • hji\membership\interfaces\Dispatchable
  • hji\membership\interfaces\EventDispatcherInterface
  • hji\membership\interfaces\Loggable
  • hji\membership\models\webservice\interfaces\IGettable
  • hji\membership\models\webservice\interfaces\ISearchable

Functions

  • __admin_redirect
  • get_pocket_listing
  • hji\membership\controllers\__inject_plugin_table
  • hji\membership\controllers\__inject_theme_table
  • hji_user_favorite_toggle
  • hjigf_display
  • hjigf_display_map
  • hjigf_get_community_feature
  • hjigf_get_post_thumbnail
  • hjigf_has_area_map
  • ridx_get_listing
  • ridx_is_results_page
  • ridx_is_single
  • ridx_is_single_print
  • table_hjpl_cache
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 
<?php

class SM_API_Client
{

    private $url = null;
    private $licenseKey = null;


    public $api_base = "promoted-properties.homejunction.com";
    public $api_dev_base = "services-test.spatialmatch.com";
    public $last_error_code = null;
    public $last_error_mess = null;
    public $api_roles = null;
    public $last_token = null;
    public $last_token_expire = null;
    private $ch = null;
    private $debug_log;
    private $debug_mode = false;
    private $application_name = null;
    public $api_version = "v2";
    protected $cache = null;

    private $error_messages = array(
        '200'   => 'Code: 200. Success.',
        '400'   => 'Code: 400. Invalid input.',
        '403'   => 'Code: 403. Invalid license key.',
        '404'   => 'Code: 404. Agent ID doesn\'t exist.',
        '500'   => 'Code: 500. Internal server error.',
        '503'   => 'Code: 503. Service unavailable.'
    );

    // pagination vars
    public $last_count = 0;
    public $page_size = 0;
    public $total_pages = 0;
    public $current_page = 0;

    function __construct($url) {
        //force dev API base if current site is hosted on a Staging HJ server
        if( $this->_is_staging_server() )
            $this->api_base = $this->api_dev_base;

        // start session where API cookie will be stored
        @session_start();
        if ( !isset($_SESSION['hjapicookie-expire']) || $_SESSION['hjapicookie-expire'] < time() )
        {
            unset($_SESSION['hjapicookie']);
        }

        // set the api key and secret based on passed parameters
        $parsed_url = parse_url($url);
        $this->url = $parsed_url['host'];

        //exception handler
        set_exception_handler( array(&$this, 'exception_handler') );

        //debug via $_GET
        register_shutdown_function( array(&$this, 'debug_data') );
    }


    /**
     * Check if current server is a staging HJ server
     * @return boolean
     */
    private function _is_staging_server()
    {
        if (stristr($_SERVER['HTTP_HOST'], 'staging.spatialmatch.com')
            || stristr($_SERVER['HTTP_HOST'], 'hjstaging.com'))
        {
            return true;
        }

        return false;
    }


    function SetLicenseKey($licenseKey) {
        $this->licenseKey = $licenseKey;
    }


    function InitCurl() {
        // initialize cURL for use later
        $this->ch = curl_init();

        curl_setopt($this->ch, CURLOPT_HEADER, true);
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->ch, CURLOPT_COOKIESESSION, true);
    }


    function __destruct() {
        // clean cURL up
        if($this->ch)
            curl_close($this->ch);
    }


    function SetCache($cache) {
        if (is_object($cache)) {
            $this->cache = $cache;
        }
//        else {
//            throw new Exception("SetCache() called but value isn't a valid cache object");
//        }
    }


    ////////////////////////////////////////////////////////////////////
    //  AUTH FUNCTIONS
    ////////////////////////////////////////////////////////////////////


    function Authenticate($force = false) {
        if( !$this->licenseKey )
            return;

        if( $force  || @!$_SESSION['hjapicookie']
                    || (isset($_GET['hjauth']) && $_GET['hjauth'] == 'force' ) )
        {
            $this->InitCurl();
            unset($_SESSION['hjapicookie']);
            $data['key'] = $this->licenseKey;
            //$this->url = 'maxchirkov.com';
            $url = '&url=' . base64_encode($this->url);
            $data = http_build_query($data) . $url;

            $result = $this->MakeAPIRequest("POST", "/{$this->api_version}/init", array(), $data, $auth = true, $force);

            if ($result === false) {
                $code = $this->last_error_code;
                $message = $this->last_error_mess;
                //throw new Exception($message, $code);
            }

            return $result;
        }

    }


    function SetApplicationName($name) {
        $this->application_name = str_replace(array("\r", "\r\n", "\n"), '', trim($name));
    }

    function SetDebugMode($mode = false) {
        $this->debug_mode = $mode;
        // enable logging if we're in debug mode
        if ($this->debug_mode == true) {
            $this->debug_log = fopen("debug.log", 'a');
            curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
            curl_setopt($this->ch, CURLOPT_STDERR, $this->debug_log);
        }
    }

    function SetDeveloperMode($enable = false) {
        if ($enable) {
            $this->api_base = $this->api_dev_base;
            $this->url = 'staging.spatialmatch.com';
            return true;
        }
        else {
            return false;
        }
    }

    function GetErrors() {
        if ($this->last_error_code && $this->last_error_mess) {
            return $this->last_error_code . ' - ' . $this->last_error_mess;
        }
        else {
            return false;
        }
    }


    ////////////////////////////////////////////////////////////////////
    //  SEARCH/LISTING FUNCTIONS
    ////////////////////////////////////////////////////////////////////


    /**
     * Returns all listings for the currently selected market
     * 1st step for a full IDX app.
     * @param [type] $args [description]
     */
    function GetListings($args) {
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/listings", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }
        return $result['results'];
    }


    /**
     * Returns Listings only for Licensed Offices and Agents
     * @param [type] $args [description]
     */
    function GetPromotedListings($args) {
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/promoted", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }
        return $result['results'];
    }


    function GetListing($args) {
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/listing", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }
        return $result;
    }


    function GetAgents($args) {
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/agents", $args, array(), $auth = false);
        if ($result === false) {
            return false;
        }

        return $result;
    }


    function UpdateAgents($args, $data) {
        $data = "data={$data}";
        $result = $this->MakeAPIRequest("POST", "/{$this->api_version}/agents", $args, $data, $auth = false);

        if ($result === false) {
            return false;
        }

        return $result;
    }

    function FindAgents($args) {
        $args['type'] = 'agents';
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/search", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }

        return $result;
    }


    function GetOffices($args) {
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/offices", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }

        return $result;
    }


    function UpdateOffices($args, $data) {
        $data = "data={$data}";
        $result = $this->MakeAPIRequest("POST", "/{$this->api_version}/offices", $args, $data, $auth = false);

        if ($result === false) {
            return false;
        }

        return $result;
    }


    function FindOffices($args) {
        $args['type'] = 'offices';
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/search", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }

        return $result;
    }


    function GetMetaData($args) {
        $result = $this->MakeAPIRequest("GET", "/{$this->api_version}/metadata", $args, array(), $auth = false);

        if ($result === false) {
            return false;
        }

        return $result;
    }


    /*
     * Makes the API call to the flexmls API.
     *
     * @param string $method HTTP method to use when making the call.  GET, POST, etc.
     * @param string $uri HTTP request URI to hit with the request
     * @param array $args array of key/value pairs of parameters.  added to request depending on HTTP method
     * @param array $caching array of caching settings. 'enabled' is true/false. 'minutes' defines how long if enabled
     * @return mixed Returns array of parsed JSON results if successful.  Returns false if API call fails
     */

    function MakeAPIRequest($method, $uri, $args = array(), $data = array(), $is_auth_request = false, $a_retry = false) {
        $success = false;

        $this->InitCurl();

        // check if cookie from session can be used
        if( !$is_auth_request && isset($_SESSION['hjapicookie']) )
            curl_setopt($this->ch, CURLOPT_COOKIE, $_SESSION['hjapicookie']);


        if (!is_array($args)) {
            $args = array();
        }

        $http_parameters = $args;

        $post_body = "";

        if ($method == "POST" && count($data) > 0) {
            // the request is to post some JSON data back to the API (like adding a contact)
            $post_body = $data;
        }

        ksort($http_parameters);

        $http_proto = "http://";

        // start putting the URL parts together
        $full_url = $http_proto . $this->api_base . $uri;

        // take the parameter key/values and put them into a URL-like structure.  key=value&key2=value2& etc.
        $query_string = "";
        foreach ($http_parameters as $k => $v) {
            if (!empty($query_string)) {
                $query_string .= "&";
            }
            $query_string .= $k . '=' . rawurlencode($v);
        }

        if (!empty($query_string)) {
            $full_url .= '?' . $query_string;
        }

        if ($this->debug_mode) {
            echo $full_url . "\n\n";
        }
// echo '<textarea>';
// echo $full_url . "\n\n";
// echo '</textarea>';
        $request_headers = "";

        curl_setopt($this->ch, CURLOPT_URL, $full_url);



        if ($method == "POST") {
            // put the built parameter key/values as the body of the POST request
            $request_headers .= "Content-Type: application/json\r\n";
            curl_setopt($this->ch, CURLOPT_POST, true);
            curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_body);
        }
        elseif ($method == "DELETE" ) {
            curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_body);
            curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
            //curl_setopt($this->ch, CURLOPT_HEADER, 0);
        }
        else {
            curl_setopt($this->ch, CURLOPT_POST, 0);
            curl_setopt($this->ch, CURLOPT_HTTPGET, true);
        }

        $request_headers .= "User-Agent: HJ API PHP Client/0.1\r\n";
        if (!empty($this->application_name)) {
            $request_headers .= "X-hjApi-User-Agent: {$this->application_name}\r\n";
        }

        #curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(trim($request_headers)));

        //$response_body = curl_exec($this->ch);
        $response = curl_exec($this->ch);

        $info = curl_getinfo($this->ch);

        if( '200' == $info['http_code'] )
        {
            $success = true;
            $this->last_error_code = false;
            $this->last_error_mess = false;
        }
        else
        {
            $this->last_error_code = @$info['http_code'];
            $this->last_error_mess = @$this->error_messages[$info['http_code']];
        }

        @list($header, $response_body) = explode("\r\n\r\n", $response, 2);

        //for debugging
        $this->debug_data[] = array(
            'webservice'=> $uri,
            'info'      => $info,
            'error'     => curl_error($this->ch),
            'post_body' => $post_body,
            'response_header' => $header,
            'response'  => $response_body,
            'session_used'   => (isset($_SESSION['hjapicookie'])) ? $_SESSION['hjapicookie'] : 'NONE',
        );

        if ($this->debug_mode == true) {
            fwrite($this->debug_log, $response_body . "\n");
        }

        if ($this->debug_mode) {
            echo $response_body . "\n\n";
        }

        // start handling the response
        $json = json_decode( utf8_encode($response_body), true );

        // if session with cookie is not set,
        // start processing header to set a cookie
        if( $is_auth_request )
        {
            $items = explode("\r\n", $header);

            foreach ( $items as $item )
            {
                @list($key, $value)  = explode(":", $item);
                @list($v, $w) = explode(";", $value);
                $value = trim($v);

                if ($key == "Set-Cookie")
                {
                    $cookie = $value;
                }
            }

            if ( isset($cookie) )
            {
                $_SESSION['hjapicookie'] = $cookie;
                $_SESSION['hjapicookie-expire'] = time() + 3600;
                $this->debug_data[]['session_set'] = $_SESSION['hjapicookie'];
                $this->debug_data[]['session_expires'] = $_SESSION['hjapicookie-expire'];
            }
            else
            {
                // error
            }
        }
        // end processing header to set a cookie


        //Agent/Office IDs Add should return 200
        //no other response is provided
        if( stristr($uri, '/agents') && ('POST' == $method || 'DELETE' == $method) )
        {
            if( $success )
                return true;
        }

        if( isset($args['page']) ){
            $this->current_page = $args['page'];
        }

        if( isset($args['rpp']) ){
            $this->page_size = $args['rpp'];
        }

        if( $this->current_page && $this->page_size && isset($json['totalRecords']) ){
            $this->last_count = $json['totalRecords'];
            $this->total_pages = ceil( (int)$json['totalRecords']/$this->page_size );
        }

        if ($success == true) {
            return $json;
        }
        elseif ($a_retry == false && $is_auth_request == false && ( !$this->last_error_code || $this->last_error_code == '403' || $this->last_error_code == '404' || $this->last_error_code == '500')  ) {
            $this->Authenticate(true);
            $return = $this->MakeAPIRequest($method, $uri, $args, $data, $is_auth_request, $a_retry = true);
            return $return;
        }
        else {
            return false;
        }

    }

    /*
     * Take a value and clean it so it can be used as a parameter value in what's sent to the API.
     *
     * @param string $var Regular string of text to be cleaned
     * @return string Cleaned string
     */

    function clean_comma_list($var) {

        $return = "";

        if (strpos($var, ',') !== false) {
            // $var contains a comma so break it apart into a list...
            $list = explode(",", $var);
            // trim the extra spaces and weird characters from the beginning and end of each item in the list...
            $list = array_map('trim', $list);
            // and put it back together as a comma-separated string to be returned
            $return = implode(",", $list);
        }
        else {
            // trim the extra spaces and weird characters from the beginning and end of the string to be returned
            $return = trim($var);
        }

        return $return;
    }

    function exception_handler($exception)
    {
        echo "Uncaught exception: " , $exception->getMessage(), "\n";
    }

    /**
     * Outputs API request info for debugging purposes
     */
    function debug_data(){
        if( isset($this->debug_data) && isset($_GET['hjdebug']) )
        {

            print '<textarea style="width: 600px; height: 600px">';
            print_r( $this->debug_data );
            print '</textarea>';
        }
    }

}
HJI WP Membership Code Reference API documentation generated by ApiGen