Skip to content

Update readme for packagist #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,27 +12,38 @@ For additional information on the PHP client, [visit the wiki](https://github.co

For full information on the API, see http://sparkplatform.com/docs

Installation
-------------
`composer require sparkapi/sparkapi:dev-master`

Usage Examples
------------------------
// include the Spark core which autoloads other classes as necessary
require_once("lib/Core.php");
require_once("vendor/autoload.php");

// connect using Access Token Authentication (additional authentication methods available in the wiki)
$api = new SparkAPI_Bearer("your_access_token_here");

// identify your application (optional)
$api->SetApplicationName("MyPHPApplication/1.0");


// get your listings
$result = $api->GetMyListings();

/*
Alternatively, if you cannot find the appropriate helper method,
try our "get", "post", "put", or "delete" methods from Core.php.
*/
$result = $api->get("my/listings");
$results = $api->GetMyListings();

foreach ($results as $result) {
// standard fields expected in the resource payload differ by MLS and role
echo $result['StandardFields']['ListingKey'];
// -or-
print_r($result);
}

/*
* Alternatively, if the appropriate helper method doesn't exist,
* try our "get", "post", "put", or "delete" methods from Core.php
* directly to the endpoint you want to use.
*/
$result = $api->get("my/account");

print_r($result);

// see the included examples.php for more complete usage

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
"homepage": "http://github.com/sparkapi/sparkapi4p2",
"license": "GPL-3.0",
"require": {
"php": ">=5.2.0",
"php": ">=5.6.0",
"jumbojett/openid-connect-php": "^0.3.0"
},
"autoload": {
62 changes: 26 additions & 36 deletions examples.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?php

header('Content-Type: text/html; charset=UTF-8');

// include the SparkAPI core which autoloads other classes as necessary
require_once("lib/Core.php");

require_once ('vendor/autoload.php');

/*
* authenticate with the API
* Changed in version 2.0
*
* There are two authentication methods that we fully support - OpenID Connect and Access Token Authentication. Additional,
* albeit deprecated, authentication examples are available on the wiki.
* There are two authentication methods that we fully support - OpenID Connect and Access Token Authentication. Additional,
* albeit deprecated, authentication examples are available on the wiki.
*/

// To utilize OpenID Connect Authentication see the wiki page here: https://github.com/sparkapi/sparkapi4p2/wiki/OpenID-Connect-Authentication
$api = new SparkAPI_SparkAPI_Bearer("your_access_token_here");
$api = new SparkAPI_Bearer("YOUR_BEARER_TOKEN");

// identify your application (optional)
$api->SetApplicationName("PHP-API-Code-Examples/1.0");
@@ -71,8 +67,6 @@
*
*/



/*
* request some basic account and system information
*/
@@ -92,17 +86,16 @@
// http://sparkplatform.com/docs/api_services/my_account
print_r($result);


/*
* different requests for listings based on context
*/

// Get all active listings, using the "get" method.
$result = $api->get("listings", array(
"parameters" => array(
"_filter" => "MlsStatus Eq 'A'"
)
));
$result = $api->get("listings", [
"parameters" => [
"_filter" => "MlsStatus Eq 'A'"
],
]);

$result = $api->GetMyListings();
// http://sparkplatform.com/docs/api_services/listings
@@ -120,13 +113,13 @@
* request for listings with some parameters. the above listing requests this argument and most of the options within
*/
$result = $api->GetListings(
array(
'_pagination' => 1,
'_limit' => 3,
'_page' => 2,
'_filter' => "PropertyType Eq 'A'",
'_expand' => 'PrimaryPhoto'
)
[
'_pagination' => 1,
'_limit' => 3,
'_page' => 2,
'_filter' => "PropertyType Eq 'A'",
'_expand' => 'PrimaryPhoto'
]
);
// http://sparkplatform.com/docs/api_services/listings
print_r($result);
@@ -148,7 +141,6 @@
$result = $api->GetListingVirtualTours($id);
// http://sparkplatform.com/docs/api_services/listings/virtual_tours


/*
* with a particular object Id known, you can request additional information about that one item
*/
@@ -158,25 +150,23 @@
$result = $api->GetListingPhoto($id, $photo_id);
// http://sparkplatform.com/docs/api_services/listings/photos


/*
* contact management
* http://sparkplatform.com/docs/api_services/contacts
*/

$result = $api->GetContacts();

$new_contact = array(
"DisplayName" => "Example Contact",
"PrimaryEmail" => "[email protected]",
"PrimaryPhoneNumber" => "888-123-4567",
"HomeStreetAddress" => "123 S. Main St",
"HomeLocality" => "Fargo",
"HomeRegion" => "ND",
"HomePostalCode" => "58104",
"Tag" => "Example Group"
);
$new_contact = [
"DisplayName" => "Example Contact",
"PrimaryEmail" => "[email protected]",
"PrimaryPhoneNumber" => "888-123-4567",
"HomeStreetAddress" => "123 S. Main St",
"HomeLocality" => "Fargo",
"HomeRegion" => "ND",
"HomePostalCode" => "58104",
"Tag" => "Example Group"
];

// $result = $api->AddContact($new_contact); // creates a new contact

$result = $api->GetContact("20090816141725963238000000"); // get a contact by their Id
259 changes: 95 additions & 164 deletions lib/Core.php

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions tests/CoreTest.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,6 @@ class SparkApi_CoreTest extends \PHPUnit\Framework\TestCase {

public function setUp() {
$this->core = new SparkAPI_Core();
}

public function tearDown() {
/* ... */
}

public function testInstantiation() {
@@ -18,8 +14,7 @@ public function testInstantiation() {
public function testMakeSendableBodyWrapsWithD() {
$body = array("ListingIds" => array("20100000000000000000000000",
"20100000000000000000000000"));
$this->assertEquals( json_encode(array("D"=>$body)),
$this->core->make_sendable_body($body));
$this->assertEquals(json_encode(array("D"=>$body)), $this->core->make_sendable_body($body));
}

public function testParseCacheTime() {
@@ -38,7 +33,7 @@ public function testParseCacheTime() {

public function testSetErrors() {
$this->core->SetErrors(null, "This is a random error");
$this->assertNull(null, $this->core->last_error_code);
$this->assertNull($this->core->last_error_code);
$this->assertEquals("This is a random error", $this->core->last_error_mess);

$this->core->SetErrors(1020, "Some message");