-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathexamples.php
182 lines (148 loc) · 5.5 KB
/
examples.php
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
<?php
header('Content-Type: text/html; charset=UTF-8');
// include the SparkAPI core which autoloads other classes as necessary
require_once("lib/Core.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.
*/
// To utilize OpenID Connect Authentication see the wiki page here: https://github.com/sparkapi/sparkapi4p2/wiki/OpenID-Connect-Authentication
$api = new SparkAPI_Bearer("your_access_token_here");
// identify your application (optional)
$api->SetApplicationName("PHP-API-Code-Examples/1.0");
/*
* enable built-in caching system
* New in version 2.0
*
* The newest version of the PHP API client (version 2.0) contains a system for enabling a
* built-in cache. The following options currently exist:
*
* * Memcache (Uses http://pecl.php.net/package/memcache)
* * Memcached (Uses http://pecl.php.net/package/memcached)
* * WordPress (for use within plugins or themes)
* * MySQLi for storing the cache in a MySQL database
*
* To enable a particular caching system, you must create an instance of the desired object and pass it to
* the API core.
*
*
* To enable Memcache or Memcached cache support, the host and port (both optional) can be given:
*
* $api->SetCache( new SparkAPI_MemcacheCache() ); // defaults to localhost and port 11211
* or:
* $api->SetCache( new SparkAPI_MemcachedCache('remotehost', 12345) ); // overrides both defaults
*
* depending on the Memcached-compliant driver you choose.
*
*
* To enable WordPress caching, no arguments are required: this method uses the set_transient() and get_transient()
* functions created by WordPress which can be extended by other WP plugins for additional (or modified) functionality.
*
* $api->SetCache( new SparkAPI_WordPressCache() );
*
*
* To enable database caching via the MySQLi extension, you can either pass connection details to the class:
*
* $api->SetCache( new SparkAPI_MySQLiCache($hostname, $database, $username, $password, $table_name));
*
* or you can re-use an existing MySQLi connection by passing the object:
*
* $api->SetCache( new SparkAPI_MySQLiCache($my_mysqli_object) );
*
* By default, a $table_name of "api_cache" is assumed if none is given. The structure for that table is:
*
* CREATE TABLE api_cache (
* cache_key VARCHAR(125),
* cache_value LONGBLOB,
* expiration INT(10),
* PRIMARY KEY(cache_key)
* )
*
*/
/*
* request some basic account and system information
*/
$result = $api->GetSystemInfo();
// http://sparkplatform.com/docs/api_services/system_info
print_r($result);
$result = $api->GetPropertyTypes();
// http://sparkplatform.com/docs/api_services/property_types
print_r($result);
$result = $api->GetStandardFields();
// http://sparkplatform.com/docs/api_services/standard_fields
print_r($result);
$result = $api->GetMyAccount();
// 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->GetMyListings();
// http://sparkplatform.com/docs/api_services/listings
print_r($result);
$result = $api->GetOfficeListings();
// http://sparkplatform.com/docs/api_services/listings
print_r($result);
$result = $api->GetCompanyListings();
// http://sparkplatform.com/docs/api_services/listings
print_r($result);
/*
* 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'
)
);
// http://sparkplatform.com/docs/api_services/listings
print_r($result);
/*
* with a particular listing Id known, several additional API calls are available
*/
$id = "20100912153422758914000000"; // this comes from the Id value in a listing response
$result = $api->GetListingPhotos($id);
// http://sparkplatform.com/docs/api_services/listings/photos
$result = $api->GetListingDocuments($id);
// http://sparkplatform.com/docs/api_services/listings/listing_documents
$result = $api->GetListingOpenHouses($id);
// http://sparkplatform.com/docs/api_services/listings/open_houses
$result = $api->GetListingVideos($id);
// http://sparkplatform.com/docs/api_services/listings/videos
$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
*/
$photo_id = "20080917142739989238000000";
$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"
);
// $result = $api->AddContact($new_contact); // creates a new contact
$result = $api->GetContact("20090816141725963238000000"); // get a contact by their Id