3 * StatusNet, the distributed open-source microblogging tool
5 * Show information about the relationship between two users
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR.'/lib/apibareauth.php';
37 * Outputs detailed information about the relationship between two users
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class ApiFriendshipsShowAction extends ApiBareAuthAction
53 * Take arguments for running
55 * @param array $args $_REQUEST args
57 * @return boolean success flag
61 function prepare($args)
63 parent::prepare($args);
65 if ($this->requiresAuth()) {
66 if ($this->checkBasicAuthUser() == false) {
71 $source_id = (int)$this->trimmed('source_id');
72 $source_screen_name = $this->trimmed('source_screen_name');
73 $target_id = (int)$this->trimmed('target_id');
74 $target_screen_name = $this->trimmed('target_screen_name');
76 if (!empty($source_id)) {
77 $this->source = User::staticGet($source_id);
78 } elseif (!empty($source_screen_name)) {
79 $this->source = User::staticGet('nickname', $source_screen_name);
81 $this->source = $this->auth_user;
84 if (!empty($target_id)) {
85 $this->target = User::staticGet($target_id);
86 } elseif (!empty($target_screen_name)) {
87 $this->target = User::staticGet('nickname', $target_screen_name);
95 * Determines whether this API resource requires auth. Overloaded to look
96 * return true in case source_id and source_screen_name are both empty
98 * @return boolean true or false
101 function requiresAuth()
103 if (common_config('site', 'private')) {
107 $source_id = $this->trimmed('source_id');
108 $source_screen_name = $this->trimmed('source_screen_name');
110 if (empty($source_id) && empty($source_screen_name)) {
120 * Check the format and show the user info
122 * @param array $args $_REQUEST data (unused)
127 function handle($args)
129 parent::handle($args);
131 if (!in_array($this->format, array('xml', 'json'))) {
132 $this->clientError(_('API method not found!'), 404);
136 if (empty($this->source)) {
138 _('Could not determine source user.'),
144 if (empty($this->target)) {
146 _('Could not find target user.'),
152 $result = $this->twitter_relationship_array($this->source, $this->target);
154 switch ($this->format) {
156 $this->init_document('xml');
157 $this->show_twitter_xml_relationship($result[relationship]);
158 $this->end_document('xml');
161 $this->init_document('json');
162 print json_encode($result);
163 $this->end_document('json');