Giter Site home page Giter Site logo

emmapraise / applenewsapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chapter-three/applenewsapi

0.0 0.0 0.0 1.83 MB

This is a PHP library that allows you to publish content to Apple News and construct documents in the Apple News JSON format.

License: MIT License

PHP 100.00%

applenewsapi's Introduction

AppleNewsAPI

Travis CI build status

AppleNewsAPI\PublisherAPI is a PHP library that allows you to publish content to Apple News. You can also retrieve and delete articles you’ve already published, and get basic information about your channel and sections.

AppleNewsAPI\Document is a PHP library that helps construct documents in the Apple News JSON format.

API Documentation

Installation

composer require chapter-three/apple-news-api

or

git clone [email protected]:chapter-three/AppleNewsAPI.git
cd AppleNewsAPI
curl -sS https://getcomposer.org/installer | php
./composer.phar install

Document class Quick Start and Examples

use ChapterThree\AppleNewsAPI\Document;
use ChapterThree\AppleNewsAPI\Document\Components\Body;
use ChapterThree\AppleNewsAPI\Document\Layouts\Layout;
use ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle;

$obj = new Document(uniqid(), 'title', 'en', new Layout(7, 1024));
$obj->addComponent(new Body('body text'))
  ->addComponentTextStyle('default', new ComponentTextStyle());

$json = $obj->json();

PublisherAPI class Quick Start and Examples

$api_key_id = "";
$api_key_secret = "";
$endpoint = "https://endpoint_url";

$PublisherAPI = new ChapterThree\AppleNewsAPI\PublisherAPI(
  $api_key_id,
  $api_key_secret,
  $endpoint
);
GET Channel
// Fetches information about a channel.
$response = $PublisherAPI->get('/channels/{channel_id}',
  [
    'channel_id' => CHANNEL_ID
  ]
);
GET Sections
// Fetches a list of all sections for a channel.
$response = $PublisherAPI->get('/channels/{channel_id}/sections',
  [
    'channel_id' => CHANNEL_ID
  ]
);
GET Section
// Fetches information about a single section.
$response = $PublisherAPI->get('/sections/{section_id}',
  [
    'section_id' => SECTION_ID
  ]
);
GET Article
// Fetches an article.
$response = $PublisherAPI->get('/articles/{article_id}',
  [
    'article_id' => ARTICLE_ID
  ]
);
POST Article
// Publishes a new article to a channel.
// $response contains an article ID and revision ID.
$response = $PublisherAPI->post('/channels/{channel_id}/articles',
  [
    'channel_id' => CHANNEL_ID
  ],
  [
    // List of files to POST
    'files' => [], // optional. A list of article assets [uri => path]
    // JSON metadata string
    'metadata' => $metadata, // required
    'json' => '', // required. Apple News Native formatted JSON string.
  ]
);
UPDATE Article
// Metadata information `revision` is required.
$metadata = json_encode([
  'data' => [
    'revision' => REVISION_ID
  ]
]);
// Updates an existing article.
// See $response variable to get a new revision ID.
$response = $PublisherAPI->post('/articles/{article_id}',
  [
    'article_id' => ARTICLE_ID
  ],
  [
    // List of files to POST
    'files' => [], // optional. A list of article assets [uri => path]
    // JSON metadata string
    'metadata' => $metadata, // required
    // Apple News Native formatted JSON string. See examples.
    'json' => '', // required.
  ]
);
DELETE Article
// Deletes an article.
$response = $PublisherAPI->delete('/articles/{article_id}',
  [
    'article_id' => ARTICLE_ID
  ]
);

Contribute

Run Unit Tests

./vendor/bin/phpunit -v --colors=auto --bootstrap vendor/autoload.php tests

To test PublisherAPI GET/POST/DELETE methods use the following pattern:

./vendor/bin/phpunit -v --colors=auto --bootstrap vendor/autoload.php
tests/PublisherAPITest.php [API_KEY] [API_SECRET] [ENDPOINT_URL] [METHOD] [ENDPOINT_PATH]

Generate PHPDoc

git clone --branch gh-pages [email protected]:chapter-three/AppleNewsAPI.git ../AppleNewsAPI_phpdoc
./vendor/bin/phpdoc run --title='chapter-three/apple-news-api v'$(cat composer.json | jq -r '.version') -d ./ -i vendor/,tests/ -t ../AppleNewsAPI_phpdoc

applenewsapi's People

Contributors

m4olivei avatar minnur avatar moonray avatar scottfalkingham avatar tbfisher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.