urbania/apple-news

dev-master 2019-03-25 22:45 UTC

This package is auto-updated.

Last update: 2024-04-25 14:52:23 UTC


README

This package offer a wrapper around the Apple News API and Apple News Format in PHP. It includes support for Laravel, Wordpress and an HTML parser.

Packagist Travis (.org) branch Coveralls github

Installation

composer require urbania/apple-news

Laravel

Versions prior to 5.5

  1. Add the Service Provider in the config file config/app.php:
'providers' => [
    // ...
    \Urbania\AppleNews\Laravel\AppleNewsServiceProvider::class,
    // ...
]
  1. Add the Facade in the config file config/app.php:
'facades' => [
    // ...
    'AppleNews' => \Urbania\AppleNews\Laravel\AppleNewsFacade::class,
    // ...
]

All versions

Publish the config file to config/apple-news.php:

php artisan vendor:publish

Usage

Pure PHP

Create a test article:

require __DIR__ . '/vendor/autoload.php';

use Urbania\AppleNews\Article;

$article = new Article([
    'identifier' => 'test-article',
    'language' => 'en-US',
    'version' => '1.7',
    'layout' => [
        'columns' => 12,
        'width' => 1024
    ],
    'title' => 'An article',
    'components' => [
        [
            'role' => 'title',
            'text' => 'This is a title'
        ],
        [
            'role' => 'body',
            'text' => 'This is a body'
        ]
    ]
]);

echo $article->toJson();

Laravel

Create a test article: (when creating an article with the facade or the helper, it takes into account the default article values found in config/apple-news.php)

// Using the facade
use AppleNews;

$article = AppleNews::article([
    'identifier' => 'test-article',
    'title' => 'An article',
    'components' => [
        [
            'role' => 'title',
            'text' => 'This is a title'
        ],
        [
            'role' => 'body',
            'text' => 'This is a body'
        ]
    ]
]);

// Using the helper
$article = article([
    // ... same as above
]);

echo $article->toJson();