-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
666df4a
commit 1966e72
Showing
21 changed files
with
936 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"name": "adityafullstackdeveloper/getgologisticsapi", | ||
"description": "Getgologisticsapi API (V1) Laravel SDK.", | ||
"keywords": [ | ||
"getgologisticsapi", | ||
"laravel getgologisticsapi Api", | ||
"Laravel getgologisticsapi Wrapper", | ||
"getgologisticsapi SDK Module" | ||
], | ||
"homepage": "https://github.com/adityafullstackdeveloper/getgologisticsapi", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "adityafullstackdeveloper", | ||
"email": "adityafullstackdeveloper@gmail.com", | ||
"homepage": "https://github.com/adityafullstackdeveloper", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2.5" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^2.16", | ||
"orchestra/testbench": "^5.0", | ||
"phpunit/phpunit": "^7.5|^9.0", | ||
"psalm/plugin-laravel": "^1.2", | ||
"vimeo/psalm": "^3.11" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Adityafullstackdeveloper\\GetGoLogistics\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Adityafullstackdeveloper\\GetGoLogistics\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"psalm": "vendor/bin/psalm", | ||
"test": "vendor/bin/phpunit", | ||
"test-coverage": "vendor/bin/phpunit --coverage-html coverage", | ||
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Adityafullstackdeveloper\\GetGoLogistics\\ShiprocketServiceProvider" | ||
], | ||
"aliases": { | ||
"Shiprocket": "Adityafullstackdeveloper\\GetGoLogistics\\GetGoLogistics" | ||
} | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Shiprocket Credentilas | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you can set the default shiprocket credentilas. However, you can pass the credentials while connecting to shiprocket client | ||
| | ||
*/ | ||
|
||
'credentials' => [ | ||
'email' => env('SHIPROCKET_EMAIL', 'youemail@email.com'), | ||
'password' => env('SHIPROCKET_PASSWORD', 'secret'), | ||
], | ||
|
||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default output response type | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify which of the output response you need. | ||
| | ||
| Supported: "collection" , "object", "array" | ||
| | ||
*/ | ||
|
||
'responseType' => 'collection', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
namespace Adityafullstackdeveloper\GetGoLogistics\Clients; | ||
|
||
interface Client | ||
{ | ||
public function setEndpoint(string $endpoint); | ||
|
||
public function setHeaders(string $token); | ||
|
||
public function get(); | ||
|
||
public function post(array $data); | ||
|
||
public function patch(array $data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
namespace Adityafullstackdeveloper\GetGoLogisticsApi\Clients; | ||
|
||
class GetGoLogisticsApiClient implements Client | ||
{ | ||
protected $url = 'https://apiv2.shiprocket.in/v1/external/'; | ||
|
||
protected $endpoint; | ||
|
||
protected $headers; | ||
|
||
protected $responseType; | ||
|
||
public function __construct() | ||
{ | ||
$this->responseType = config('getgologistics.responseType'); | ||
} | ||
|
||
/** | ||
* set the endpoint | ||
* | ||
* @param string $endpoint | ||
* @return object $this | ||
*/ | ||
public function setEndpoint(string $endpoint) :object | ||
{ | ||
$this->endpoint = $this->url . $endpoint; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* set the header | ||
* | ||
* @param string $token | ||
* @return object | ||
*/ | ||
public function setHeaders(string $token) :object | ||
{ | ||
$this->headers = [ "Content-Type: application/json" ]; | ||
if ($token != 'login') { | ||
array_push($this->headers, "Authorization: Bearer {$token}"); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Send the data using post request | ||
* | ||
* @param array $data | ||
* @return mixed | ||
*/ | ||
public function post(array $data, $type = "POST") | ||
{ | ||
$curl = curl_init(); | ||
|
||
curl_setopt_array($curl, [ | ||
CURLOPT_URL => $this->endpoint, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => true, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => $type, | ||
CURLOPT_POSTFIELDS => json_encode($data), | ||
CURLOPT_HTTPHEADER => $this->headers, | ||
]); | ||
|
||
$response = curl_exec($curl); | ||
|
||
if (! $this->isValid($response)) { | ||
$response = json_encode([ 'curl_error' => curl_error($curl) ]); | ||
} | ||
|
||
curl_close($curl); | ||
|
||
return $this->responseType($response); | ||
} | ||
|
||
/** | ||
* Send a data using PATCH Request | ||
* | ||
* @param array $data | ||
* @return mixed | ||
*/ | ||
public function patch(array $data) | ||
{ | ||
return $this->post($data, 'PATCH'); | ||
} | ||
|
||
/** | ||
* get the requested data using get request | ||
* | ||
* @return mixed | ||
*/ | ||
public function get() | ||
{ | ||
$curl = curl_init(); | ||
|
||
curl_setopt_array($curl, [ | ||
CURLOPT_URL => $this->endpoint, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => true, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
CURLOPT_HTTPHEADER => $this->headers, | ||
]); | ||
|
||
$response = curl_exec($curl); | ||
|
||
if (! $this->isValid($response)) { | ||
$response = json_encode(['curl_error' => curl_error($curl)]); | ||
} | ||
|
||
curl_close($curl); | ||
|
||
return $this->responseType($response); | ||
} | ||
|
||
/** | ||
* Check the return data is valid | ||
* | ||
* @param mixed $string | ||
* @return bool | ||
*/ | ||
private function isValid($string) :bool | ||
{ | ||
if (! $string) { | ||
return false; | ||
} | ||
|
||
return json_decode($string) ? true : false; | ||
} | ||
|
||
/** | ||
* Return the response type based on config responseType | ||
* | ||
* @param $response | ||
* @return mixed | ||
*/ | ||
private function responseType($response) | ||
{ | ||
if ($this->responseType == 'collection') { | ||
return collect(json_decode($response, true)); | ||
} | ||
|
||
if ($this->responseType == 'object') { | ||
return json_decode($response); | ||
} | ||
|
||
return json_decode($response, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Adityafullstackdeveloper\GetGoLogistics\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class SketchCommand extends Command | ||
{ | ||
public $signature = 'sketch'; | ||
|
||
public $description = 'My command'; | ||
|
||
public function handle() | ||
{ | ||
$this->comment('All done'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Adityafullstackdeveloper\GetGoLogistics\Exceptions; | ||
|
||
use Exception; | ||
|
||
class GetGoLogisticsException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Adityafullstackdeveloper\GetGoLogistics; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
/** | ||
* @see \Seshac\GetGoLogistics\GetGoLogisticsApi | ||
*/ | ||
class GetGoLogistics extends Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'getgologistics'; | ||
} | ||
} |
Oops, something went wrong.