forked from alchemy-fr/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuthedUser.php
171 lines (160 loc) · 4.97 KB
/
AuthedUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* @version $Id$
* @author Andrew Morton <[email protected]>
* @license http://opensource.org/licenses/lgpl-license.php
* GNU Lesser General Public License, Version 2.1
* @package Phlickr
*/
/**
* Phlickr_Api includes the core classes.
*/
require_once dirname(__FILE__) . '/Api.php';
/**
* This class extends Phlickr_User.
*/
require_once dirname(__FILE__) . '/User.php';
/**
* One or more methods returns Phlickr_AuthedPhotosetList objects.
*/
require_once dirname(__FILE__) . '/AuthedPhotosetList.php';
/**
* This class extends Phlickr_User to perform actions on a logged in user.
*
* Sample usage:
* <code>
* <?php
* include_once '/AuthedUser.php';
*
* // instantiate the object
* $api = new Phlickr_Api(FLICKR_API_KEY, FLICKR_API_SECRET, FLICKR_TOKEN);
* $user = new Phlickr_AuthedUser($api);
*
* // go through your favorite photos
* $photolist = $user->getFavoritePhotoList();
*
* // add a new favorite photo
* $user->addFavorite(12871545);
*
* // remove a favorite photo
* $user->removeFavorite(12871545);
* ?>
* </code>
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
* @see Phlickr_User
* @since 0.1.6
*/
class Phlickr_AuthedUser extends Phlickr_User {
/**
* Constructor.
*
* @param object Phlickr_Api $api This object must have valid
* authentication information or an exception will be thrown.
*/
function __construct(Phlickr_Api $api) {
assert($api->isAuthValid());
parent::__construct($api, $api->getUserId());
}
/**
* Return a UserList of this user's contacts.
*
* @return object Phlickr_UserList
*/
public function getContactUserList() {
$request = $this->getApi()->createRequest(
'flickr.contacts.getList',
array('user_id'=>$this->getId())
);
return new Phlickr_UserList($request);
}
/**
* Return a PhotoList of this user's favorite photos.
*
* @param integer $perPage Number of photos per page
* @return object Phlickr_PhotoList
*/
public function getFavoritePhotoList($perPage = Phlickr_PhotoList::PER_PAGE_DEFAULT) {
$request = $this->getApi()->createRequest('flickr.favorites.getList',
array('user_id'=>$this->getId())
);
return new Phlickr_PhotoList($request, $perPage);
}
/**
* Return a GroupList of the groups that this user belongs to.
*
* @return object Phlickr_GroupList
*/
public function getGroupList() {
$request = $this->getApi()->createRequest(
'flickr.groups.pools.getGroups',
array('user_id'=>$this->getId())
);
return new Phlickr_GroupList($request);
}
/**
* Return a PhotoList of this user's photos.
*
* @param integer $perPage Number of photos per page
* @return object Phlickr_PhotoList
*/
public function getPhotoList($perPage = Phlickr_PhotoList::PER_PAGE_DEFAULT) {
$request = $this->getApi()->createRequest('flickr.photos.search',
array('user_id'=>$this->getId())
);
return new Phlickr_PhotoList($request, $perPage);
}
/**
* Return a PhotosetList for this user.
*
* @return object Phlickr_PhotosetList
*/
public function getPhotosetList() {
return new Phlickr_AuthedPhotosetList($this->getApi());
}
/**
* Add a photo to the user's list of favorites.
*
* Add the photo and return the updated favorite list.
*
* @param interger Photo id.
* @return object Phlickr_PhotoList the new favorites. Note: the photo list
* is refreshed before it is returned but the new favorite might
* not be listed. If this is the case, you'll need to call
* refresh() again.
* @since 0.1.7
*/
public function addFavorite($photo_id) {
$resp = $this->getApi()->executeMethod(
'flickr.favorites.add',
array('photo_id' => $photo_id)
);
// call refresh to clear out the cached favorite list
$ret = $this->getFavoritePhotoList();
$ret->refresh();
return $ret;
}
/**
* Remove a photo from the user's list of favorites.
*
* Remove the photo and return the updated favorite list.
*
* @param interger Photo id.
* @return object Phlickr_PhotoList the new favorites. Note: the photo list
* is refreshed before it is returned but the old favorite might
* still be listed. If this is the case, you'll need to call
* refresh().
* @since 0.1.7
*/
public function removeFavorite($photo_id) {
$resp = $this->getApi()->executeMethod(
'flickr.favorites.remove',
array('photo_id' => $photo_id)
);
$ret = $this->getFavoritePhotoList();
// call refresh to clear out the cached favorite list
$ret->refresh();
return $ret;
}
}