Permalink
Browse files

Added support for new feature to list possible fields on entry creation.

Added relationship support and examples.
Killed addSet() in favor of a more robust addData().
Added some links to documentation.
Added a version number to the lib.
Updated the documentation.
Updated Curl lib to the latest version.
  • Loading branch information...
1 parent 154b562 commit f74f04e2597bb7fe81012ef05c51ca916f82475f @SammyK committed Feb 18, 2012
Showing with 498 additions and 110 deletions.
  1. +43 −12 README.md
  2. +82 −9 controllers/donations.php
  3. +84 −36 controllers/personas.php
  4. +203 −0 controllers/relationships.php
  5. +26 −22 libraries/Curl.php
  6. +60 −31 libraries/Donor_tools.php
View
@@ -53,15 +53,15 @@ get() the fund's ID:
$this->donor_tools->get('fund', 123);
-### Create (POST) Data
+### Start A Create (POST) Object
Before we can just start adding data to the object willy-nilly, we need to instantiate the type of
data we are going to send. We'll use the singular form of the type of data we want to send. For
example a persona:
$this->donor_tools->startData('persona');
-Now we can start adding whatever tag we like. There are are three ways to do this.
+Now we can start adding whatever tag we like. There are are two ways to do this.
#### General Data
@@ -81,27 +81,37 @@ Or maybe some tags:
$this->donor_tools->addData('tag-list', array('Tag One', 'Tag Two'));
-#### Set Data
+#### Set Data (Removed)
-Personas can have multiple names, emails, addresses and phone numbers associated with them.
-Therefore we must treat each of those data differently. We could add a name:
+The addSet() method is no longer with us. :( But the good news is addData() has taken over its job
+and does a great job at it. The old way to add a set of names would have been like so:
$this->donor_tools->addSet('name', array(
'first-name' => 'Some',
'last-name' => 'Name',
));
-
-Or even two!
-
$this->donor_tools->addSet('name', array(
'first-name' => 'Another',
'last-name' => 'Name',
));
-Notice that for the set name, we're using the singular form. The library will automatically
-"pluralize" the name for the tag. One more example - an email:
+That won't work anymore. But now we can do the same thing with the addData() method. All we need is
+a numeric array of our array data.
+
+ $names = array(
+ array(
+ 'first-name' => 'Some',
+ 'last-name' => 'Name',
+ ),
+ array(
+ 'first-name' => 'Another',
+ 'last-name' => 'Name',
+ ),
+ );
+ $this->donor_tools->addData('names', $names);
- $this->donor_tools->addSet('email-address', array('email-address' => 'test@example.com'));
+Notice when we add the data with addData, we're using the plural form of "names". The library will
+automatically "singularize" the name for the tag.
#### Money
@@ -112,6 +122,8 @@ type, it has its own method:
Obviously personas don't have a money data type, but funds do!
+### Send A Create (POST) Request
+
Now that we have all the data we want to add, we send the create request:
$this->donor_tools->create();
@@ -151,7 +163,26 @@ Or for sources
$this->donor_tools->replacementSource(19);
$this->donor_tools->delete('source', 1234);
-For a full set of examples with more values and error handling, check out the files in the /controllers folder.
+#### Relationships
+
+You can create relationships between two personas in the system with the relationship object:
+
+ $this->donor_tools->startData('relationship');
+
+And then set up the required data.
+
+ $this->donor_tools->addData('persona-id', $person_id);
+ $this->donor_tools->addData('inverse-persona-id', $inverse_person_id);
+ $this->donor_tools->addData('relationship-type-id', 25);
+ if( $this->donor_tools->create($person_id);
+
+For a full example of realtionship management and list of possible relationship-type-id's, see
+/controllers/relationships.php
+
+#### But Wait, There's More!
+
+I've included examples of pretty much anything the API will allow. For a full set of examples with
+more values and error handling, check out the files in the /controllers folder.
Enjoy!
[SammyK](http://sammyk.me/)
@@ -2,6 +2,9 @@
class Donations extends CI_Controller
{
+ // Donations documentation
+ // http://www.donortools.com/userguide/api/donations
+
// Retrieve Donation(s)
public function index( $id = 0 )
{
@@ -42,6 +45,36 @@ public function index( $id = 0 )
$this->donor_tools->debug(TRUE);
}
+ // Retrieve available fields for creating a new entry
+ public function fields( $id = 0 )
+ {
+ // Load Donortools.com Lib
+ $this->load->library('donor_tools');
+
+ // Get field list
+ $status = $this->donor_tools->get('donation-new');
+
+ if( $status === TRUE )
+ {
+ // Data is returned as a SimpleXMLElement object
+ $data = $this->donor_tools->getResponse();
+
+ var_dump($data);
+
+ // Show the data in a pretty format
+ echo '<pre>';
+ echo htmlspecialchars($this->donor_tools->formatXml($data));
+ echo '</pre>';
+ return;
+ }
+
+ echo '<h2>Fail!</h2>';
+ // Get error
+ echo '<p>' . $this->donor_tools->getError() . '</p>';
+ // Show debug data
+ $this->donor_tools->debug(TRUE);
+ }
+
// Create Donation
public function create()
{
@@ -53,23 +86,61 @@ public function create()
// Donation Info
$donation_info = array(
- 'amount-in-cents' => 2000,
- 'fund-id' => 0, // Change this
- 'memo' => 'TPS Reports',
+ array(
+ 'amount-in-cents' => 1000,
+ 'fund-id' => 0, // Change this
+ 'memo' => 'Split #1',
+ ),
);
- $this->donor_tools->addSet('split', $donation_info);
+ $this->donor_tools->addData('splits', $donation_info);
// Other Data
$this->donor_tools->addData('donation-type-id', 0); // Change this
- $this->donor_tools->addData('persona-id', 0); // Change this
$this->donor_tools->addData('source-id', 0); // Change this
$this->donor_tools->addData('transaction-id', '2160755875');
+ // There are two ways to assoicate a donation with a person
+ // #1 - With their ID:
+ //$this->donor_tools->addData('persona-id', 0); // Change this
+
+ // #2 - With the "find-or-create-person" feature:
+ $person_data = array(
+ 'names' => array(
+ array(
+ 'first-name' => 'Bill',
+ 'last-name' => 'Monroe',
+ ),
+ ),
+ 'addresses' => array(
+ array(
+ 'street-address' => '100 Green St',
+ 'city' => 'Chicago',
+ 'state' => 'IL',
+ 'postal-code' => '60604',
+ 'country' => 'US',
+ ),
+ ),
+ 'phone-numbers' => array(
+ array(
+ 'phone-number' => '312-123-1234',
+ ),
+ ),
+ 'email-addresses' => array(
+ array(
+ 'email-address' => 'bill@example.com',
+ ),
+ ),
+ );
+ $this->donor_tools->addData('find-or-create-person', $person_data);
+
// CREATE
if( $this->donor_tools->create() )
{
$id = $this->donor_tools->getId();
- echo '<h2>Success! New Donation ID: ' . $id . '</h2>';
+ $persona_id = $this->donor_tools->getPersonaId();
+ echo '<h2>Success!</h2>';
+ echo '<p>New Donation ID: ' . $id . '</p>';
+ echo '<p>Persona ID: ' . $persona_id . '</p>';
return;
}
@@ -92,10 +163,12 @@ public function update( $id )
// Donation Info
$donation_info = array(
- 'id' => 0, // This split ID (Change this or you'll get a 404 error)
- 'memo' => 'My new memo',
+ array(
+ 'id' => 0, // This split ID (Change this or you'll get a 404 error)
+ 'memo' => 'My new memo',
+ ),
);
- $this->donor_tools->addSet('split', $donation_info);
+ $this->donor_tools->addData('splits', $donation_info);
// Other Data
$this->donor_tools->addData('transaction-id', '123');
Oops, something went wrong.

0 comments on commit f74f04e

Please sign in to comment.