Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-03-03-23-44-14
[civicrm-core.git] / api / v3 / examples / MailingGroup / Subscribe.php
1 <?php
2 /**
3 * Test Generated example of using mailing_group subscribe API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function mailing_group_subscribe_example() {
10 $params = array(
11 'email' => 'test@test.test',
12 'group_id' => 2,
13 'contact_id' => 3,
14 'hash' => 'b15de8b64e2cec34',
15 'time_stamp' => '20101212121212',
16 );
17
18 try{
19 $result = civicrm_api3('mailing_group', 'subscribe', $params);
20 }
21 catch (CiviCRM_API3_Exception $e) {
22 // Handle error here.
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
26 return array(
27 'error' => $errorMessage,
28 'error_code' => $errorCode,
29 'error_data' => $errorData,
30 );
31 }
32
33 return $result;
34 }
35
36 /**
37 * Function returns array of result expected from previous function.
38 *
39 * @return array
40 * API result array
41 */
42 function mailing_group_subscribe_expectedresult() {
43
44 $expectedResult = array(
45 'is_error' => 0,
46 'version' => 3,
47 'count' => 1,
48 'id' => 1,
49 'values' => array(
50 '1' => array(
51 'contact_id' => '3',
52 'subscribe_id' => '1',
53 'hash' => '67eac7789eaee00',
54 ),
55 ),
56 );
57
58 return $expectedResult;
59 }
60
61 /**
62 * This example has been generated from the API test suite.
63 * The test that created it is called
64 * testMailerGroupSubscribeGivenContactId
65 * and can be found in
66 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MailingGroupTest.php
67 *
68 * You can see the outcome of the API tests at
69 * https://test.civicrm.org/job/CiviCRM-master-git/
70 *
71 * To Learn about the API read
72 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
73 *
74 * Browse the api on your own site with the api explorer
75 * http://MYSITE.ORG/path/to/civicrm/api
76 *
77 * Read more about testing here
78 * http://wiki.civicrm.org/confluence/display/CRM/Testing
79 *
80 * API Standards documentation:
81 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
82 */