1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5/**
6 * Stories endpoint driver
7 *
8 * PHP version 5.1.0+
9 *
10 * LICENSE: This source file is subject to version 3.0 of the PHP license
11 * that is available through the world-wide-web at the following URI:
12 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
13 * the PHP License and are unable to obtain it through the web, please
14 * send a note to license@php.net so we can mail you a copy immediately.
15 *
16 * @category    Services
17 * @package     Services_Digg
18 * @author      Joe Stump <joe@joestump.net>
19 * @copyright   1997-2007 The PHP Group
20 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
21 * @version     CVS: $Id:$
22 * @link        http://pear.php.net/package/Services_Digg
23 */
24
25/**
26 * Services_Digg_Stories
27 *
28 * @category    Services
29 * @package     Services_Digg
30 * @author      Joe Stump <joe@joestump.net>
31 */
32class Services_Digg_Stories extends Services_Digg_Common
33{
34    /**
35     * __call
36     *
37     * @access      public
38     * @param       string      $function       API endpiont to call
39     * @param       array       $args
40     * @throws      Services_Digg_Exception
41     */
42    public function __call($function, array $args)
43    {
44        $endPoint = '/stories/' . $function;
45        $params = array();
46        if (isset($args[0]) && is_array($args[0])) {
47            $params = $args[0];
48        }
49
50        return $this->sendRequest($endPoint, $params);
51    }
52
53    /**
54     * Get all stories
55     *
56     * @access      public
57     * @param       array       $params     Digg API arguments
58     * @throws      Services_Digg_Exception
59     */
60    public function getAll(array $params = array())
61    {
62        return $this->sendRequest('/stories', $params);
63    }
64
65    /**
66     * Get a single story by ID
67     *
68     * @access      public
69     * @param       int         $id         ID of story
70     * @param       array       $params     API parameters
71     * @throws      Services_Digg_Exception
72     */
73    public function getStoryById($id, array $params = array())
74    {
75        $result = $this->sendRequest('/story/' . $id, $params);
76        return $result->stories[0];
77    }
78
79    /**
80     * Get a single story by title
81     *
82     * @access      public
83     * @param       string      $title      Clean title of story
84     * @param       array       $params     API parameters
85     * @throws      Services_Digg_Exception
86     */
87    public function getStoryByTitle($title, array $params = array())
88    {
89        $result = $this->sendRequest('/story/' . $title, $params);
90        return $result->stories[0];
91    }
92
93    /**
94     * Get a list of stories by their ID's
95     *
96     * @access      public
97     * @param       array       $stories    An array of story ID's
98     * @param       array       $params     Digg API arguments
99     * @throws      Services_Digg_Exception
100     */
101    public function getStoriesById(array $stories, array $params = array())
102    {
103        $endPoint = '/stories/' . implode(',', $stories);
104        return $this->sendRequest($endPoint, $params);
105    }
106
107    /**
108     * Get a list of stories' comments
109     *
110     * @access      public
111     * @param       array       $stories    An array of story ID's
112     * @param       array       $params     Digg API arguments
113     * @throws      Services_Digg_Exception
114     */
115    public function getStoriesComments(array $stories, array $params = array())
116    {
117        $endPoint = '/stories/' . implode(',', $stories) . '/comments';
118        return $this->sendRequest($endPoint, $params);
119    }
120
121    /**
122     * Get a list of stories' diggs
123     *
124     * @access      public
125     * @param       array       $stories    An array of story ID's
126     * @param       array       $params     Digg API arguments
127     * @throws      Services_Digg_Exception
128     */
129    public function getStoriesDiggs(array $stories, array $params = array())
130    {
131        $endPoint = '/stories/' . implode(',', $stories) . '/diggs';
132        return $this->sendRequest($endPoint, $params);
133    }
134
135    /**
136     * Get stories by container
137     *
138     * @access      public
139     * @param       string      $container  Name of container (ie. Sports)
140     * @param       array       $params     Digg API arguments
141     * @throws      Services_Digg_Exception
142     */
143    public function getContainer($container, array $params = array())
144    {
145        $endPoint = '/stories/container/' . $container;
146        return $this->sendRequest($endPoint, $params);
147    }
148
149    /**
150     * Get top stories by container
151     *
152     * @access      public
153     * @param       string      $container  Name of container (ie. Sports)
154     * @param       array       $params     Digg API arguments
155     * @throws      Services_Digg_Exception
156     */
157    public function getContainerTop($container, array $params = array())
158    {
159        $endPoint = '/stories/container/' . $container . '/top';
160        return $this->sendRequest($endPoint, $params);
161    }
162
163    /**
164     * Get hot stories by container
165     *
166     * @access      public
167     * @param       string      $container  Name of container (ie. Sports)
168     * @param       array       $params     Digg API arguments
169     * @throws      Services_Digg_Exception
170     */
171    public function getContainerHot($container, array $params = array())
172    {
173        $endPoint = '/stories/container/' . $container . '/hot';
174        return $this->sendRequest($endPoint, $params);
175    }
176
177    /**
178     * Get popular stories in a specific container
179     *
180     * @access      public
181     * @param       string      $container  Name of container (ie. Sports)
182     * @param       array       $params     Digg API arguments
183     * @throws      Services_Digg_Exception
184     */
185    public function getContainerPopular($container, array $params = array())
186    {
187        $endPoint = '/stories/container/' . $container . '/popular';
188        return $this->sendRequest($endPoint, $params);
189    }
190
191    /**
192     * Get upcoming stories in a specific container
193     *
194     * @access      public
195     * @param       string      $container  Name of container (ie. Sports)
196     * @param       array       $params     Digg API arguments
197     * @throws      Services_Digg_Exception
198     */
199    public function getContainerUpcoming($container, array $params = array())
200    {
201        $endPoint = '/stories/container/' . $container . '/upcoming';
202        return $this->sendRequest($endPoint, $params);
203    }
204
205    /**
206     * Get stories in a specific topic
207     *
208     * @access      public
209     * @param       string      $topic      Name of topic (ie. Apple)
210     * @param       array       $params     Digg API arguments
211     * @throws      Services_Digg_Exception
212     */
213    public function getTopic($topic, array $params = array())
214    {
215        $endPoint = '/stories/topic/' . $topic;
216        return $this->sendRequest($endPoint, $params);
217    }
218
219    /**
220     * Get top stories by topic
221     *
222     * @access      public
223     * @param       string      $topic      Name of topic (ie. Apple)
224     * @param       array       $params     Digg API arguments
225     * @throws      Services_Digg_Exception
226     */
227    public function getTopicTop($topic, array $params = array())
228    {
229        $endPoint = '/stories/topic/' . $topic . '/top';
230        return $this->sendRequest($endPoint, $params);
231    }
232
233    /**
234     * Get hot stories by topic
235     *
236     * @access      public
237     * @param       string      $topic      Name of topic (ie. Apple)
238     * @param       array       $params     Digg API arguments
239     * @throws      Services_Digg_Exception
240     */
241    public function getTopicHot($container, array $params = array())
242    {
243        $endPoint = '/stories/topic/' . $container . '/hot';
244        return $this->sendRequest($endPoint, $params);
245    }
246
247    /**
248     * Get popular stories in a specific topic
249     *
250     * @access      public
251     * @param       string      $topic      Name of topic (ie. Apple)
252     * @param       array       $params     Digg API arguments
253     * @throws      Services_Digg_Exception
254     */
255    public function getTopicPopular($topic, array $params = array())
256    {
257        $endPoint = '/stories/topic/' . $topic . '/popular';
258        return $this->sendRequest($endPoint, $params);
259    }
260
261    /**
262     * Get upcoming stories in a specific topic
263     *
264     * @access      public
265     * @param       string      $topic      Name of topic (ie. Apple)
266     * @param       array       $params     Digg API arguments
267     * @throws      Services_Digg_Exception
268     */
269    public function getTopicUpcoming($topic, array $params = array())
270    {
271        $endPoint = '/stories/topic/' . $topic . '/upcoming';
272        return $this->sendRequest($endPoint, $params);
273    }
274
275    /**
276     * Get popular stories' comments
277     *
278     * @access      public
279     * @param       array       $params     Digg API arguments
280     * @return      object
281     * @throws      Services_Digg_Exception
282     */
283    public function getPopularComments(array $params = array())
284    {
285        return $this->sendRequest('/stories/popular/comments', $params);
286    }
287
288    /**
289     * Get all comments on upcoming stories
290     *
291     * @access      public
292     * @param       array       $params     API arguments
293     * @return      object
294     * @throws      Services_Digg_Exception
295     */
296    public function getUpcomingComments(array $params = array())
297    {
298        return $this->sendRequest('/stories/upcoming/comments', $params);
299    }
300
301    /**
302     * Get popular stories' diggs
303     *
304     * @access      public
305     * @param       array       $params     Digg API arguments
306     * @throws      Services_Digg_Exception
307     */
308    public function getPopularDiggs(array $params = array())
309    {
310        return $this->sendRequest('/stories/popular/diggs', $params);
311    }
312
313    /**
314     * Get upcoming stories' diggs
315     *
316     * @access      public
317     * @param       array       $params     Digg API arguments
318     * @throws      Services_Digg_Exception
319     */
320    public function getUpcomingDiggs(array $params = array())
321    {
322        return $this->sendRequest('/stories/upcoming/diggs', $params);
323    }
324}
325
326?>
327