rogervila/cosmicjs-php

Based on https://github.com/cosmicjs/cosmicjs-php but with composer and OOP.

1.0.0 2016-11-12 17:52 UTC

This package is auto-updated.

Last update: 2024-12-04 18:59:27 UTC


README

Code Climate Issue Count Test Coverage TravisCI Build Status StyleCI Latest Stable Version Total Downloads Appveyor Build status

Based on https://github.com/cosmicjs/cosmicjs-php but with composer and OOP.

Install

$ composer require rogervila/cosmicjs-php

Basic setup

// Set the configuration
$config = new \Rogervila\CosmicJS\Config();

$config
    ->setBucketSlug('YOUR_BUCKET_SLUG')
    ->setWriteKey('YOUR_WRITE_KEY')
    ->setReadKey('YOUR_READ_KEY');

// Create an instance
$cosmic = new \Rogervila\CosmicJS\CosmicJS($config);

// Bucket information
$cosmic->getBucket();

// Read objects
$cosmic->getObjects();

// Read object by slug
$cosmic->getObject('OBJECT_SLUG');

// Read media
$cosmic->getMedia();

// Create an object

// object parameters
$parameters = new \Rogervila\CosmicJS\Parameters($config);
$parameters->typeSlug = 'my-object';
$parameters->title = 'My Object';

// add metafields
$meta = new \Rogervila\CosmicJS\Metafield();

$meta->key = 'field-name';
$meta->type = 'textarea';
$meta->value = 'lorem ipsum';

$parameters->metafields = [
    $meta,
];

$cosmic->addObject($parameters);

// Edit an object

// create object parameters...

$cosmic->editObject($parameters);


// Delete an object

// create object parameters...

$cosmic->editObject($parameters);

TODOS

  • More tests
  • Move from Curl to Guzzle