Skip to content

Commit cd03f5e

Browse files
authored
Merge pull request #144 from netglue/readme-update
Add some docs to the readme
2 parents 40d6433 + b012f85 commit cd03f5e

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

README.md

+56-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
This library provides an API client so that you can read and write your document type definitions using the [Prismic Custom Types API](https://prismic.io/docs/technologies/custom-types-api).
1414

15-
Currently, you can list, read, insert and update document types.
15+
Currently, you can list, read, insert and update document types, and do the same for 'Shared Slices'
1616

17-
The client requires that you make use of _(And similarly, it returns instances of)_ the shipped `Definition` value object.
17+
The client requires that you make use of _(And similarly, it returns instances of)_ the shipped `Definition` or `SharedSlice` value objects.
1818

1919
Typically, you wouldn't interact with the client directly, but as part of a build process that takes care of all that stuff for you. This client is quite fresh, but it's primary use will soon be part of [`netglue/prismic-cli`](https://github.com/netglue/prismic-cli), so that it will become trivial to synchronise your local development document definitions with those in your production Prismic repository _(and vice-versa)_.
2020

21+
It's worth noting that document types and slices are not validated in any way. That's up to you, but, you should get descriptive exceptions when your JSON doesn't validate on the remote server.
22+
2123
## Installation
2224

2325
The only supported installation method is via composer:
@@ -44,16 +46,64 @@ $client = new BaseClient(
4446
)
4547
```
4648

49+
## Usage
50+
51+
### CRUD for Document Types
52+
53+
```php
54+
use Prismic\DocumentType\Client;
55+
use Prismic\DocumentType\Definition;
56+
57+
assert($client instanceof Client);
58+
59+
// Insert or update a document type:
60+
$client->saveDefinition(Definition::new(
61+
id: 'my-type',
62+
label: 'Some Label',
63+
repeatable: true,
64+
active: true,
65+
json: $someJsonPayloadAsAString,
66+
));
67+
68+
// Fetch all remote document type defs
69+
$client->fetchAllDefinitions();
70+
71+
// Fetch a single definition
72+
$client->getDefinition('some-type');
73+
74+
// Delete a document type definition
75+
$client->deleteDefinition('some-type');
76+
```
77+
78+
### CRUD for Shared Slices
79+
80+
```php
81+
use Prismic\DocumentType\SharedSlice;use Prismic\DocumentType\SharedSliceManagementClient;
82+
83+
assert($client instanceof SharedSliceManagementClient);
84+
85+
// Insert or update a slice def:
86+
$client->saveSharedSlice(SharedSlice::new(
87+
id: 'some-slice-id',
88+
json: $someJsonPayloadAsAString,
89+
));
90+
91+
// Fetch all slice defs:
92+
$client->fetchAllSharedSlices();
93+
94+
// Fetch one slice def:
95+
$client->getSharedSlice('whatever');
96+
97+
// Delete a shared slice:
98+
$client->deleteSharedSlice('some-id');
99+
```
100+
47101
## Limitations/Roadmap
48102

49103
### Authentication
50104

51105
Currently, authentication is only possible with a [permanent access token](https://prismic.io/docs/technologies/custom-types-api#permanent-token-recommended) that you create/retrieve from the Prismic repository settings. Session based tokens are not supported.
52106

53-
### Slices
54-
55-
CRUD operations on shared slices are not yet implemented but are planned for future development. If you really want this feature, you're welcome to contribute.
56-
57107
## Contributing
58108

59109
Please feel free to get involved with development. The project uses PHPUnit for tests, [Psalm](https://psalm.dev) for static analysis and [Infection](https://infection.github.io) for mutation testing. CI should have your back if you want to submit a feature or fix ;)

0 commit comments

Comments
 (0)