The Haystack SDK consists of three main files
Required Includes
Creating a Haystack API Object
Creating New Haystack.
Getting a Haystack Id
Adding Profiles to the Haystack.
Adding Haystack Categories
Modifying Tag Values
Listing Profiles in a Haystack
Deleting Profiles
Deleting Haystacks
require_once('HaystackWebServiceClient.php');
// Some defines to help us with authentication
define('MY_TOKEN', '2af334aa72e106f95a778f515c162aa3');
define('MY_EMAIL', 'my.email@myorg.com'); // end
MY_TOKEN and MY_EMAIL with the ones which are right for your authentication.
// Instantiating an API object.
$apiClient = &new HaystackWebServiceClient(MY_TOKEN, MY_EMAIL); // end
$haystackName = 'myFavouriteHaystack';
$apiClient->HaystackCreate($haystackName, $hid); // end
// Retrieve the ID of already existing haystack.
$apiClient->HaystackId($haystackName, $hid2);
// Validate that it is the same as the ID returned by the HaystackCreate() command.
assert($hid == $hid2); // end
// With this line of code we create a brand new profile in the system and assign
// our haystack as its main haystack.
$apiClient->ProfileCreate($hid, 'profile1@myorg.com', 'profile1_pass');
// The next line creates another brand new profile but adds some additional info
// for the profile.
$info = array('fname'=>'John', 'lname'=>'Smith');
$apiClient->ProfileCreate($hid, 'john.smith@myorg.com', 'john_pass', $info);
// And this last line does not create a new profile but add existing profile
// to our haystack since 'ccarfi@cerado.com' already exists in the system.
$apiClient->ProfileCreate($hid, 'stanimir.peev@sciant.com', ''); // end
// First demonstrate that a newly created haystack already have categories in it.
$apiClient->HaystackCategories($hid, $result);
assert(count($result) > 0);
// You can print the categories like this
print_r($result);
// Or you walk over the array of categories
foreach ($result as $category)
{
echo $category;
} // end
$subCmd parameter with 'add' instead of the default 'list' value.
// Adding a new category is easy. With the code below you add a single category.
$apiClient->HaystackCategories($hid, $result, 'add', 'myCategory1');
// And with the code below you add a few categories at once.
$apiClient->HaystackCategories($hid, $result, 'add',
'myCategory2,myCategory3,myCategory4'); // end
// Add the tag 'Sciant' to all profiles in our haystack.
$apiClient->HaystackTags($hid, $result, 'add', 'Organization', 'Sciant');
// Now add the 'Wizcom' tag under the 'Organization' category for two
// specific profiles.
$apiClient->HaystackTags($hid, $result, 'add', 'Organization', 'Wizcom',
'stanimir.peev@sciant.com, john.smith@myorg.com'); // end
// First list all profiles which have the 'Sciant' tag in the 'Otganization'
// category.
$apiClient->HaystackListProfiles($hid, $result, 'Organization', 'Sciant');
// Since we added this tag to all profiles we should assert that the number returned
// is equal to 4.
assert(count($result) == 4);
// Then for each profile print its first and last name
foreach( $result as &$profile )
{
echo $profile['fname'], ' ', $profile['lname'];
}
// Now list all profiles which have a tag 'Wizcom' (regardless of the category), but
// take only their e-mail as return value.
$apiClient->HaystackListProfiles($hid, $result, null, 'Wizcom', 1, 'email'); // end
// First try to receive a list of profiles in a pesons's network.
$user1 = 'john.smith@myorg.com';
$apiClient->MyNetworkList($user1, $network);
// But since we haven't added any, the result should be empty.
assert(count($network) == 0);
// Now add two persons in the network of 'john.smith@myorg.com'.
$apiClient->MyNetworkAdd($user1, 'profile1@myorg.com, stanimir.peev@sciant.com');
$apiClient->MyNetworkList($user1, $network);
// Now we should have more profiles.
assert(count($result) == 2);
// Delete one of the users in $user1 network. This will remove
// the profile from 'john.smith@myorg.com' network, but the profile
// itself will contonue to exists in the system.
$apiClient->MyNetworkDel($user1, 'profile1@myorg.com'); // end
// With this call we delete the 'profile1@myorg.com' from the 'myFavouriteHaystack'
// haystack. Since this is the profile's one and only haystack, the profile is
// wiped out of the system.
$apiClient->ProfileDelete($hid, 'profile1@myorg.com');
// The following code delete a profile which belongs to multiple haytacks.
// As a result the profile is removed from 'myFavouriteHaystack' but continues to
// stay in the system.
$apiClient->ProfileDelete($hid, 'stanimir.peev@sciant.com'); // end
// This code deletes the haystack we created.
$apiClient->HaystackDelete($hid) // end
1.4.7