mgerarts/hn-api-php

A PHP wrapper for the Hacker news API, using Guzzle

v1.0.2 2017-05-28 07:59 UTC

This package is auto-updated.

Last update: 2024-11-08 23:32:25 UTC


README

A HN Api client wrapper for PHP, built to experiment with Guzzle services.

Installation

The package is available through composer:

$ composer require mgerarts/hn-api-php

Usage

The client is a wrapper around a Guzzle service definition. It can be instantiated like this:

<?php

use HackerNewsApi\Service\HackerNewsServiceClient;
use HackerNewsApi\Client\HackerNewsClient;

$client = new HackerNewsClient(HackerNewsServiceClient::create());

You can then start making requests:

<?php

$client->getItem(8863);

// Will return:
// HackerNewsApi\Models\Item {#70
//   -id: 8863
//   -deleted: false
//   -type: "story"
//   -by: "dhouston"
//   -time: 1175714200
//   -text: null
//   -dead: false
//   -parent: null
//   -poll: null
//   -kids: array:33 [..]
//   -url: "http://www.getdropbox.com/u/2/screencast.html"
//   -score: 111
//   -title: "My YC app: Dropbox - Throw away your USB drive"
//   -parts: []
//   -descendants: 71
// }

A full list of available methods can be found here.