Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit 339bca4a5ab73a64924e3e0c25ca39183bed935e 0 parents
David Coallier authored
Showing with 4,039 additions and 0 deletions.
  1. +135 −0 Services/Capsule.php
  2. +287 −0 Services/Capsule/Common.php
  3. +51 −0 Services/Capsule/Exception.php
  4. +279 −0 Services/Capsule/Kase.php
  5. +198 −0 Services/Capsule/Kase/Customfield.php
  6. +164 −0 Services/Capsule/Kase/History.php
  7. +79 −0 Services/Capsule/Kase/Milestone.php
  8. +125 −0 Services/Capsule/Kase/Party.php
  9. +126 −0 Services/Capsule/Kase/Tag.php
  10. +176 −0 Services/Capsule/Opportunity.php
  11. +197 −0 Services/Capsule/Opportunity/Customfield.php
  12. +164 −0 Services/Capsule/Opportunity/History.php
  13. +79 −0 Services/Capsule/Opportunity/Milestone.php
  14. +125 −0 Services/Capsule/Opportunity/Party.php
  15. +125 −0 Services/Capsule/Opportunity/Tag.php
  16. +124 −0 Services/Capsule/Organization.php
  17. +213 −0 Services/Capsule/Party.php
  18. +138 −0 Services/Capsule/Party/Cases.php
  19. +193 −0 Services/Capsule/Party/Customfield.php
  20. +158 −0 Services/Capsule/Party/History.php
  21. +154 −0 Services/Capsule/Party/Opportunity.php
  22. +80 −0 Services/Capsule/Party/People.php
  23. +125 −0 Services/Capsule/Party/Tag.php
  24. +133 −0 Services/Capsule/Person.php
  25. +98 −0 Services/Capsule/Resource.php
  26. +27 −0 Services_Capsule.tmproj
  27. +11 −0 examples/config.php.tpl
  28. +37 −0 examples/live/testopportunityupdate.php
  29. +21 −0 examples/opportunity/addopportunityhistorynote.php
  30. +21 −0 examples/opportunity/addopportunitytag.php
  31. +22 −0 examples/opportunity/deleteopportunitytag.php
  32. +24 −0 examples/opportunity/getanyopportunity.php
  33. +18 −0 examples/opportunity/getopportunity.php
  34. +20 −0 examples/opportunity/getopportunitytags.php
  35. +16 −0 examples/opportunity/listopportunities.php
  36. +23 −0 examples/party/getanyparty.php
  37. +19 −0 examples/party/getparty.php
  38. +18 −0 examples/party/getpartypeople.php
  39. +17 −0 examples/party/listparties.php
  40. +19 −0 examples/party/searchparties.php
135 Services/Capsule.php
@@ -0,0 +1,135 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+require_once 'HTTP/Request2.php';
+
+require_once 'Services/Capsule/Exception.php';
+require_once 'Services/Capsule/Common.php';
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version Release: @package_version@
+ */
+class Services_Capsule extends Services_Capsule_Common
+{
+ /**
+ * Sections available to the API
+ *
+ * @var array An array of sections available to the API
+ */
+ protected $sections = array();
+
+ /**
+ * Constructor
+ *
+ * Initialize the class with the API token.
+ *
+ * @param string $token The API Token you use for your API Calls
+ */
+ public function __construct($appName, $token)
+ {
+ $this->token = $token;
+ $this->appName = $appName;
+ }
+
+ /**
+ * Magical Getter
+ *
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param string $sub Items, Meetings, Notes, Projects or User.
+ *
+ * @return mixed Services_Capsule_*
+ */
+ public function __get($section)
+ {
+ $section = ucwords(strtolower($section));
+ switch ($section) {
+ case 'Party':
+ case 'Opportunity':
+ case 'Kase':
+ case 'Resource':
+ case 'Person':
+
+ if (!isset($this->sections[$section])) {
+ $classname = 'Services_Capsule_' .$section;
+
+ if (!class_exists($classname)) {
+ $filename = str_replace('_', '/', $classname) . '.php';
+
+ if (!(include $filename)) {
+ throw new Services_Capsule_RuntimeException(
+ 'File ' . $filename . ' does not exist.'
+ );
+ }
+
+ }
+
+ $this->sections[$section] = new $classname;
+
+ $this->sections[$section]
+ ->setToken($this->token)
+ ->setAppName($this->appName)
+ ->setModuleName(strtolower($section));
+ }
+
+ return $this->sections[$section];
+ break;
+
+ default:
+ throw new Services_Capsule_RuntimeException(
+ 'Section '. $section .' is not a valid API call. If you believe this ' .
+ 'is wrong please report a bug on http://pear.php.net/Services_Capsule'
+ );
+ }
+ }
+}
287 Services/Capsule/Common.php
@@ -0,0 +1,287 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version Release: @package_version@
+ */
+abstract class Services_Capsule_Common
+{
+ /**
+ * Sub section. History of an Opportunity for example
+ * is Services_Capsule_Opportunity_History
+ *
+ * @var string The sub section mame
+ */
+ protected $subSections = array();
+
+ /**
+ * The name of the module to call
+ *
+ * @var string The module name to call
+ */
+ protected $moduleName;
+
+ /**
+ * The identification token
+ *
+ * @link https://sample.capsulecrm.com/user/api
+ * @var string The web service identification token
+ */
+ protected $token;
+
+ /**
+ * The application name
+ *
+ * @var string The actual app name of your company
+ */
+ protected $appName;
+
+ /**
+ * An object of the HTTP_Request2 Client
+ *
+ * @var HTTP_Request2 An HTTP_Request2 instance.
+ */
+ protected $client;
+
+ /**
+ * The capsule webservice endpoint in a sprintf configurable url.
+ *
+ * @see $this->appName
+ * @var string The web service endpoint.
+ */
+ protected $endpoint = 'https://%s.capsulecrm.com/api/%s';
+
+ /**
+ * Magical Getter
+ *
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param string $sub Items, Meetings, Notes, Projects or User.
+ *
+ * @return mixed Services_Capsule_*
+ */
+ public function __get($section)
+ {
+ $section = ucwords(strtolower($section));
+
+ switch ($section) {
+ case 'History':
+ case 'Tag':
+ case 'Party':
+ case 'Opportunity':
+ case 'Customfield':
+ case 'Milestone':
+
+ $currentModule = ucfirst(strtolower($this->moduleName));
+
+ if (!isset($this->subSections[$section])) {
+ $classname = 'Services_Capsule_'. $currentModule . '_' .$section;
+
+ if (!class_exists($classname)) {
+ $filename = str_replace('_', '/', $classname) . '.php';
+
+ if (!(include $filename)) {
+ throw new Services_Capsule_RuntimeException(
+ 'File ' . $filename . ' does not exist.'
+ );
+ }
+
+ }
+
+ $this->subSections[$section] = new $classname;
+ }
+
+ $this->subSections[$section]
+ ->setToken($this->token)
+ ->setAppName($this->appName)
+ ->setModuleName(strtolower($currentModule));
+
+ return $this->subSections[$section];
+ break;
+
+ default:
+ throw new Services_Capsule_RuntimeException(
+ 'Section '. $section .' is not a valid API call. If you believe this ' .
+ 'is wrong please report a bug on http://pear.php.net/Services_Capsule'
+ );
+ }
+ }
+
+ /**
+ * Set the identification token
+ *
+ * This method is used to set the identification token
+ * that you can gather from the capsule website.
+ *
+ * @link https://sampl.capsulecrm.com/user/api
+ *
+ * @param string $token The web service token.
+ * @return object $this
+ */
+ public function setToken($token)
+ {
+ $this->token = $token;
+ return $this;
+ }
+
+ /**
+ * Set the application name
+ *
+ * This method is used to set the first part of the
+ * $this->endpoint variable (%s).
+ *
+ * @param string $appName The name of your application (company name).
+ * @return object $this
+ */
+ public function setAppName($appName)
+ {
+ $this->appName = $appName;
+ return $this;
+ }
+
+ /**
+ * Set the module naem
+ *
+ * This method is used to set the module name that the
+ * child will be invoking.
+ *
+ * @param string $moduleName The module name to use.
+ * @return object $this
+ */
+ public function setModuleName($moduleName)
+ {
+ $this->moduleName = $moduleName;
+ return $this;
+ }
+
+ /**
+ * Send the request to the capsule web service
+ *
+ * This method is used to send all the requests to the capsule web service.
+ *
+ * @throws Services_Capsule_UnexpectedValueException
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @uses HTTP_Request2
+ *
+ * @param string $url The URL to request.
+ * @param string $method The HTTP Method (Use HTTP_Request2::METHOD_*)
+ * Default is HTTP_Request2::METHOD_GET (GET).
+ * @param string $data The data to pass to the body. Null by default.
+ */
+ protected function sendRequest($url, $method = HTTP_Request2::METHOD_GET, $data = null)
+ {
+ if (!isset($this->appName)) {
+ throw new Services_Capsule_UnexpectedValueException(
+ 'Please set an app name.'
+ );
+ }
+
+ if (!isset($this->client) || !($this->client instanceof HTTP_Request2)) {
+ $this->client = new HTTP_Request2();
+ $this->client->setAdapter('curl');
+ }
+
+ $finalUrl = sprintf($this->endpoint, $this->appName, $this->moduleName);
+ $finalUrl = $finalUrl . $url;
+
+ $this->client
+ ->setHeader('Content-Type: application/json')
+ ->setHeader('Accept: application/json')
+ ->setAuth($this->token, 'x')
+ ->setMethod($method)
+ ->setUrl($finalUrl);
+
+ if (!is_null($data)) {
+ $this->client->setBody($data);
+ }
+
+ try {
+ $response = $this->client->send();
+ } catch (HTTP_Request2_Exception $e) {
+ throw new Services_Capsule_RuntimeException($e);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Parse the response
+ *
+ * This method is used to parse the response that is returned from
+ * the request that was made in $this->sendRequest().
+ *
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param HTTP_Request2_Response $response The response from the webservice.
+ * @return mixed stdClass|bool A stdClass object of the
+ * json-decode'ed body or true if
+ * the code is 201 (created)
+ */
+ protected function parseResponse(HTTP_Request2_Response $response)
+ {
+ $body = $response->getBody();
+ $return = json_decode($body);
+ if (!($return instanceof stdClass)) {
+ if ($response->getStatus() == 201 || $response->getStatus() == 200) {
+ return true;
+ }
+
+ throw new Services_Capsule_RuntimeException(
+ 'Invalid response with no valid json body'
+ );
+ }
+
+ return $return;
+ }
+}
51 Services/Capsule/Exception.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+interface Services_Capsule_Exception {}
+
+class Services_Capsule_RuntimeException extends RuntimeException implements Services_Capsule_Exception {}
+
+class Services_Capsule_UnexpectedValueException extends UnexpectedValueException
+ implements Services_Capsule_Exception {}
279 Services/Capsule/Kase.php
@@ -0,0 +1,279 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_case
+ * @version Release: @package_version@
+ */
+/**
+ * "Kase is not a typo. This is how the modules are invoked in the API /api/kase".
+ */
+class Services_Capsule_Kase extends Services_Capsule_Common
+{
+ /**
+ * Get an case
+ *
+ * This method is used to fetch a particular case by
+ * it's identification id.
+ *
+ * @link /api/kase/{id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $id The case ID to retrieve from the service.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function get($id)
+ {
+ $response = $this->sendRequest('/' . (double)$id);
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * List all the opportunities
+ *
+ * List opportunities. Optionally the results can be
+ * limited or paged using the parameters $limit and $start.
+ *
+ * @link /api/kase[?start={start}][&limit={limit}]
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param int $start The start page (Optional).
+ * @param int $limit The limit per page (Optional).
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getList($start = null, $limit = null)
+ {
+ $request = array();
+
+ if (!is_null($start)) {
+ $request['start'] = $start;
+ }
+
+ if (!is_null($limit)) {
+ $request['limit'] = $limit;
+ }
+
+ $request = http_build_query($request);
+ $response = $this->sendRequest('?' . $request);
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get any cases
+ *
+ * This method fetches a list of cases for a company (appName)
+ * by tag, or lastmodified field with the usual
+ * start and limit tag.
+ *
+ * If you are fetching by lastmodified, you must make sure that the input
+ * is formatted as ISO dates (IE: Midnight June 31, 2009 GMT would be 20090631T000000)
+ * or more explicitly YYYYMMDDTHHMMSS
+ *
+ * Example:
+ * <?php
+ * try {
+ * $capsule = new Services_Capsule($appName, $token);
+ * $results = $capsule->case->getAny(array(
+ * 'lastmodified' => '20090631T000000',
+ * 'start' => '100',
+ * 'limit' => '25'
+ * ));
+ * } catch (Services_Capsule_RuntimeException $re) {
+ * print_r($re); die();
+ * }
+ *
+ * print_r($results); // An object
+ * ?>
+ *
+ * @link /api/kase?lastmodified={YYYYMMDDTHHMMSS}[&start={start}][&limit={limit}]
+ * @link /api/kase?tag={tag}[&start={start}][&limit={limit}]
+ *
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param array $params An array of parameters to search for.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAny(array $params)
+ {
+ $request = http_build_query($params);
+ $response = $this->sendRequest('?' . $request);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get a list of custom fields
+ *
+ * List custom fields for a case. Note that boolean custom fields
+ * that have been set to false will not be returned.
+ *
+ * @link /api/kase/{id}/customField
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve
+ * the custom field from.
+ * @param string $fieldName The custom field to retrieve.
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getCustomField($caseId, $fieldName)
+ {
+ $url = '/' . (double)$caseId . '/' . $fieldName;
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get a list of available custom fields
+ *
+ * List of available custom field configurations for cases.
+ *
+ * @link /api/kase/customfield/definitions
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getCustomFieldDefinitions()
+ {
+ $response = $this->sendRequest('/customfield/definitions');
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get a list of additional parties
+ *
+ * View additional people & organisations related to this case.
+ *
+ * @link /api/kase/{id}/party
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $kaseId The case to retrieve the parties from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getParty($kaseId)
+ {
+ $url = '/' . (double)$kaseId . '/party';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get case history
+ *
+ * History of notes and emails for case records.
+ *
+ * @link /api/kase/{id}/history
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve the history from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getHistory($caseId)
+ {
+ $url = '/' . (double)$caseId . '/history';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get case tags
+ *
+ * A list of tags for an case.
+ *
+ * @link /api/kase/{id}/tag
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve the tags from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getTags($caseId)
+ {
+ $url = '/' . (double)$caseId . '/tag';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete a case
+ *
+ * Delete a case.
+ *
+ * @link /api/kase/{kase-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to delete.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($caseId)
+ {
+ $url = '/' . (double)$caseId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);
+ }
+}
198 Services/Capsule/Kase/Customfield.php
@@ -0,0 +1,198 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_case
+ * @link http://capsulecrm.com/help/page/javelin_api_case_custom_fields
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Kase_Customfield extends Services_Capsule_Common
+{
+
+ /**
+ * Get a list of custom fields
+ *
+ * List custom fields for a case. Note that boolean custom fields
+ * that have been set to false will not be returned.
+ *
+ * @link /api/kase/{id}/customfield
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve
+ * the custom field from.
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($caseId)
+ {
+ $url = '/' . (double)$caseId . '/customfield';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get a list of available custom fields
+ *
+ * List of available custom field configurations for opportunities.
+ *
+ * @link /api/kase/customfield/definitions
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getDefinitions()
+ {
+ $response = $this->sendRequest('/customfield/definitions');
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add a new Custom field to a case (BY CASE ID)
+ *
+ * This method is used to create a new custom field to a
+ * case that is associated in a case.
+ *
+ * @link /api/kase/{kase-id}/customfield
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to create the new field on.
+ * @param array $fields An assoc array of fields to add in the new
+ * customField
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function add($caseId, array $fields)
+ {
+ if (!isset($fields['boolean'])) {
+ throw new Services_Capsule_RuntimeException(
+ '"boolean" parameter of second parameter required ' .
+ 'Ex: ("boolean" => "true")'
+ );
+ }
+
+ $url = '/' . (double)$caseId . '/customfield';
+ $customField = array('customField' => $fields);
+
+ $response = $this->sendRequest(
+ $url, HTTP_Request2::METHOD_POST, json_encode($customField)
+ );
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Update the custom field of a case
+ *
+ * This method is used to update an history note to an
+ * case.
+ *
+ * Updating an existing boolean field to a value of false
+ * will delete the custom field from the contact, it will
+ * not be displayed on the next get.
+ *
+ * @link /api/kase/{kase-id}/customfield/{customfield-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to create the new field on.
+ * @param double $fieldId
+ * @param array $fields An assoc array of fields to add in the new
+ * customField
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function update($caseId, $fieldId, $fields)
+ {
+ $url = '/' . (double)$caseId . '/customfield/ ' . (double)$fieldId;
+ $customField = array('customField' => $fields);
+
+ $response = $this->sendRequest(
+ $url, HTTP_Request2::METHOD_PUT, json_encode($customField)
+ );
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete the custom field of a case
+ *
+ * This method is used to delete the custom field
+ * of a case.
+ *
+ * Updating an existing boolean field to a value of false
+ * will delete the custom field from the contact, it will
+ * not be displayed on the next get.
+ *
+ * @link /api/kase/{kase-id}/customfield/{customfield-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to create the new field on.
+ * @param double $fieldId
+ * @param array $fields An assoc array of fields to add in the new
+ * customField
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($caseId, $fieldId)
+ {
+ $url = '/' . (double)$caseId . '/customfield/ ' . (double)$fieldId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);
+ }
+}
164 Services/Capsule/Kase/History.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_case
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Kase_History extends Services_Capsule_Common
+{
+ /**
+ * Get case history
+ *
+ * History of notes and emails for case records.
+ *
+ * @link /api/case/{id}/history
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve the history from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($caseId)
+ {
+ $url = '/' . (double)$caseId . '/history';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add an history note to a case
+ *
+ * This method is used to add an history note to an
+ * case.
+ *
+ * @link /api/case/{kase-id}/history
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to create the note on.
+ * @param string $note The note to add to history.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function addNote($caseId, $note)
+ {
+ $url = '/' . (double)$caseId . '/history';
+
+ $note = array(
+ 'historyItem' => array(
+ 'note' => $note
+ ),
+ );
+
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_POST, json_encode($note));
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add an history note of a case
+ *
+ * This method is used to update an history note to an
+ * case.
+ *
+ * @link /api/case/{kase-id}/history/{history-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to create the tags on.
+ * @param double $historyId The note id to update.
+ * @param string $note The note to add to history.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function updateNote($caseId, $historyId, $note)
+ {
+ $url = '/' . (double)$caseId . '/history/' . (double)$historyId;
+
+ $note = array(
+ 'historyItem' => array(
+ 'note' => $note
+ ),
+ );
+
+ $response = $this->sendRequest(
+ $url, HTTP_Request2::METHOD_PUT, json_encode($note)
+ );
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete an history note from a case
+ *
+ * This method is used to delete an history note from an
+ * case.
+ *
+ * @link /api/case/{kase-id}/history/{history-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to delete the note from.
+ * @param double $historyId The note id to delete.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function deleteNote($caseId, $historyId)
+ {
+ $url = '/' . (double)$caseId . '/history/' . (double)$historyId;
+
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+ return $this->parseResponse($response);
+ }
+}
79 Services/Capsule/Kase/Milestone.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_opportunity
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Opportunity_Milestone extends Services_Capsule_Common
+{
+
+ /**
+ * Get a list of opportunity milestones
+ *
+ * Each account in Capsule can have a unique opportunity milestone configuration.
+ * Use the milestone names when creating or updating opportunities.
+ *
+ * @link /api/opportunity/milestones
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $partyId The party to retrieve the people from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($partyId)
+ {
+ $response = $this->sendRequest('/milestones');
+ return $this->parseResponse($response);
+ }
+}
125 Services/Capsule/Kase/Party.php
@@ -0,0 +1,125 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_case
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Kase_Party extends Services_Capsule_Common
+{
+
+ /**
+ * Get a list of additional parties
+ *
+ * View additional people & organisations related to this case.
+ *
+ * @link /api/case/{id}/party
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve the parties from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($caseId)
+ {
+ $url = '/' . (double)$caseId . '/party';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add a party to a case
+ *
+ * This method is used to Add the Person or Organisation
+ * to the case supplied in the $partyId parameter
+ *
+ * @link /api/case/{id}/party/{party-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to add the party on.
+ * @param string $partyId The party/org to add to the case.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function add($caseId, $partyId)
+ {
+ $url = '/' . (double)$caseId . '/party/' . (double)$partyId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_POST);
+
+ return $this->parseResponse($response);
+ }
+ /**
+ * Delete a party from a case
+ *
+ * This method is used to delete a Person or Organisation
+ * to the case supplied in the $partyId parameter
+ *
+ * @link /api/case/{id}/party/{party-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to delete the party from.
+ * @param string $partyId The party/org to delete from the case.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($caseId, $partyId)
+ {
+ $url = '/' . (double)$caseId . '/party/' . (double)$partyId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);
+ }
+}
126 Services/Capsule/Kase/Tag.php
@@ -0,0 +1,126 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_case
+ * @link http://capsulecrm.com/help/page/javelin_api_case_tags
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Kase_Tag extends Services_Capsule_Common
+{
+ /**
+ * Get case tags
+ *
+ * A list of tags for a case.
+ *
+ * @link /api/kase/{id}/tagName
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to retrieve the tags from.
+ * @return stdClass A stdClass object containing the information from.
+ * the json-decoded response from the server.
+ */
+ public function getAll($caseId)
+ {
+ $url = '/' . (double)$caseId . '/tag';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add a tag to a case
+ *
+ * The tag name will need to be URL encoded. If the tag is already present on
+ * the case status in the response will be 200 OK, when the tag is added
+ * the response will be 201 Created.
+ *
+ * @link /api/kase/{kase-id}/tag/{tag-name}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to create the tags on.
+ * @param string $tagName The name of the new tag to create.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function add($caseId, $tagName)
+ {
+ $url = '/' . (double)$caseId . '/tag/' . urlencode($tagName);
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_POST);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete a tag from a case
+ *
+ * The tag name will need to be URL encoded.
+ *
+ * @link /api/kase/{kase-id}/tag/{tag-name}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case to delete the tags from.
+ * @param string $tagName The name of the new tag to delete.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($caseId, $tagName)
+ {
+ $url = '/' . (double)$caseId . '/tag/' . urlencode($tagName);
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);
+ }
+}
176 Services/Capsule/Opportunity.php
@@ -0,0 +1,176 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_opportunity
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Opportunity extends Services_Capsule_Common
+{
+ /**
+ * Get an opportunity
+ *
+ * This method is used to fetch a particular opportunity by
+ * it's identification id.
+ *
+ * @link /api/opportunity/{id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $id The opportunity ID to retrieve from the service.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function get($id)
+ {
+ $response = $this->sendRequest('/' . (double)$id);
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * List all the opportunities
+ *
+ * List opportunities. Optionally the results can be
+ * limited or paged using the parameters $limit and $start.
+ *
+ * @link /api/opportunity[?start={start}][&limit={limit}]
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param int $start The start page (Optional).
+ * @param int $limit The limit per page (Optional).
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getList($start = null, $limit = null)
+ {
+ $request = array();
+
+ if (!is_null($start)) {
+ $request['start'] = $start;
+ }
+
+ if (!is_null($limit)) {
+ $request['limit'] = $limit;
+ }
+
+ $request = http_build_query($request);
+ $response = $this->sendRequest('?' . $request);
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get any opportunities
+ *
+ * This method fetches a list of opportunities for a company (appName)
+ * by tag, milestone (name), or lastmodified field with the usual
+ * start and limit tag.
+ *
+ * If you are fetching by lastmodified, you must make sure that the input
+ * is formatted as ISO dates (IE: Midnight June 31, 2009 GMT would be 20090631T000000)
+ * or more explicitly YYYYMMDDTHHMMSS
+ *
+ * Example:
+ * <?php
+ * try {
+ * $capsule = new Services_Capsule($appName, $token);
+ * $results = $capsule->opportunity->getAny(array(
+ * 'lastmodified' => '20090631T000000',
+ * 'start' => '100',
+ * 'limit' => '25'
+ * ));
+ * } catch (Services_Capsule_RuntimeException $re) {
+ * print_r($re); die();
+ * }
+ *
+ * print_r($results); // An object
+ * ?>
+ *
+ * @link /api/opportunity?lastmodified={YYYYMMDDTHHMMSS}[&start={start}][&limit={limit}]
+ * @link /api/opportunity?tag={tag}[&start={start}][&limit={limit}]
+ *
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param array $params An array of parameters to search for.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAny(array $params)
+ {
+ $request = http_build_query($params);
+ $response = $this->sendRequest('?' . $request);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete an opportunity
+ *
+ * Delete the opportunity passed to the method.
+ *
+ * @link /api/opportunity/{opportunity-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to delete.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($opportunityId)
+ {
+ $url = '/' . (double)$opportunityId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);
+ }
+
+}
197 Services/Capsule/Opportunity/Customfield.php
@@ -0,0 +1,197 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_opportunity
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Opportunity_Customfield extends Services_Capsule_Common
+{
+
+ /**
+ * Get a list of custom fields
+ *
+ * List custom fields for a case. Note that boolean custom fields
+ * that have been set to false will not be returned.
+ *
+ * @link /api/opportunity/{id}/customfield
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to retrieve
+ * the custom field from.
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($opportunityId)
+ {
+ $url = '/' . (double)$opportunityId . '/customfield' ;
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Get a list of available custom fields
+ *
+ * List of available custom field configurations for opportunities.
+ *
+ * @link /api/opportunity/customfield/definitions
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getDefinitions()
+ {
+ $response = $this->sendRequest('/customfield/definitions');
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add a new Custom field to an opportunity (BY CASE ID)
+ *
+ * This method is used to create a new custom field to a
+ * case that is associated in an opportunity.
+ *
+ * @link /api/opportunity/{kase-id}/customfield
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to create the new field on.
+ * @param array $fields An assoc array of fields to add in the new
+ * customField
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function add($caseId, array $fields)
+ {
+ if (!isset($fields['boolean'])) {
+ throw new Services_Capsule_RuntimeException(
+ '"boolean" parameter of second parameter required ' .
+ 'Ex: ("boolean" => "true")'
+ );
+ }
+
+ $url = '/' . (double)$caseId . '/customfield';
+ $customField = array('customField' => $fields);
+
+ $response = $this->sendRequest(
+ $url, HTTP_Request2::METHOD_POST, json_encode($customField)
+ );
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Update the custom field of an opportunity
+ *
+ * This method is used to update an history note to an
+ * opportunity.
+ *
+ * Updating an existing boolean field to a value of false
+ * will delete the custom field from the contact, it will
+ * not be displayed on the next get.
+ *
+ * @link /api/opportunity/{kase-id}/customfield/{customfield-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to create the new field on.
+ * @param double $fieldId
+ * @param array $fields An assoc array of fields to add in the new
+ * customField
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function update($caseId, $fieldId, $fields)
+ {
+ $url = '/' . (double)$caseId . '/customfield/ ' . (double)$fieldId;
+ $customField = array('customField' => $fields);
+
+ $response = $this->sendRequest(
+ $url, HTTP_Request2::METHOD_PUT, json_encode($customField)
+ );
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete the custom field of an opportunity
+ *
+ * This method is used to delete the custom field
+ * of an opportunity.
+ *
+ * Updating an existing boolean field to a value of false
+ * will delete the custom field from the contact, it will
+ * not be displayed on the next get.
+ *
+ * @link /api/opportunity/{kase-id}/customfield/{customfield-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $caseId The case id to create the new field on.
+ * @param double $fieldId
+ * @param array $fields An assoc array of fields to add in the new
+ * customField
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($caseId, $fieldId)
+ {
+ $url = '/' . (double)$caseId . '/customfield/ ' . (double)$fieldId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);
+ }
+}
164 Services/Capsule/Opportunity/History.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_opportunity
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Opportunity_History extends Services_Capsule_Common
+{
+ /**
+ * Get opportunity history
+ *
+ * History of notes and emails for opportunity records.
+ *
+ * @link /api/opportunity/{id}/history
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to retrieve the history from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($opportunityId)
+ {
+ $url = '/' . (double)$opportunityId . '/history';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add an history note to an opportunity
+ *
+ * This method is used to add an history note to an
+ * opportunity.
+ *
+ * @link /api/opportunity/{opportunity-id}/history
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to create the note on.
+ * @param string $note The note to add to history.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function addNote($opportunityId, $note)
+ {
+ $url = '/' . (double)$opportunityId . '/history';
+
+ $note = array(
+ 'historyItem' => array(
+ 'note' => $note
+ ),
+ );
+
+ $response = $this->sendRequest(
+ $url, HTTP_Request2::METHOD_POST, json_encode($note)
+ );
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add an history note of an opportunity
+ *
+ * This method is used to update an history note to an
+ * opportunity.
+ *
+ * @link /api/opportunity/{opportunity-id}/history/{history-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to create the tags on.
+ * @param double $historyId The note id to update.
+ * @param string $note The note to add to history.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function updateNote($opportunityId, $historyId, $note)
+ {
+ $url = '/' . (double)$opportunityId . '/history/' . (double)$historyId;
+
+ $note = array(
+ 'historyItem' => array(
+ 'note' => $note
+ ),
+ );
+
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_PUT, json_encode($note));
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Delete an history note from an opportunity
+ *
+ * This method is used to delete an history note from an
+ * opportunity.
+ *
+ * @link /api/opportunity/{opportunity-id}/history/{history-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to delete the note from.
+ * @param double $historyId The note id to delete.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function deleteNote($opportunityId, $historyId)
+ {
+ $url = '/' . (double)$opportunityId . '/history/' . (double)$historyId;
+
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+ return $this->parseResponse($response);
+ }
+}
79 Services/Capsule/Opportunity/Milestone.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_opportunity
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Opportunity_Milestone extends Services_Capsule_Common
+{
+
+ /**
+ * Get a list of opportunity milestones
+ *
+ * Each account in Capsule can have a unique opportunity milestone configuration.
+ * Use the milestone names when creating or updating opportunities.
+ *
+ * @link /api/opportunity/milestones
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $partyId The party to retrieve the people from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($partyId)
+ {
+ $response = $this->sendRequest('/milestones');
+ return $this->parseResponse($response);
+ }
+}
125 Services/Capsule/Opportunity/Party.php
@@ -0,0 +1,125 @@
+<?php
+/**
+ * +-----------------------------------------------------------------------+
+ * | Copyright (c) 2010, David Coallier & echolibre ltd |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | o Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | o Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution.|
+ * | o The names of the authors may not be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * | |
+ * +-----------------------------------------------------------------------+
+ * | Author: David Coallier <david@echolibre.com> |
+ * +-----------------------------------------------------------------------+
+ *
+ * PHP version 5
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @copyright echolibre ltd. 2009-2010
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @version GIT: $Id$
+ */
+
+/**
+ * Services_Capsule
+ *
+ * @category Services
+ * @package Services_Capsule
+ * @author David Coallier <david@echolibre.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @link http://github.com/davidcoallier/Services_Capsule
+ * @link http://capsulecrm.com/help/page/javelin_api_opportunity
+ * @version Release: @package_version@
+ */
+class Services_Capsule_Opportunity_Party extends Services_Capsule_Common
+{
+
+ /**
+ * Get a list of additional parties
+ *
+ * View additional people & organisations related to this opportunity.
+ *
+ * @link /api/opportunity/{id}/party
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to retrieve the parties from.
+ * @return stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function getAll($opportunityId)
+ {
+ $url = '/' . (double)$opportunityId . '/party';
+ $response = $this->sendRequest($url);
+
+ return $this->parseResponse($response);
+ }
+
+ /**
+ * Add a party to an opportunity
+ *
+ * This method is used to Add the Person or Organisation
+ * to the opportunity supplied in the $partyId parameter
+ *
+ * @link /api/opportunity/{id}/party/{party-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to add the party on.
+ * @param string $partyId The party/org to add to the opportunity.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function add($opportunityId, $partyId)
+ {
+ $url = '/' . (double)$opportunityId . '/party/' . (double)$partyId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_POST);
+
+ return $this->parseResponse($response);
+ }
+ /**
+ * Delete a party from an opportunity
+ *
+ * This method is used to delete a Person or Organisation
+ * to the opportunity supplied in the $partyId parameter
+ *
+ * @link /api/opportunity/{id}/party/{party-id}
+ * @throws Services_Capsule_RuntimeException
+ *
+ * @param double $opportunityId The opportunity to delete the party from.
+ * @param string $partyId The party/org to delete from the opportunity.
+ *
+ * @return mixed bool|stdClass A stdClass object containing the information from
+ * the json-decoded response from the server.
+ */
+ public function delete($opportunityId, $partyId)
+ {
+ $url = '/' . (double)$opportunityId . '/party/' . (double)$partyId;
+ $response = $this->sendRequest($url, HTTP_Request2::METHOD_DELETE);
+
+ return $this->parseResponse($response);