Ian province abbreviation patch - issue 724
[civicrm-core.git] / api / v3 / examples / MailingGroup / Subscribe.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
3 * Test Generated example of using mailing_group subscribe API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9function 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 );
6a488035 17
50fb255d 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;
6a488035
TO
34}
35
fb32de45 36/**
50fb255d 37 * Function returns array of result expected from previous function.
38 *
39 * @return array
40 * API result array
6a488035 41 */
50fb255d 42function mailing_group_subscribe_expectedresult() {
6a488035 43
53ca8fd7 44 $expectedResult = array(
50fb255d 45 'is_error' => 0,
46 'version' => 3,
47 'count' => 1,
48 'id' => 1,
49 'values' => array(
9f1b81e0 50 '1' => array(
50fb255d 51 'contact_id' => '3',
52 'subscribe_id' => '1',
53 'hash' => '67eac7789eaee00',
54 ),
6a488035 55 ),
50fb255d 56 );
6a488035 57
fb32de45 58 return $expectedResult;
6a488035
TO
59}
60
50fb255d 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
69d79249 66* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MailingGroupTest.php
6a488035
TO
67*
68* You can see the outcome of the API tests at
69d79249 69* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
70*
71* To Learn about the API read
69d79249 72* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 73*
69d79249 74* Browse the api on your own site with the api explorer
41d4d31f 75* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
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
b259a4ab 82*/