2017 © Pedro Peláez
 

library open-platform-php

PHP library for utzlizing the The Guardian Newspaper's Open Platform

image

t14/open-platform-php

PHP library for utzlizing the The Guardian Newspaper's Open Platform

  • Wednesday, November 11, 2015
  • by t14
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Master Build Status Dev Build Status, (*1)

Guardian Open Platform PHP Client

This is a PHP based client library that aims to provide an easy to use option for consuming The Guardian NewsPapers Open Platform API., (*2)

Before you get started

Before you get started you need to get an api key which you can obtain here, (*3)

Installation

Using composer composer require t14/open-platform-php Create a config.yml file like the one below and add your api key., (*4)

# Open Platform Config
- host:
  - 'http://content.guardianapis.com'
- apiKey:
  - 'YOUR API KEY HERE'

Basic Usage

Edit the config.yml file and replace the api key with your own. You can choose to use a different YAML config file (see the config section below), (*5)

require 'vendor/autoload.php';
use OpenPlatform\Client;

$op = new Client('DIR_OF_CONFIG_FILE/config.yml');

$op->endpoint('search')
   ->filter('politics', 'section')
   ->filter('newest', 'order-by')
   ->searchQuery('latest election news')
   ->getContent()->getBody();

The getContent() returns a Guzzle client object making it possible to chain a different method other than getBody() See Guzzle documentation for more information, (*6)

The searchQuery('my free text search') method allows you to add a free text search to your query. You also have the option to specify filters and use different endpoints., (*7)

Endpoints

You can query a different endpoint by passing the name of the endpoint as a parameter to the endpoint('nameOfEndpoint') method. For example to query the sections endpoint you could do the following, (*8)

$op->endpoint('sections')
   ->searchQuery('business')
   ->getContent()->getBody();

Filters

You can chain the filter method to the endpoint method and then to its self allowing you to set multiple filters. Each endpoint supports certain filters and an exception will be thrown if you try to use an incompatible filter to to check which filters are supported by which endpoint you can use the content explorer, (*9)

The filter method takes a query as its first parameter and the name of the filter you want to use as its second parameter. For example if you would like to use the 'search' endpoint and filter your results to only show a single page, ordered by the most recent from the 'politics' section you could do the following;, (*10)

$op->endpoint('search')
    ->filter('politics', 'section')
    ->filter('newest', 'order-by')
    ->filter(1, 'page')
    ->getContent()->getBody();

Useful resources

This library is largely based on the Open Platform content explorer. You can use it to help you find out which filters are compatible with which endpoints, see what kind of results your queries return and more. open-platform.theguardian.com, (*11)

Contributing

Please feel free to fork this repo and open a pull request., (*12)

The Versions

11/11 2015

dev-sample

dev-sample

PHP library for utzlizing the The Guardian Newspaper's Open Platform

  Sources   Download

GPL

The Requires

 

The Development Requires

by Temi Jegede

openplatform

06/11 2015

dev-dev

dev-dev

PHP library for utzlizing the The Guardian Newspaper's Open Platform

  Sources   Download

GPL

The Requires

 

The Development Requires

by Temi Jegede

openplatform

05/07 2015

dev-master

9999999-dev

PHP library for utzlizing the The Guardian Newspaper's Open Platform

  Sources   Download

GPL

The Requires

 

The Development Requires

by Temi Jegede

openplatform

04/07 2015

0.1

0.1.0.0

PHP library for utzlizing the The Guardian Newspaper's Open Platform

  Sources   Download

GPL

The Requires

 

The Development Requires

by Temi Jegede

openplatform