2017 © Pedro Peláez
 

library defaqto

PHP package for interacting with the Defaqto.io API.

image

theninthnode/defaqto

PHP package for interacting with the Defaqto.io API.

  • Thursday, March 6, 2014
  • by theninthnode
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

DefaqtoIO PHP Client

DefaqtoIO PHP Client is a PHP package for using the DefaqtoIO CMS service., (*1)

Installation

Composer

Add the library to your composer.json file, (*2)

"theninthnode/defaqto": "dev-master"

Run composer install to get the latest version of the package., (*3)

Manually

It's recommended that you use Composer, however you can download and install from this repository., (*4)

Please note. This client requires the Guzzle REST PHP package., (*5)

Laravel 4

This package comes with a Service Provider and Facade for easy integration with Laravel4., (*6)

  1. Add the following entry to the providers array in config/app.php, (*7)

    'TheNinthNode\Defaqto\DefaqtoServiceProvider', (*8)

  2. Add the following entry to the aliases array in config/app.php, (*9)

    'Defaqto' => 'TheNinthNode\Defaqto\Facades\Defaqto',, (*10)

Usage

  1. Register your account at defaqto.io.
  2. Log in and create your first app by clicking the "+ Create New App" button.
  3. In your new app click "Settings" from the left menu.
  4. Take note of the the App ID and Access Token.
  5. Create a test page.

After installing the package you can use it like this:, (*11)

$pages = Defaqto::setup($app_id, $access_token)->get('pages');
var_dump($pages);

NOTE. If you get a class not found error load the class in with:, (*12)

use TheNinthNode\Defaqto\Defaqto;

OR, (*13)

$pages = TheNinthNode\Defaqto\Defaqto::setup($app_id, $access_token)->get('pages');

You can use the class with the following syntax:, (*14)

$html = Defaqto::setup($app_id, $access_token)->get('resource', array('key'=>'value'));

Where resource is one of pages, blocks, variables, blog/posts, blog/categories, blog/tags, blog/authors., (*15)

The second (optional) param is an array of key=>value pairs known as attributes. ie. array('page_slug'=>'about-us'), (*16)

Each resource has the following optional params:, (*17)

  • order - field to use for sorting
  • dir - direction to sort ASC or DESC
  • limit - limit the amount of results
  • offset - number of results to skip

There is a third optional param for use with the blog/posts resource. This is an array of resources to exclude (tags, categories, authors), (*18)

Examples

Pages

resource: pages, (*19)

Params:, (*20)

  • page_id
  • page_slug

To get all pages:, (*21)

$pages = Defaqto::setup($app_id, $access_token)->get('pages');
var_dump($pages);

To get a page by page_slug, (*22)

$page = Defaqto::setup($app_id, $access_token)->get('pages', array('page_slug'=>'about-us'));
echo $page['title'];

HTML Blocks

resource: blocks, (*23)

Params:, (*24)

  • block_id

To get all blocks:, (*25)

$blocks = Defaqto::setup($app_id, $access_token)->get('blocks');
var_dump($blocks);

To get a block by block_id, (*26)

$block = Defaqto::setup($app_id, $access_token)->get('blocks', array('block_id'=>1234));
echo $block['content'];

Variables

resource: variables, (*27)

Params:, (*28)

  • key

To get all variables:, (*29)

$variables = Defaqto::setup($app_id, $access_token)->get('variables');
var_dump($variables);

To get a variable by it's key, (*30)

$variable = Defaqto::setup($app_id, $access_token)->get('variables', array('key'=>'pricing'));
echo $variable['value'];

Blog posts

resource: blog/posts, (*31)

Params:, (*32)

  • post_id
  • post_slug
  • category_slug
  • tag_slug
  • status - draft|published (defaults to published)

To get all (published) posts:, (*33)

$posts = Defaqto::setup($app_id, $access_token)->get('blog/posts');
var_dump($posts);

To get a post by it's post_slug, (*34)

$post = Defaqto::setup($app_id, $access_token)->get('blog/posts', array('post_slug'=>'hello-world'));
echo $post['title'];

To get all posts by tag (tag_slug), (*35)

$posts = Defaqto::setup($app_id, $access_token)->get('blog/posts', array('tag_slug'=>'javascript'));
var_dump($posts);

To get all posts without their authors, tags, or categories, (*36)

$posts = Defaqto::setup($app_id, $access_token)->get('blog/posts', array(), array('authors', 'tags', 'categories'));

Blog categories

resource: blog/categories, (*37)

Params:, (*38)

  • category_id
  • category_slug

To get all categories:, (*39)

$cats = Defaqto::setup($app_id, $access_token)->get('blog/categories');
var_dump($cats);

To get a category by it's slug, (*40)

$category = Defaqto::setup($app_id, $access_token)->get('blog/categories', array('category_slug'=>'announcements'));
echo $category['name'];

Blog tags

resource: blog/tags, (*41)

Params:, (*42)

  • tag_id
  • tag_slug

To get all tags:, (*43)

$tags = Defaqto::setup($app_id, $access_token)->get('blog/tags');
var_dump($tags);

To get a tag by it's slug, (*44)

$tag = Defaqto::setup($app_id, $access_token)->get('blog/tags', array('tag_slug'=>'javascript'));
echo $tag['name'];

Blog authors

resource: blog/authors, (*45)

Params:, (*46)

  • author_id
  • username

To get all authors:, (*47)

$authors = Defaqto::setup($app_id, $access_token)->get('blog/authors');
var_dump($authors);

To get an author by their username, (*48)

$author = Defaqto::setup($app_id, $access_token)->get('blog/authors', array('username'=>'jonesy'));
echo $author['bio'];

The Versions

06/03 2014

dev-master

9999999-dev

PHP package for interacting with the Defaqto.io API.

  Sources   Download

The Requires

 

by Billy Jones