Skip to content

Commit

Permalink
adds getPostsBySubreddit
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycatalinismith committed Sep 3, 2011
1 parent fc0e12a commit 3d9127a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Reddit.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,33 @@ public function vote($thingId, $direction)
}
}

/**
* Returns an array of the posts in a subreddit
*
* @access public
* @param string $subredditName Plain-text name
* @return array
*/
public function getPostsBySubreddit($subredditName)
{
$verb = 'GET';
$url = "http://www.reddit.com/r/{$subredditName}.json";

$response = $this->getData($verb, $url);

$posts = array();

foreach ($response['data']['children'] as $child) {

$post = new Post($this);
$post->setData($child['data']);

$posts[] = $post;

}

return $posts;
}

}

0 comments on commit 3d9127a

Please sign in to comment.