Skip to content

Commit 497879a

Browse files
author
Rob Wittman
committed
Stashing
1 parent 6049699 commit 497879a

File tree

3 files changed

+41
-48
lines changed

3 files changed

+41
-48
lines changed

lib/Service/CountryService.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class CountryService extends AbstractService
1616
public function all(array $params = array())
1717
{
1818
$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']);
2121
}
2222

2323
/**
@@ -29,23 +29,27 @@ public function all(array $params = array())
2929
public function count()
3030
{
3131
$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'];
3434
}
3535

3636
/**
3737
* Receive a single country
3838
*
3939
* @link https://help.shopify.com/api/reference/country#show
4040
* @param integer $countryId
41-
* @param array $params
41+
* @param array $fields
4242
* @return Country
4343
*/
44-
public function get($countryId, array $params = array())
44+
public function get($countryId, array $fields = array())
4545
{
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']);
4953
}
5054

5155
/**
@@ -59,13 +63,10 @@ public function create(Country &$country)
5963
{
6064
$data = $country->exportData();
6165
$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(
6567
'country' => $data
66-
)
67-
);
68-
$country->setData($response->country);
68+
));
69+
$country->setData($response['country']);
6970
}
7071

7172
/**
@@ -78,14 +79,11 @@ public function create(Country &$country)
7879
public function update(Country &$country)
7980
{
8081
$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(
8584
'country' => $data
86-
)
87-
);
88-
$country->setData($response->country);
85+
));
86+
$country->setData($response['country']);
8987
}
9088

9189
/**
@@ -97,9 +95,6 @@ public function update(Country &$country)
9795
*/
9896
public function delete(Country $country)
9997
{
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');
10499
}
105100
}

lib/Service/CustomCollectionService.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class CustomCollectionService extends AbstractService
1616
public function all(array $params = array())
1717
{
1818
$endpoint = '/admin/custom_collections.json';
19-
$request = $this->createRequest($endpoint);
20-
return $this->getEdge($request, $params, CustomCollection::class);
19+
$response = $this->request($endpoint, 'GET', $params);
20+
return $this->createCollection(CustomCollection::class, $response['custom_collections']);
2121
}
2222

2323
/**
@@ -30,23 +30,27 @@ public function all(array $params = array())
3030
public function count(array $params = array())
3131
{
3232
$endpoint = '/admin/custom_collections/count.json';
33-
$request = $this->createRequest($endpoint);
34-
return $this->getCount($request, $options);
33+
$response = $this->request($endpoint, 'GET', $params);
34+
return $response['count'];
3535
}
3636

3737
/**
3838
* Receive a single custom collection
3939
*
4040
* @link https://help.shopify.com/api/reference/customcollection#show
4141
* @param integer $customCollectionId
42-
* @param array $params
42+
* @param array $fields
4343
* @return CustomCollection
4444
*/
45-
public function get($customCollectionId, array $params = array())
45+
public function get($customCollectionId, array $fields = array())
4646
{
47+
$params = array();
48+
if (!empty($fields)) {
49+
$params['fields'] = $fields;
50+
}
4751
$endpoint = '/admin/custom_collections/'.$customCollectionId.'.json';
48-
$request = $this->createRequest($endpoint);
49-
return $this->getNode($request, $params, CustomCollection::class);
52+
$response = $this->request($endpoint, 'GET', $params);
53+
return $this->createObject(CustomCollection::class, $response['custom_collection']);
5054
}
5155

5256
/**
@@ -60,13 +64,10 @@ public function create(CustomCollection &$customCollection)
6064
{
6165
$data = $customCollection->exportData();
6266
$endpoint = '/admin/custom_collections.json';
63-
$request = $this->createRequest($endpoint, static::REQUEST_METHOD_POST);
64-
$response = $this->send(
65-
$request, array(
67+
$response = $this->request($endpoint, 'POST', array(
6668
'custom_collection' => $data
67-
)
68-
);
69-
$customCollection->setData($response->custom_collection);
69+
));
70+
$customCollection->setData($response['custom_collection']);
7071
}
7172

7273
/**
@@ -79,14 +80,11 @@ public function create(CustomCollection &$customCollection)
7980
public function update(CustomCollection &$customCollection)
8081
{
8182
$data = $customCollection->exportData();
82-
$endpoint = '/admin/custom_collections/'.$customCollection->getId().'.json';
83-
$request = $this->createRequest($endpoint, static::REQUEST_METHOD_PUT);
84-
$response = $this->send(
85-
$request, array(
83+
$endpoint = '/admin/custom_collections/'.$customCollection->id.'.json';
84+
$response = $this->request($endpoint, 'PUT', array(
8685
'custom_collection' => $data
87-
)
88-
);
89-
$customCollection->setData($response->custom_collection);
86+
));
87+
$customCollection->setData($response['custom_collection']);
9088
}
9189

9290
/**

lib/Service/ProductService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function create(Product &$product)
8080
public function update(Product &$product)
8181
{
8282
$data = $product->exportData();
83-
$endpoint = '/admin/products/'.$product->getId().'.json';
83+
$endpoint = '/admin/products/'.$product->id.'.json';
8484
$response = $this->request($endpoint, 'PUT', array(
8585
'product' => $data
8686
));

0 commit comments

Comments
 (0)