项目作者: wp-api-libraries

项目描述 :
A WordPress php library for interacting with the IDX Broker API.
高级语言: PHP
项目地址: git://github.com/wp-api-libraries/wp-idxbroker-api.git
创建时间: 2016-09-07T16:25:38Z
项目社区:https://github.com/wp-api-libraries/wp-idxbroker-api

开源协议:GNU General Public License v3.0

下载


WP IDX Broker API

A WordPress php library for interacting with the IDX Broker API.

Code Climate
Test Coverage
Issue Count
Build Status

Example Usage

The IDX Broker API library contains a method for each endpoint of the API. Visit the PHPDocs for the full documentation.

GET Requests

  1. $idx_api = new IdxBrokerAPI( 'example_api_key' );
  2. $res1 = $idx_api->get_clients_featured();
  3. $res2 = $idx_api->get_clients_systemlinks( 'url' );
  4. $res3 = $idx_api->get_mls_approvedmls();

POST Requests

  1. $res1 = $idx_api->post_clients_dynamicwrapperurl( 'https://example.com/luxury-real-estate', '12345' );
  2. $data = array( 'note' => 'Wheres my IDX?' );
  3. $res2 = $idx_api->post_leads_note( '3', '1', $data );

PUT Requests

  1. $data = array(
  2. 'propertyName' => 'Test Property',
  3. 'property' => array('idxID' => 'a001', 'listingID' => '345678' )
  4. );
  5. $res1 = $idx_api->put_leads_property( 812, $data );

DELETE Requests

  1. $res1 = $idx_api->delete_clients_supplemental( 345678 );

Helper Methods

The library also provides a few methods that assist in extracting information that is not readily accessible.

Check API Key Usage

After you make a call to the API you can check your hourly API key usage using the check_usage method

  1. $usage = $idx_api->check_usage();

Get Wrapper Domain

The API doesnt have an easy way of getting the domain used on the client wrapper pages. The domain can be some version of either <youraccount>.idxbroker.com or <customsubdomain>.<yourdomain>.com

  1. $domain = $idx_api->get_idx_domain();
  2. /*
  3. Results
  4. Array
  5. (
  6. [scheme] => https
  7. [url] => search.example.com
  8. [full] => https://search.example.com
  9. )
  10. */

Extending Functionality

The IDXBrokerAPI Class is extensible, which gives developers the ability to override the functionality of the class to their needs.

For Example. Exceeding the hourly limit is a common issue developers may face when using the API. By overriding the request() method, we can cache the calls made to the API.

  1. class OptimizedIdxBrokerAPI extends IdxBrokerAPI {
  2. /**
  3. * By overriding the request method we can intercept the API call and choose to
  4. * either make a fresh API call or retrieve a cached result from the database.
  5. */
  6. public function request( $force_refresh = false ) {
  7. // Only cache GET requests.
  8. if ( 'GET' !== $this->args['method'] ) {
  9. return parent::request();
  10. }
  11. // We md5 the route to create a unique key for that call and to also reduce the risk of
  12. // creating a key that is over 64 characters long, aka the max length for option names.
  13. $transient_key = 'idxbroker_cache_' . md5( $this->route );
  14. // Check if cached results for API call exist.
  15. $request = get_transient( $transient_key );
  16. // If nothing is found, make the request.
  17. if ( true === $force_refresh || false === $request ) {
  18. // Parent method handles the request to IDX Broker.
  19. $request = parent::request();
  20. if ( false !== $request ) {
  21. set_transient( $transient_key, $request, 1 * HOUR_IN_SECONDS );
  22. }
  23. }
  24. return $request;
  25. }
  26. }

Now when you instantiate your new class and make calls to methods such as get_clients_featured() or get_partners_clients(), you will get cached versions of the results if they are available.

Usage:
  1. $optimized_idx_api = new OptimizedIdxBrokerAPI( 'yourapikey' );
  2. $results = $optimized_idx_api->get_clients_featured(); // Fresh call to the API.
  3. $results = $optimized_idx_api->get_clients_featured(); // Cached results.