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