1
|
|
|
<?php |
2
|
|
|
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint; |
3
|
|
|
|
4
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams; |
5
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson; |
6
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson; |
7
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource; |
8
|
|
|
|
9
|
|
|
class BlogEndpoint extends AbstractEndpoint |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param array $query |
13
|
|
|
* @return array|GenericResource[] |
14
|
|
|
*/ |
15
|
|
|
public function findAll(array $query = array()) |
16
|
|
|
{ |
17
|
|
|
$request = new GetJson('/admin/blogs.json', $query); |
18
|
|
|
$response = $this->send($request); |
19
|
|
|
return $this->createCollection($response->get('blogs')); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return int |
24
|
|
|
*/ |
25
|
|
|
public function countAll() |
26
|
|
|
{ |
27
|
|
|
$request = new GetJson('/admin/blogs/count.json'); |
28
|
|
|
$response = $this->send($request); |
29
|
|
|
return $response->get('count'); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param int $blogId |
34
|
|
|
* @param array $fields |
35
|
|
|
* @return GenericResource |
36
|
|
|
*/ |
37
|
|
|
public function findOne($blogId, array $fields = array()) |
38
|
|
|
{ |
39
|
|
|
$params = $fields ? array('fields' => $fields) : array(); |
40
|
|
|
$request = new GetJson('/admin/blogs/' . $blogId . '.json', $params); |
41
|
|
|
$response = $this->send($request); |
42
|
|
|
return $this->createEntity($response->get('blog')); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param GenericResource $blog |
47
|
|
|
* @return GenericResource |
48
|
|
|
*/ |
49
|
|
|
public function create(GenericResource $blog) |
50
|
|
|
{ |
51
|
|
|
$request = new PostJson('/admin/blogs.json', array('blog' => $blog->toArray())); |
52
|
|
|
$response = $this->send($request); |
53
|
|
|
return $this->createEntity($response->get('blog')); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $blogId |
58
|
|
|
* @param GenericResource $blog |
59
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
60
|
|
|
*/ |
61
|
|
|
public function update($blogId, GenericResource $blog) |
62
|
|
|
{ |
63
|
|
|
$request = new PostJson('/admin/blogs/' . $blogId . '.json', array('blog' => $blog->toArray())); |
64
|
|
|
$response = $this->send($request); |
65
|
|
|
return $this->createEntity($response->get('blog')); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int $blogId |
70
|
|
|
*/ |
71
|
|
|
public function delete($blogId) |
72
|
|
|
{ |
73
|
|
|
$request = new DeleteParams('/admin/blogs/' . $blogId . '.json'); |
74
|
|
|
$this->send($request); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|