Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update readme and fix load config #5

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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