@@ -16,8 +16,8 @@ class CountryService extends AbstractService
16
16
public function all (array $ params = array ())
17
17
{
18
18
$ endpoint = '/admin/countries.json ' ;
19
- $ request = $ this ->createRequest ($ endpoint );
20
- return $ this ->getEdge ( $ request , $ params , Country::class);
19
+ $ response = $ this ->request ($ endpoint, ' GET ' , $ params );
20
+ return $ this ->createCollection ( Country::class, $ response [ ' countries ' ] );
21
21
}
22
22
23
23
/**
@@ -29,23 +29,27 @@ public function all(array $params = array())
29
29
public function count ()
30
30
{
31
31
$ endpoint = '/admin/countries/count.json ' ;
32
- $ request = $ this ->createRequest ($ endpoint );
33
- return $ this -> getCount ( $ request ) ;
32
+ $ response = $ this ->request ($ endpoint, ' GET ' );
33
+ return $ response [ ' count ' ] ;
34
34
}
35
35
36
36
/**
37
37
* Receive a single country
38
38
*
39
39
* @link https://help.shopify.com/api/reference/country#show
40
40
* @param integer $countryId
41
- * @param array $params
41
+ * @param array $fields
42
42
* @return Country
43
43
*/
44
- public function get ($ countryId , array $ params = array ())
44
+ public function get ($ countryId , array $ fields = array ())
45
45
{
46
- $ endpoint = '/admin/countries/ ' .$ countryId .'.json ' ;
47
- $ request = $ this ->createRequest ($ endpoint );
48
- return $ this ->getNode ($ request , $ params , Country::class);
46
+ $ params = array ();
47
+ if (!empty ($ fields )) {
48
+ $ params ['fields ' ] = implode (', ' , $ fields );
49
+ }
50
+ $ endpoint = '/admin/countrys/ ' .$ countryId .'.json ' ;
51
+ $ response = $ this ->request ($ endpoint , 'GET ' , $ params );
52
+ return $ this ->createObject (Country::class, $ response ['country ' ]);
49
53
}
50
54
51
55
/**
@@ -59,13 +63,10 @@ public function create(Country &$country)
59
63
{
60
64
$ data = $ country ->exportData ();
61
65
$ endpoint = '/admin/countries.json ' ;
62
- $ request = $ this ->createRequest ($ endpoint , static ::REQUEST_METHOD_POST );
63
- $ response = $ this ->send (
64
- $ request , array (
66
+ $ response = $ this ->request ($ endpoint , 'POST ' , array (
65
67
'country ' => $ data
66
- )
67
- );
68
- $ country ->setData ($ response ->country );
68
+ ));
69
+ $ country ->setData ($ response ['country ' ]);
69
70
}
70
71
71
72
/**
@@ -78,14 +79,11 @@ public function create(Country &$country)
78
79
public function update (Country &$ country )
79
80
{
80
81
$ data = $ country ->exportData ();
81
- $ endpoint = '/admin/countries/ ' .$ country ->getId ().'.json ' ;
82
- $ request = $ this ->createRequest ($ endpoint , static ::REQUEST_METHOD_PUT );
83
- $ response = $ this ->send (
84
- $ request , array (
82
+ $ endpoint = '/admin/countries/ ' .$ country ->id .'.json ' ;
83
+ $ response = $ this ->request ($ endpoint , 'PUT ' , array (
85
84
'country ' => $ data
86
- )
87
- );
88
- $ country ->setData ($ response ->country );
85
+ ));
86
+ $ country ->setData ($ response ['country ' ]);
89
87
}
90
88
91
89
/**
@@ -97,9 +95,6 @@ public function update(Country &$country)
97
95
*/
98
96
public function delete (Country $ country )
99
97
{
100
- $ endpoint = '/admin/countries/ ' .$ country ->getId ().'.json ' ;
101
- $ request = $ this ->createRequest ($ endpoint , static ::REQUEST_METHOD_DELETE );
102
- $ response = $ this ->send ($ request );
103
- return ;
98
+ return $ this ->request ('/admin/countries/ ' .$ country ->id .'.json ' , 'DELETE ' );
104
99
}
105
100
}
0 commit comments