Skip to content

Commit

Permalink
fix: update readme and fix load config (#5)
Browse files Browse the repository at this point in the history
* fix function

* Fix styling

* add version

Co-authored-by: sangvictim <[email protected]>
  • Loading branch information
sangvictim and sangvictim authored Oct 7, 2021
1 parent 2fb166e commit 3d1e5e2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
9 changes: 7 additions & 2 deletions README-ID.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ Ini adalah konten dari file config yang telah dipublish:

```php
return [
'API_KEY' => env('RAJAONGKIR_KEY', 'somerandomstring'),
'ACCOUNT_TYPE' => env('RAJAONGKIR_TYPE', 'starter')
];
```

## Penggunaan

```php
$laravel-rajaongkir = new Kodepintar\LaravelRajaongkir();
echo $laravel-rajaongkir->echoPhrase('Hello, Kodepintar!');
use Kodepintar\LaravelRajaongkir\LaravelRajaongkir as Ongkir;

$data = new Ongkir();
$data = $data->getProvince();
return $data;
```

## Kredit
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ This is the contents of the published config file:

```php
return [
'API_KEY' => env('RAJAONGKIR_KEY', 'somerandomstring'),
'ACCOUNT_TYPE' => env('RAJAONGKIR_TYPE', 'starter')
];
```

## Usage

```php
$laravel-rajaongkir = new Kodepintar\LaravelRajaongkir();
echo $laravel-rajaongkir->echoPhrase('Hello, Kodepintar!');
use Kodepintar\LaravelRajaongkir\LaravelRajaongkir as Ongkir;

$data = new Ongkir();
$data = $data->getProvince();
return $data;
```

## Credits
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "kodepintar/laravel-rajaongkir",
"description": "This is my package laravel-rajaongkir",
"version": "1.0",
"keywords": [
"kodepintar",
"laravel",
Expand Down
Empty file removed resources/views/.gitkeep
Empty file.
17 changes: 0 additions & 17 deletions src/Commands/LaravelRajaongkirCommand.php

This file was deleted.

11 changes: 5 additions & 6 deletions src/LaravelRajaongkir.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace Kodepintar\LaravelRajaongkir;

use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;

class LaravelRajaongkir
{
public const BASE_URL = [
protected $BASE_URL = [
'starter' => 'https://api.rajaongkir.com/starter',
'basic' => 'https://api.rajaongkir.com/basic',
'pro' => 'https://pro.rajaongkir.com/api',
Expand All @@ -17,19 +16,19 @@ class LaravelRajaongkir

public function __construct()
{
$accountType = config('rajaongkir.ACCOUNT_TYPE');
$accountType = config('rajaongkir.ACCOUNT_TYPE', env('RAJAONGKIR_TYPE'));

$this->url = self::BASE_URL[$accountType];
$this->url = $this->BASE_URL[$accountType];

return $this;
}

protected function apiCall(string $urlPath, array $payload = [], string $method = 'GET'): Response
protected function apiCall(string $urlPath, array $payload = [], string $method = 'GET')
{
$url = $this->url . '/' . ltrim($urlPath, '/');

return Http::withHeaders([
'key' => config('rajangkir.API_KEY'),
'key' => config('rajaongkir.API_KEY', env('RAJAONGKIR_KEY')),
'content-type' => 'application/x-www-form-urlencoded',
])->{strtolower($method)}($url, $payload);
}
Expand Down

0 comments on commit 3d1e5e2

Please sign in to comment.