├── .gitignore ├── example.php ├── README.md ├── cosmicjs.php └── curl.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | bucket_slug = "driver-example"; // bucket slug 7 | $config->read_key = ""; // leave empty if not required 8 | $config->write_key = ""; // leave empty if not required 9 | 10 | $config->url = "https://api.cosmicjs.com/v1/" . $config->bucket_slug; 11 | $config->objects_url = $config->url . "/objects"; 12 | $config->media_url = $config->url . "/media"; 13 | $config->add_object_url = $config->url . "/add-object"; 14 | $config->edit_object_url = $config->url . "/edit-object"; 15 | $config->delete_object_url = $config->url . "/delete-object"; 16 | 17 | include("cosmicjs.php"); 18 | 19 | /* Get Objects 20 | ================================= */ 21 | $objects = $cosmicjs->getObjects(); 22 | 23 | var_dump($objects); 24 | 25 | ?> 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Cosmic JS Logo](https://cosmicjs.com/images/marketing/logo-w-brand.jpg)](https://cosmicjs.com/) 2 | === 3 | 4 | ### Getting started 5 | Go to [https://cosmicjs.com](https://cosmicjs.com), create an account and setup a bucket. 6 | 7 | ### Install 8 | ``` 9 | git clone https://github.com/cosmicjs/cosmicjs-php 10 | ``` 11 | ### Usage 12 | ```php 13 | bucket_slug = "driver-example"; // bucket slug 18 | $config->read_key = ""; // leave empty if not required 19 | $config->write_key = ""; // leave empty if not required 20 | include("cosmicjs.php"); 21 | 22 | /* Add 23 | ================================= */ 24 | $object_string = '{ 25 | "type_slug": "pages", 26 | "title": "Test Title", 27 | "content": "here is some test content", 28 | "write_key": "' . $config->write_key . '" 29 | }'; 30 | $object = $cosmicjs->addObject($object_string); 31 | 32 | /* Edit 33 | ================================= */ 34 | $object_string = '{ 35 | "slug": "test-title", 36 | "title": "New Title", 37 | "content": "here is some NEW test content", 38 | "write_key": "' . $config->write_key . '" 39 | }'; 40 | $object = $cosmicjs->editObject($object_string); 41 | 42 | /* Delete 43 | ================================= */ 44 | $object_string = '{ 45 | "slug": "test-title", 46 | "write_key": "' . $config->write_key . '" 47 | }'; 48 | $object = $cosmicjs->deleteObject($object_string); 49 | 50 | /* Get Objects 51 | ================================= */ 52 | $objects = $cosmicjs->getObjects(); 53 | 54 | /* Get Media 55 | ================================= */ 56 | $media = $cosmicjs->getMedia(); 57 | ?> 58 | ``` 59 | -------------------------------------------------------------------------------- /cosmicjs.php: -------------------------------------------------------------------------------- 1 | curl = $curl; 9 | $this->config = $config; 10 | $this->config->bucket_slug = $config->bucket_slug; 11 | $this->config->object_slug = $config->object_slug; 12 | $this->config->read_key = $config->read_key; 13 | $this->config->write_key = $config->write_key; 14 | $this->config->url = "https://api.cosmicjs.com/v1/" . $this->config->bucket_slug; 15 | $this->config->objects_url = $this->config->url . "/objects?read_key=" . $this->config->read_key; 16 | $this->config->object_url = $this->config->url . "/object/" . $this->config->object_slug . "?read_key=" . $this->config->read_key; 17 | $this->config->media_url = $this->config->url . "/media?read_key=" . $this->config->read_key; 18 | $this->config->add_object_url = $this->config->url . "/add-object?write_key=" . $this->config->write_key; 19 | $this->config->edit_object_url = $this->config->url . "/edit-object?write_key=" . $this->config->write_key; 20 | $this->config->delete_object_url = $this->config->url . "/delete-object?write_key=" . $this->config->write_key; 21 | } 22 | // Get all objects 23 | public function getObjects(){ 24 | $data = json_decode($this->curl->get($this->config->objects_url)); 25 | return $data; 26 | } 27 | // Get all object 28 | public function getObject(){ 29 | $data = json_decode($this->curl->get($this->config->object_url)); 30 | return $data; 31 | } 32 | // Get media 33 | public function getMedia(){ 34 | $data = json_decode($this->curl->get($this->config->media_url)); 35 | return $data->media; 36 | } 37 | // Add object 38 | public function addObject($params){ 39 | $data = $this->curl->post($this->config->add_object_url, $params); 40 | return $data; 41 | } 42 | // Edit object 43 | public function editObject($params){ 44 | $data = $this->curl->put($this->config->edit_object_url, $params); 45 | return $data; 46 | } 47 | // Delete object 48 | public function deleteObject($params){ 49 | $data = $this->curl->delete($this->config->delete_object_url, $params); 50 | return $data; 51 | } 52 | } 53 | $cosmicjs = new CosmicJS; -------------------------------------------------------------------------------- /curl.php: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------