Skip to content

Commit bfffd7f

Browse files
committed
✏️ Added Usage and DTO showcase
1 parent efbee8c commit bfffd7f

File tree

1 file changed

+220
-2
lines changed

1 file changed

+220
-2
lines changed

README.md

Lines changed: 220 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,230 @@ can create your token. Be sure to activate all rights you need.
4747

4848
👉 Make sure to activate **HTTP Token Authentication** in your system settings.
4949

50-
## 🏗 Usage (WIP)
50+
## 🏗 Usage
51+
52+
### 👶 User Resource
53+
54+
```php
55+
use CodebarAg\Zammad\Facades\Zammad;
56+
57+
/**
58+
* Get the current authenticated user.
59+
*/
60+
$user = Zammad::user()->me();
61+
62+
/**
63+
* Show a list of users.
64+
*/
65+
$users = Zammad::user()->list();
66+
67+
/**
68+
* Search a single user.
69+
*/
70+
$term = 'email:[email protected]';
71+
72+
$user = Zammad::user()->search($term);
73+
74+
/**
75+
* Show a user by id.
76+
*/
77+
$user = Zammad::user()->show(20);
78+
79+
/**
80+
* Create a new user.
81+
*/
82+
$data = [
83+
'firstname' => 'Bob',
84+
'email' => '[email protected]',
85+
];
86+
87+
$user = (new Zammad())->user()->create($data);
88+
89+
/**
90+
* Delete a user by id.
91+
*/
92+
(new Zammad())->user()->delete(20);
93+
94+
/**
95+
* Search a user by email. If not found create a new user.
96+
*/
97+
$user = (new Zammad())->user()->searchOrCreateByEmail('[email protected]');
98+
```
99+
100+
### 🎫 Ticket Resource
101+
102+
```php
103+
use CodebarAg\Zammad\Facades\Zammad;
104+
105+
/**
106+
* Show a list of tickets.
107+
*/
108+
$tickets = Zammad::ticket()->list();
109+
110+
/**
111+
* Search tickets which include following term.
112+
*/
113+
$term = 'bob';
114+
115+
$tickets = Zammad::ticket()->search($term);
116+
117+
/**
118+
* Show a ticket by id.
119+
*/
120+
$ticket = Zammad::ticket()->show(20);
121+
122+
/**
123+
* Create a new ticket.
124+
*/
125+
$data = [
126+
'title' => 'The application is not working',
127+
'group' => 'Inbox',
128+
'customer' => '[email protected]',
129+
'article' => [
130+
'body' => 'It just crashes if I visit the page',
131+
'type' => 'note',
132+
'internal' => false,
133+
],
134+
];
135+
136+
$ticket = (new Zammad())->ticket()->create($data);
137+
138+
/**
139+
* Delete a ticket by id.
140+
*/
141+
(new Zammad())->user()->delete(20);
142+
```
143+
144+
### 💬 Comment Resource
51145

52146
```php
53147
use CodebarAg\Zammad\Facades\Zammad;
54148

55-
//
149+
/**
150+
* Show comments by ticket id
151+
*/
152+
$comments = Zammad::comment()->showByTicket(20);
153+
154+
/**
155+
* Show a comment by id.
156+
*/
157+
$comment = Zammad::comment()->show(20);
158+
159+
/**
160+
* Create a new comment.
161+
*/
162+
$data = [
163+
'ticket_id' => 42,
164+
'subject' => 'Login still not working',
165+
'body' => 'Somehow the login is not working<br>Could you check that?',
166+
'content_type' => 'text/html',
167+
'attachments' => [
168+
[
169+
'filename' => 'log.txt',
170+
'data' => 'RHUgYmlzdCBlaW4g8J+OgSBmw7xyIGRpZSDwn4yN',
171+
'mime-type' => 'text/plain',
172+
],
173+
],
174+
];
175+
176+
$comment = (new Zammad())->comment()->create($data);
177+
178+
/**
179+
* Delete a comment by id.
180+
*/
181+
(new Zammad())->comment()->delete(20);
182+
```
183+
184+
### 🏠 Object Resource
185+
186+
```php
187+
use CodebarAg\Zammad\Facades\Zammad;
188+
189+
/**
190+
* Show a list of objects.
191+
*/
192+
$objects = Zammad::object()->list();
193+
194+
/**
195+
* Show a object by id.
196+
*/
197+
$object = Zammad::object()->show(20);
198+
199+
/**
200+
* Execute database migrations
201+
*/
202+
(new Zammad())->object()->executeMigrations();
203+
```
204+
205+
### 🧷 Attachment Resource
206+
207+
```php
208+
use CodebarAg\Zammad\Facades\Zammad;
209+
210+
/**
211+
* Download attachment.
212+
*/
213+
$content = Zammad::attachment()->download(
214+
ticketId: 32,
215+
commentId: 111,
216+
attachmentId: 42,
217+
);
218+
```
219+
220+
## 🏋️ DTO showcase
221+
222+
```php
223+
CodebarAg\Zammad\DTO\User {
224+
+id: 20 // int
225+
+first_name: "Bob" // string
226+
+last_name: "Schweizer" // string
227+
+login: "[email protected]" // string
228+
+email: "[email protected]" // string
229+
+last_login_at: Carbon\Carbon // Carbon
230+
+updated_at: Carbon\Carbon // Carbon
231+
+created_at: Carbon\Carbon // Carbon
232+
```
233+
234+
```php
235+
CodebarAg\Zammad\DTO\Ticket {
236+
+id: 32 // int
237+
+number: 69032 // int
238+
+user_id: 20 // int
239+
+group_id: 3 // int
240+
+state_id: 1 // int
241+
+subject: "Login is not working" // string
242+
+comments_count: 3 // int
243+
+updated_at: Carbon\Carbon // Carbon
244+
+created_at: Carbon\Carbon // Carbon
245+
}
246+
```
247+
248+
```php
249+
CodebarAg\Zammad\DTO\Comment {
250+
+id: 66 // int
251+
+type_id: 10 // int
252+
+ticket_id: 32 // int
253+
+subject: "App Subject" // string
254+
+body: "Something is wrong" // string
255+
+content_type: "text/plain" // string
256+
+from: "Bob Schweizer" // string
257+
+to: null // ?string
258+
+internal: false // boolean
259+
+created_by_id: 20 // int
260+
+updated_by_id: 20 // int
261+
+attachments: Illuminate\Support\Collection // Collection|Attachment[]
262+
+updated_at: Carbon\Carbon // Carbon
263+
+created_at: Carbon\Carbon // Carbon
264+
}
265+
```
266+
267+
```php
268+
CodebarAg\Zammad\DTO\Attachment {
269+
+id: 313 // int
270+
+size: 30 // int
271+
+name: "log.txt" // string
272+
+type: "text/plain" // string
273+
}
56274
```
57275

58276
## 🔧 Configuration file

0 commit comments

Comments
 (0)