Giter VIP home page Giter VIP logo

wp-idxbroker-api's Introduction

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

$idx_api = new IdxBrokerAPI( 'example_api_key' );

$res1 = $idx_api->get_clients_featured();

$res2 = $idx_api->get_clients_systemlinks( 'url' );

$res3 = $idx_api->get_mls_approvedmls();

POST Requests

$res1 = $idx_api->post_clients_dynamicwrapperurl( 'https://example.com/luxury-real-estate', '12345' );

$data = array( 'note' => 'Wheres my IDX?' );
$res2 = $idx_api->post_leads_note( '3', '1', $data );

PUT Requests

$data = array( 
  'propertyName' => 'Test Property',
  'property' => array('idxID' => 'a001', 'listingID' => '345678' )
);
$res1 = $idx_api->put_leads_property( 812, $data );

DELETE Requests

$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

$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

$domain = $idx_api->get_idx_domain();

/*
Results
Array
(
    [scheme] => https
    [url] => search.example.com
    [full] => https://search.example.com
)
*/

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.

class OptimizedIdxBrokerAPI extends IdxBrokerAPI {

  /**
   * By overriding the request method we can intercept the API call and choose to 
   * either make a fresh API call or retrieve a cached result from the database.
   */
  public function request( $force_refresh = false ) {
    // Only cache GET requests.
    if ( 'GET' !== $this->args['method'] ) {
      return parent::request();
    }

    // We md5 the route to create a unique key for that call and to also reduce the risk of
    // creating a key that is over 64 characters long, aka the max length for option names.
    $transient_key = 'idxbroker_cache_' . md5( $this->route );

    // Check if cached results for API call exist.
    $request = get_transient( $transient_key );

    // If nothing is found, make the request.
    if ( true === $force_refresh || false === $request ) {
      // Parent method handles the request to IDX Broker.
      $request = parent::request();

      if ( false !== $request ) {
        set_transient( $transient_key, $request, 1 * HOUR_IN_SECONDS );
      }
    }
		
    return $request;
  }
	
}

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:
$optimized_idx_api = new OptimizedIdxBrokerAPI( 'yourapikey' );

$results = $optimized_idx_api->get_clients_featured(); // Fresh call to the API.

$results = $optimized_idx_api->get_clients_featured(); // Cached results.

wp-idxbroker-api's People

Contributors

bhubbard avatar bradleymoore111 avatar sfgarza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-idxbroker-api's Issues

API Call for Search

Hey, first off, sorry if this is not the right place - I tried IDXBRoker's help and couldn't get very far with API related questions. They originally told me that a data api didn't exist so it was awesome to find this!

For search I created my own personal handler that created the POST request exactly how it's expected on the IDXBroker end... it's excruciatingly complicated -- the reason I don't use add_query_arg is because IDXBroker's API expects and accepts multiple key/value pairs with identical keys so I had to write a handler for that. This works fine, but it's a pain to implement.

Anyway - I was hoping I could replace this with an eas(y|ier) to use API call with this wrapper -- any ideas? The API docs aren't the greatest :\

        $mail_url = 'http://listings.foobar.com/idx/results/listings';
        $post = array_map( 'sanitize_text_field', $_POST);
	$output = array();
	$map    = array(
		'low-price'                     => array(
			'key'         => 'lp',
			'passthrough' => true
		),
		'idxID'                         => array(
			'key'         => 'idxID',
			'passthrough' => true
		),
		'square-feet'                   => array(
			'key'         => 'sqft',
			'passthrough' => true
		),
		'max-days-listed'               => array(
			'key'         => 'add',
			'passthrough' => true
		),
		'high-price'                    => array(
			'key'         => 'hp',
			'passthrough' => true
		),
		'property-type'                 =>
			array(
				'key'         => 'pt',
				'passthrough' => true
			),
		'bathrooms'                     => array(
			'key'         => 'tb',
			'passthrough' => true

		),
		'bedrooms'                      => array(
			'key'         => 'bd',
			'passthrough' => true

		),
		'area-name'                     => array(
			'key'      => 'a_areaName%5B%5D',
			'multiple' => true,

		),
		'section'                       => array(
			'key'      => 'a_section%5B%5D',
			'multiple' => true,

		),
		'has-images'                    => array(
			'key'      => 'amin_photocount',
			'checkbox' => true,
			'value'    => 1
		),
		'has-virtual-tour'              => array(
			'key'      => 'wvt',
			'checkbox' => true,
			'value'    => 'y'
		),
		'has-open-house'                => array(
			'key'      => 'woh',
			'checkbox' => true,
			'value'    => 'y'
		),
		'featured-listing'              => array(
			'key'      => 'fl',
			'checkbox' => true,
			'value'    => 'y'
		),
		'min-year-built'                => array(
			'key'         => 'amin_yearBuilt',
			'passthrough' => true,
			'filter'      => function ( $value ) {
				return (int) $value;
			}
		),
		'max-year-built'                => array(
			'key'         => 'amax_yearBuilt',
			'passthrough' => true,
			'filter'      => function ( $value ) {
				return (int) $value;
			}
		),
		'style'                         => array(
			'key'      => 'a_style',
			'multiple' => true

		),
		'residential-subtype'           => array(
			'key'      => 'a_propSubType%5B%5D',
			'multiple' => true

		),
		'multi-family-subtype'          => array(
			'key'      => 'a_propSubType%5B%5D',
			'multiple' => true

		),
		'residential-rental-subtype'    => array(
			'key'      => 'a_propSubType%5B%5D',
			'multiple' => true

		),
		'commercial-subtype'            => array(
			'key'      => 'a_propSubType%5B%5D',
			'multiple' => true

		),
		'land-subtype,business-subtype' => array(
			'key'      => 'a_propSubType%5B%5D',
			'multiple' => true

		),
		'business-subtype'              => array(
			'key'      => 'a_propSubType%5B%5D',
			'multiple' => true

		),
		'order'                         => array(
			'key'         => 'srt',
			'passthrough' => true
		),
		'city'                          => array(
			'key'         => 'city%5B%5D',
			'passthrough' => true
		),
		'county'                        => array(
			'key'         => 'county%5B%5D',
			'passthrough' => true
		),
		'zipcode'                       => array(
			'key'         => 'zipcode%5B%5D',
			'passthrough' => true
		),
		'ccz'                           => array(
			'key'         => 'ccz',
			'passthrough' => true
		),



	);

	$maps = array_keys( $map );

	foreach ( $maps as $map_key ) {

		if ( isset( $map[ $map_key ]['filter'] ) && $map[ $map_key ]['filter'] ) {
			$post[ $map_key ] = call_user_func( $map[ $map_key ]['filter'], $post[ $map_key ] );

		}

		if ( isset( $map[ $map_key ]['checkbox'] ) && $map[ $map_key ]['checkbox'] && isset( $post[ $map_key ] ) && $post[ $map_key ] ) {

			$output[] = array(
				$map[ $map_key ]['key'] => $map[ $map_key ]['value']
			);

		} elseif ( isset( $map[ $map_key ]['passthrough'] ) && $map[ $map_key ]['passthrough'] && isset( $post[ $map_key ] ) && $post[ $map_key ] ) {

			$output[] = array(
				$map[ $map_key ]['key'] => $post[ $map_key ]
			);
		} elseif ( isset( $map[ $map_key ]['multiple'] ) && $map[ $map_key ]['multiple'] && isset( $post[ $map_key ] ) && is_array( $post[ $map_key ] ) && $post[ $map_key ] ) {

			$output[] = array(
				$map[ $map_key ]['key'] => $post[ $map_key ]
			);


		} elseif ( isset( $post[ $map_key ] ) && isset( $map[ $map_key ]['values'][ $post[ $map_key ] ] ) && $map[ $map_key ]['values'][ $post[ $map_key ] ] ) {
			$output[] = array(
				$map[ $map_key ]['key'] => $map[ $map_key ]['values'][ $post[ $map_key ] ]
			);
		}
	}

$url_params = '';
foreach ( $output as $item ) {

	foreach ( $item as $key => $val ) {
		if ( $url_params ) {
			$url_params .= '&';
		}
		if ( is_array( $val ) ) {
			$count = 0;
			foreach ( $val as $output_val ) {
				if ( $output_val ) {
					if ( $count > 0 ) {
						$url_params .= '&';
					}
					$url_params .= $key . '=' . urlencode( $output_val );
					$count++;
				}
			}
		} else {
			if ( $val ) {
				$url_params .= $key . '=' . urlencode( $val );
			}
		}

	}

}

$url = str_replace( '&&', '&', rtrim( $main_url . '?' . $url_params, '&' ) );
wp_redirect( $url, 302 );

adding saved links

Using the lib I am only returning false when trying to add a saved link. 400 is the status code I get from the API call.

Was trying to pass
'linkName' => 'Good_side_of_tracks', 'pageTitle' => 'Good_side_of_tracks', 'linkTitle' => 'Good_side_of_tracks', 'queryString' => array('idxID' => 'a001', 'hp' => '200000')
in my array.

Is PUT and POST supported for savedlinks or leads?

issue with the API?

i appreciate the effort with https://github.com/wp-api-libraries

I'm trying to use https://github.com/wp-api-libraries/wp-idxbroker-api and I've noticed that your GET API example is:

$idx_api = new IdxBrokerAPI( 'example_api_key');
$results = $idx_api->build_request( 'properties/featured' )->request();

I tried this using my API key and it returns false.

Digging deeper it appears that API request translates to...

a request to โ€Œ

https://api.idxbroker.com/properties/featured
with headers:
Content-Type => application/x-www-form-urlencoded,
accesskey => my key,
ancillarykey => null,
outputtype => json,
apiversion => 1.4.0

a method of GET and a body of ""

According to the IDX API https://middleware.idxbroker.com/docs/api/overview.php the URL structure is:

https://api.idxbroker.com/{component}/{method}/{primary request ID}/{secondary request ID}?{query string}

however also according to that link the Current components include: partners, clients, mls, and leads -- properties isn't there.

am I doing something wrong?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.