Git Product home page Git Product logo

ghost-api-php's Introduction

ghost-api-php

Easy pulling of content from a Ghost API.

Installation

composer require guym4c/ghost-api-php

Usage

Get an instance of the API client:

$ghost = new Ghost(
    $yourGhostApiBaseUrl,
    $yourGhostApiKey,
);

You can also pass in a Doctrine Cache provider here (and configure its lifetime), and the client will cache all requests that give a single-resource answer.

Call static methods on the resource classes to get your data.

use Guym4c\GhostApiPhp\Model as Cms;

Cms\Post::bySlug($ghost, 'my-post-slug');
Cms\Tag::byId($ghost, 'my-tag-id');
Cms\Page::get()

If you don't know the slug or ID of the resource you're looking for, you can also run queries. (You'll probably want to be reading Ghost's API docs in parallel if you use this method, so that you know what the client is doing.)

Cms\Page::get(
    /* limit: */ 5,
    /* simple sorting: */ new Sort('some_value', SortOrder::DESC),
);

get() returns a CollectionRequest that exposes methods for managing pagination - you can access the returned records using getResources().

Filtering

The third parameter to the ::get method above is a Ghost NQL filter, assembled programmatically using the client. It provides fluent methods that allow you to construct complex filter expressions.

(new Filter())
    ->by('some-val', '=', 'true', true)
    ->and('another-val', '-', 'not-this')
    ->else((new Filter())
        ->by(
            'this-filter-will-be-given-brackets',
            '=',
            'which-overrides-operator-precedence',
        )
    );

with() and else() are bracket-ised versions of and() and or(). You must start with by().

We've passed an additional true at the start here to denote that the value, 'true', is a literal and should be interpreted by Ghost as a boolean, not a string.

[] in-group syntax is not supported by the client.

Refer to the Ghost docs for more information on NQL filtering.

ghost-api-php's People

Contributors

guym4c avatar

Watchers

 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.