Compare commits
3
Commits
2b8d6e3062
...
8dcb580393
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dcb580393 | ||
|
|
e178d1c8b4 | ||
|
|
6c13fe7d7d |
@@ -6,7 +6,7 @@ use GuzzleHttp\Client;
|
|||||||
|
|
||||||
class ApiFetcher
|
class ApiFetcher
|
||||||
{
|
{
|
||||||
public function get($endpoint) {
|
public function get($endpoint, $field = 'items') {
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
|
|
||||||
$baseUrl = config('dotsapi.base_url');
|
$baseUrl = config('dotsapi.base_url');
|
||||||
@@ -31,8 +31,10 @@ class ApiFetcher
|
|||||||
);
|
);
|
||||||
|
|
||||||
$data = json_decode($response->getBody()->getContents(), true);
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
$items = $data['items'];
|
|
||||||
|
|
||||||
return $items;
|
if($field == '')
|
||||||
|
return $data;
|
||||||
|
|
||||||
|
return $data[$field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DotsAPI\Fetcher\v2;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
|
class AuthApiFetcher
|
||||||
|
{
|
||||||
|
public function get($endpoint, $field = 'items') {
|
||||||
|
$client = new Client();
|
||||||
|
|
||||||
|
$baseUrl = config('dotsapi.base_url');
|
||||||
|
$apiToken = config('dotsapi.api_token');
|
||||||
|
$apiAccountToken = config('dotsapi.api_account_token');
|
||||||
|
$apiAuthToken = config('dotsapi.api_auth_token');
|
||||||
|
|
||||||
|
$apiUrl = $baseUrl . $endpoint;
|
||||||
|
|
||||||
|
$response = $client->get(
|
||||||
|
$apiUrl,
|
||||||
|
[
|
||||||
|
'headers' => [
|
||||||
|
'Api-Auth-Token' => $apiAuthToken,
|
||||||
|
'Api-Token' => $apiToken,
|
||||||
|
'Api-Account-Token' => $apiAccountToken,
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
],
|
||||||
|
'query' => [
|
||||||
|
'v'=> '2.0.0',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
|
|
||||||
|
if($field == '')
|
||||||
|
return $data;
|
||||||
|
|
||||||
|
return $data[$field];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DotsAPI\Fetcher\v2;
|
||||||
|
|
||||||
|
use GuzzleHttp;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
|
class AuthApiSender
|
||||||
|
{
|
||||||
|
public function get($endpoint, $json, $field = 'id') {
|
||||||
|
$client = new Client();
|
||||||
|
|
||||||
|
$baseUrl = config('dotsapi.base_url');
|
||||||
|
$apiToken = config('dotsapi.api_token');
|
||||||
|
$apiAccountToken = config('dotsapi.api_account_token');
|
||||||
|
$apiAuthToken = config('dotsapi.api_auth_token');
|
||||||
|
|
||||||
|
$apiUrl = $baseUrl . $endpoint;
|
||||||
|
|
||||||
|
$response = $client->post(
|
||||||
|
$apiUrl,
|
||||||
|
[
|
||||||
|
GuzzleHttp\RequestOptions::JSON => $json,
|
||||||
|
'headers' => [
|
||||||
|
'Api-Auth-Token' => $apiAuthToken,
|
||||||
|
'Api-Token' => $apiToken,
|
||||||
|
'Api-Account-Token' => $apiAccountToken,
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
],
|
||||||
|
'query' => [
|
||||||
|
'v'=> '2.0.0',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
|
|
||||||
|
if($field == '')
|
||||||
|
return $data;
|
||||||
|
|
||||||
|
return $data[$field];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,6 +56,20 @@ class Cart extends Model
|
|||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getItemJSON()
|
||||||
|
{
|
||||||
|
$items = $this->items;
|
||||||
|
$itemJSON = [];
|
||||||
|
|
||||||
|
foreach($items as $item)
|
||||||
|
array_push($itemJSON, [
|
||||||
|
'id' =>$item->uuid,
|
||||||
|
'count'=> $item->count
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $itemJSON;
|
||||||
|
}
|
||||||
|
|
||||||
public function getItemIds(): array
|
public function getItemIds(): array
|
||||||
{
|
{
|
||||||
return $this->items()->pluck('item_id')->toArray();
|
return $this->items()->pluck('item_id')->toArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user