@@ -6,38 +6,38 @@ |
||
6 | 6 | |
7 | 7 | class RajaOngkirServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Register services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
9 | + /** |
|
10 | + * Register services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | 14 | |
15 | - protected $commands = [ |
|
16 | - 'Irfa\RajaOngkir\Console\Commands\ROCache', |
|
17 | - 'Irfa\RajaOngkir\Console\Commands\ROInfoPackage', |
|
18 | - ]; |
|
19 | - |
|
20 | - public function register() |
|
21 | - { |
|
22 | - $this->commands($this->commands); |
|
23 | - |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Bootstrap services. |
|
28 | - * |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function boot() |
|
32 | - { |
|
33 | - $this->publishes([ |
|
34 | - __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php'), ], 'raja-ongkir'); |
|
35 | - |
|
36 | - $this->publishes([ |
|
37 | - __DIR__.'/../database/migrations/' => database_path('migrations'), |
|
38 | - ], 'raja-ongkir'); |
|
39 | - |
|
40 | - $this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations'), |
|
41 | - ], 'raja-ongkir'); |
|
42 | - } |
|
15 | + protected $commands = [ |
|
16 | + 'Irfa\RajaOngkir\Console\Commands\ROCache', |
|
17 | + 'Irfa\RajaOngkir\Console\Commands\ROInfoPackage', |
|
18 | + ]; |
|
19 | + |
|
20 | + public function register() |
|
21 | + { |
|
22 | + $this->commands($this->commands); |
|
23 | + |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Bootstrap services. |
|
28 | + * |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function boot() |
|
32 | + { |
|
33 | + $this->publishes([ |
|
34 | + __DIR__.'/../resources/config/irfa/rajaongkir.php' => config_path('irfa/rajaongkir.php'), ], 'raja-ongkir'); |
|
35 | + |
|
36 | + $this->publishes([ |
|
37 | + __DIR__.'/../database/migrations/' => database_path('migrations'), |
|
38 | + ], 'raja-ongkir'); |
|
39 | + |
|
40 | + $this->publishes([__DIR__.'/../database/migrations/' => database_path('migrations'), |
|
41 | + ], 'raja-ongkir'); |
|
42 | + } |
|
43 | 43 | } |
@@ -7,89 +7,89 @@ |
||
7 | 7 | |
8 | 8 | class ROCache extends Command |
9 | 9 | { |
10 | - /** |
|
11 | - * The name and signature of the console command. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $signature = 'raja-ongkir:cache {name}'; |
|
10 | + /** |
|
11 | + * The name and signature of the console command. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $signature = 'raja-ongkir:cache {name}'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * The console command description. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $description = 'Create cache RajaOngkir'; |
|
17 | + /** |
|
18 | + * The console command description. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $description = 'Create cache RajaOngkir'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Create a new command instance. |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct(); |
|
32 | - } |
|
24 | + /** |
|
25 | + * Create a new command instance. |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Execute the console command. |
|
36 | - * |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public function handle() |
|
40 | - { |
|
41 | - if($this->argument('name') == "all"){ |
|
42 | - $this->all(); |
|
43 | - } elseif($this->argument('name') == "city"){ |
|
44 | - RajaOngkir::cachingCity(); |
|
45 | - } elseif($this->argument('name') == "province"){ |
|
46 | - RajaOngkir::cachingProvince(); |
|
47 | - } elseif($this->argument('name') == "subdistrict"){ |
|
48 | - RajaOngkir::cachingSubDistrict(); |
|
49 | - } elseif($this->argument('name') == "clear"){ |
|
50 | - ROCache::clearCache(); |
|
51 | - } elseif($this->argument('name') == "refresh"){ |
|
52 | - ROCache::refresh(); |
|
53 | - } else{ |
|
54 | - $this->line('<fg=yellow>Valid input is all, clear, refresh, city, province and subdistrict.'); |
|
55 | - } |
|
56 | - } |
|
57 | - private function all(){ |
|
58 | - echo "---------------------".PHP_EOL; |
|
59 | - echo"Province Caching".PHP_EOL; |
|
60 | - echo"---------------------".PHP_EOL; |
|
61 | - RajaOngkir::cachingProvince(); |
|
62 | - echo PHP_EOL."---------------------".PHP_EOL; |
|
63 | - sleep(1);//Cooling Down |
|
64 | - echo"City Caching".PHP_EOL; |
|
65 | - echo "---------------------".PHP_EOL; |
|
66 | - RajaOngkir::cachingCity(); |
|
67 | - echo PHP_EOL."---------------------".PHP_EOL; |
|
68 | - sleep(1);//Cooling Down |
|
69 | - echo"Subdistrict Caching".PHP_EOL; |
|
70 | - echo "---------------------".PHP_EOL; |
|
71 | - RajaOngkir::cachingSubDistrict(); |
|
72 | - echo PHP_EOL."---------------------".PHP_EOL; |
|
73 | - } |
|
74 | - private function refresh(){ |
|
75 | - echo "---------------------".PHP_EOL; |
|
76 | - echo"Refresh Cache".PHP_EOL; |
|
77 | - echo"---------------------".PHP_EOL; |
|
78 | - ROCache::clearCache(); |
|
79 | - echo "---------------------".PHP_EOL; |
|
80 | - echo"Province Caching".PHP_EOL; |
|
81 | - echo"---------------------".PHP_EOL; |
|
82 | - RajaOngkir::cachingProvince(); |
|
83 | - echo PHP_EOL."---------------------".PHP_EOL; |
|
84 | - sleep(1);//Cooling Down |
|
85 | - echo"City Caching".PHP_EOL; |
|
86 | - echo "---------------------".PHP_EOL; |
|
87 | - RajaOngkir::cachingCity(); |
|
88 | - echo PHP_EOL."---------------------".PHP_EOL; |
|
89 | - sleep(1);//Cooling Down |
|
90 | - echo"Subdistrict Caching".PHP_EOL; |
|
91 | - echo "---------------------".PHP_EOL; |
|
92 | - RajaOngkir::cachingSubDistrict(); |
|
93 | - echo PHP_EOL."---------------------".PHP_EOL; |
|
94 | - } |
|
34 | + /** |
|
35 | + * Execute the console command. |
|
36 | + * |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public function handle() |
|
40 | + { |
|
41 | + if($this->argument('name') == "all"){ |
|
42 | + $this->all(); |
|
43 | + } elseif($this->argument('name') == "city"){ |
|
44 | + RajaOngkir::cachingCity(); |
|
45 | + } elseif($this->argument('name') == "province"){ |
|
46 | + RajaOngkir::cachingProvince(); |
|
47 | + } elseif($this->argument('name') == "subdistrict"){ |
|
48 | + RajaOngkir::cachingSubDistrict(); |
|
49 | + } elseif($this->argument('name') == "clear"){ |
|
50 | + ROCache::clearCache(); |
|
51 | + } elseif($this->argument('name') == "refresh"){ |
|
52 | + ROCache::refresh(); |
|
53 | + } else{ |
|
54 | + $this->line('<fg=yellow>Valid input is all, clear, refresh, city, province and subdistrict.'); |
|
55 | + } |
|
56 | + } |
|
57 | + private function all(){ |
|
58 | + echo "---------------------".PHP_EOL; |
|
59 | + echo"Province Caching".PHP_EOL; |
|
60 | + echo"---------------------".PHP_EOL; |
|
61 | + RajaOngkir::cachingProvince(); |
|
62 | + echo PHP_EOL."---------------------".PHP_EOL; |
|
63 | + sleep(1);//Cooling Down |
|
64 | + echo"City Caching".PHP_EOL; |
|
65 | + echo "---------------------".PHP_EOL; |
|
66 | + RajaOngkir::cachingCity(); |
|
67 | + echo PHP_EOL."---------------------".PHP_EOL; |
|
68 | + sleep(1);//Cooling Down |
|
69 | + echo"Subdistrict Caching".PHP_EOL; |
|
70 | + echo "---------------------".PHP_EOL; |
|
71 | + RajaOngkir::cachingSubDistrict(); |
|
72 | + echo PHP_EOL."---------------------".PHP_EOL; |
|
73 | + } |
|
74 | + private function refresh(){ |
|
75 | + echo "---------------------".PHP_EOL; |
|
76 | + echo"Refresh Cache".PHP_EOL; |
|
77 | + echo"---------------------".PHP_EOL; |
|
78 | + ROCache::clearCache(); |
|
79 | + echo "---------------------".PHP_EOL; |
|
80 | + echo"Province Caching".PHP_EOL; |
|
81 | + echo"---------------------".PHP_EOL; |
|
82 | + RajaOngkir::cachingProvince(); |
|
83 | + echo PHP_EOL."---------------------".PHP_EOL; |
|
84 | + sleep(1);//Cooling Down |
|
85 | + echo"City Caching".PHP_EOL; |
|
86 | + echo "---------------------".PHP_EOL; |
|
87 | + RajaOngkir::cachingCity(); |
|
88 | + echo PHP_EOL."---------------------".PHP_EOL; |
|
89 | + sleep(1);//Cooling Down |
|
90 | + echo"Subdistrict Caching".PHP_EOL; |
|
91 | + echo "---------------------".PHP_EOL; |
|
92 | + RajaOngkir::cachingSubDistrict(); |
|
93 | + echo PHP_EOL."---------------------".PHP_EOL; |
|
94 | + } |
|
95 | 95 | } |
@@ -38,40 +38,40 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function handle() |
40 | 40 | { |
41 | - if($this->argument('name') == "all"){ |
|
41 | + if ($this->argument('name') == "all") { |
|
42 | 42 | $this->all(); |
43 | - } elseif($this->argument('name') == "city"){ |
|
43 | + } elseif ($this->argument('name') == "city") { |
|
44 | 44 | RajaOngkir::cachingCity(); |
45 | - } elseif($this->argument('name') == "province"){ |
|
45 | + } elseif ($this->argument('name') == "province") { |
|
46 | 46 | RajaOngkir::cachingProvince(); |
47 | - } elseif($this->argument('name') == "subdistrict"){ |
|
47 | + } elseif ($this->argument('name') == "subdistrict") { |
|
48 | 48 | RajaOngkir::cachingSubDistrict(); |
49 | - } elseif($this->argument('name') == "clear"){ |
|
49 | + } elseif ($this->argument('name') == "clear") { |
|
50 | 50 | ROCache::clearCache(); |
51 | - } elseif($this->argument('name') == "refresh"){ |
|
51 | + } elseif ($this->argument('name') == "refresh") { |
|
52 | 52 | ROCache::refresh(); |
53 | - } else{ |
|
53 | + } else { |
|
54 | 54 | $this->line('<fg=yellow>Valid input is all, clear, refresh, city, province and subdistrict.'); |
55 | 55 | } |
56 | 56 | } |
57 | - private function all(){ |
|
57 | + private function all() { |
|
58 | 58 | echo "---------------------".PHP_EOL; |
59 | 59 | echo"Province Caching".PHP_EOL; |
60 | 60 | echo"---------------------".PHP_EOL; |
61 | 61 | RajaOngkir::cachingProvince(); |
62 | 62 | echo PHP_EOL."---------------------".PHP_EOL; |
63 | - sleep(1);//Cooling Down |
|
63 | + sleep(1); //Cooling Down |
|
64 | 64 | echo"City Caching".PHP_EOL; |
65 | 65 | echo "---------------------".PHP_EOL; |
66 | 66 | RajaOngkir::cachingCity(); |
67 | 67 | echo PHP_EOL."---------------------".PHP_EOL; |
68 | - sleep(1);//Cooling Down |
|
68 | + sleep(1); //Cooling Down |
|
69 | 69 | echo"Subdistrict Caching".PHP_EOL; |
70 | 70 | echo "---------------------".PHP_EOL; |
71 | 71 | RajaOngkir::cachingSubDistrict(); |
72 | 72 | echo PHP_EOL."---------------------".PHP_EOL; |
73 | 73 | } |
74 | - private function refresh(){ |
|
74 | + private function refresh() { |
|
75 | 75 | echo "---------------------".PHP_EOL; |
76 | 76 | echo"Refresh Cache".PHP_EOL; |
77 | 77 | echo"---------------------".PHP_EOL; |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | echo"---------------------".PHP_EOL; |
82 | 82 | RajaOngkir::cachingProvince(); |
83 | 83 | echo PHP_EOL."---------------------".PHP_EOL; |
84 | - sleep(1);//Cooling Down |
|
84 | + sleep(1); //Cooling Down |
|
85 | 85 | echo"City Caching".PHP_EOL; |
86 | 86 | echo "---------------------".PHP_EOL; |
87 | 87 | RajaOngkir::cachingCity(); |
88 | 88 | echo PHP_EOL."---------------------".PHP_EOL; |
89 | - sleep(1);//Cooling Down |
|
89 | + sleep(1); //Cooling Down |
|
90 | 90 | echo"Subdistrict Caching".PHP_EOL; |
91 | 91 | echo "---------------------".PHP_EOL; |
92 | 92 | RajaOngkir::cachingSubDistrict(); |
@@ -7,60 +7,60 @@ discard block |
||
7 | 7 | |
8 | 8 | class ROInfoPackage extends Command |
9 | 9 | { |
10 | - /** |
|
11 | - * The name and signature of the console command. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $signature = 'raja-ongkir {cmd}'; |
|
10 | + /** |
|
11 | + * The name and signature of the console command. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $signature = 'raja-ongkir {cmd}'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * The console command description. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $description = 'Option'; |
|
17 | + /** |
|
18 | + * The console command description. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $description = 'Option'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Create a new command instance. |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct(); |
|
32 | - } |
|
24 | + /** |
|
25 | + * Create a new command instance. |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Execute the console command. |
|
36 | - * |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public function handle() |
|
40 | - { |
|
41 | - if($this->argument('cmd') == "version" || $this->argument('cmd') == "v" ){ |
|
42 | - $this->informasi(); |
|
43 | - } elseif($this->argument('cmd') == "key"){ |
|
44 | - $this->line('Api Key: '.config('irfa.rajaongkir.api_key')); |
|
45 | - } elseif($this->argument('cmd') == "type"){ |
|
46 | - $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
|
47 | - } elseif($this->argument('cmd') == "info"){ |
|
48 | - $this->informasi(); |
|
49 | - $this->line('-------------------------------------------------------------------------------'); |
|
50 | - $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
|
51 | - $this->line('Api Key: '.config('irfa.rajaongkir.api_key')); |
|
52 | - $this->line('Api Version: '.config('irfa.rajaongkir.api_version')); |
|
53 | - $this->line('Province Table: '.config('irfa.rajaongkir.province_table')); |
|
54 | - $this->line('City Table: '.config('irfa.rajaongkir.city_table')); |
|
55 | - $this->line('Subdistrict Table: '.config('irfa.rajaongkir.subdistrict_table')); |
|
56 | - $this->line('Cache Type: '.config('irfa.rajaongkir.cache_type')); |
|
57 | - } else{ |
|
58 | - $this->line('<fg=yellow>valid input is version, key, type, info,and v.'); |
|
59 | - } |
|
60 | - } |
|
34 | + /** |
|
35 | + * Execute the console command. |
|
36 | + * |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public function handle() |
|
40 | + { |
|
41 | + if($this->argument('cmd') == "version" || $this->argument('cmd') == "v" ){ |
|
42 | + $this->informasi(); |
|
43 | + } elseif($this->argument('cmd') == "key"){ |
|
44 | + $this->line('Api Key: '.config('irfa.rajaongkir.api_key')); |
|
45 | + } elseif($this->argument('cmd') == "type"){ |
|
46 | + $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
|
47 | + } elseif($this->argument('cmd') == "info"){ |
|
48 | + $this->informasi(); |
|
49 | + $this->line('-------------------------------------------------------------------------------'); |
|
50 | + $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
|
51 | + $this->line('Api Key: '.config('irfa.rajaongkir.api_key')); |
|
52 | + $this->line('Api Version: '.config('irfa.rajaongkir.api_version')); |
|
53 | + $this->line('Province Table: '.config('irfa.rajaongkir.province_table')); |
|
54 | + $this->line('City Table: '.config('irfa.rajaongkir.city_table')); |
|
55 | + $this->line('Subdistrict Table: '.config('irfa.rajaongkir.subdistrict_table')); |
|
56 | + $this->line('Cache Type: '.config('irfa.rajaongkir.cache_type')); |
|
57 | + } else{ |
|
58 | + $this->line('<fg=yellow>valid input is version, key, type, info,and v.'); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - private function informasi(){ |
|
63 | - $this->line(" |_ _| / _| | __ \ (_) / __ \ | | (_) |
|
62 | + private function informasi(){ |
|
63 | + $this->line(" |_ _| / _| | __ \ (_) / __ \ | | (_) |
|
64 | 64 | | | _ __| |_ __ _ ______ | |__) |__ _ _ __ _ | | | |_ __ __ _| | ___ _ __ |
65 | 65 | | | | '__| _/ _` | |______| | _ // _` | |/ _` | | | | | '_ \ / _` | |/ / | '__| |
66 | 66 | _| |_| | | || (_| | | | \ \ (_| | | (_| | | |__| | | | | (_| | <| | | |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | _/ | __/ | |
69 | 69 | |__/ |___/ ".PHP_EOL); |
70 | 70 | |
71 | - $this->line('-------------------------------------------------------------------------------'); |
|
72 | - $this->line('Raja Ongkir'); |
|
73 | - $this->line('Version 1.6.0 (2020)'); |
|
74 | - $this->line('https://github.com/irfaardy/raja-ongkir'); |
|
75 | - } |
|
71 | + $this->line('-------------------------------------------------------------------------------'); |
|
72 | + $this->line('Raja Ongkir'); |
|
73 | + $this->line('Version 1.6.0 (2020)'); |
|
74 | + $this->line('https://github.com/irfaardy/raja-ongkir'); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | } |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function handle() |
40 | 40 | { |
41 | - if($this->argument('cmd') == "version" || $this->argument('cmd') == "v" ){ |
|
41 | + if ($this->argument('cmd') == "version" || $this->argument('cmd') == "v") { |
|
42 | 42 | $this->informasi(); |
43 | - } elseif($this->argument('cmd') == "key"){ |
|
43 | + } elseif ($this->argument('cmd') == "key") { |
|
44 | 44 | $this->line('Api Key: '.config('irfa.rajaongkir.api_key')); |
45 | - } elseif($this->argument('cmd') == "type"){ |
|
45 | + } elseif ($this->argument('cmd') == "type") { |
|
46 | 46 | $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
47 | - } elseif($this->argument('cmd') == "info"){ |
|
47 | + } elseif ($this->argument('cmd') == "info") { |
|
48 | 48 | $this->informasi(); |
49 | 49 | $this->line('-------------------------------------------------------------------------------'); |
50 | 50 | $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | $this->line('City Table: '.config('irfa.rajaongkir.city_table')); |
55 | 55 | $this->line('Subdistrict Table: '.config('irfa.rajaongkir.subdistrict_table')); |
56 | 56 | $this->line('Cache Type: '.config('irfa.rajaongkir.cache_type')); |
57 | - } else{ |
|
57 | + } else { |
|
58 | 58 | $this->line('<fg=yellow>valid input is version, key, type, info,and v.'); |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - private function informasi(){ |
|
62 | + private function informasi() { |
|
63 | 63 | $this->line(" |_ _| / _| | __ \ (_) / __ \ | | (_) |
64 | 64 | | | _ __| |_ __ _ ______ | |__) |__ _ _ __ _ | | | |_ __ __ _| | ___ _ __ |
65 | 65 | | | | '__| _/ _` | |______| | _ // _` | |/ _` | | | | | '_ \ / _` | |/ / | '__| |
@@ -44,7 +44,7 @@ |
||
44 | 44 | $this->line('Api Key: '.config('irfa.rajaongkir.api_key')); |
45 | 45 | } elseif($this->argument('cmd') == "type"){ |
46 | 46 | $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
47 | - } elseif($this->argument('cmd') == "info"){ |
|
47 | + } elseif($this->argument('cmd') == "info"){ |
|
48 | 48 | $this->informasi(); |
49 | 49 | $this->line('-------------------------------------------------------------------------------'); |
50 | 50 | $this->line('Account Type: '.config('irfa.rajaongkir.account_type')); |
@@ -12,292 +12,292 @@ |
||
12 | 12 | |
13 | 13 | class Api extends CacheCurl |
14 | 14 | { |
15 | - private static $account_type; |
|
16 | - private static $api_key; |
|
17 | - private static $api_version; |
|
18 | - private static $url; |
|
19 | - private static $count = 0; |
|
20 | - |
|
21 | - private static function setup_option() |
|
22 | - { |
|
23 | - if (function_exists('config') and function_exists('app')) {//Load Config For Laravel |
|
24 | - self::$account_type = strtolower(config('irfa.rajaongkir.account_type')); |
|
25 | - self::$api_key = config('irfa.rajaongkir.api_key'); |
|
26 | - self::$api_version = config('irfa.rajaongkir.api_version'); |
|
27 | - } else {//Load config For PHP Native |
|
28 | - require __DIR__.'../../../../config/config.php'; |
|
29 | - self::$account_type = strtolower($config['account_type']); |
|
30 | - self::$api_key = $config['api_key']; |
|
31 | - self::$api_version = $config['api_version']; |
|
32 | - } |
|
33 | - if (self::$account_type == 'pro') { |
|
34 | - self::$url = 'https://pro.rajaongkir.com/api'; |
|
35 | - } else { |
|
36 | - self::$url = 'https://api.rajaongkir.com/'.self::$account_type; |
|
37 | - } |
|
38 | - } |
|
39 | - |
|
40 | - protected static function cacheProvince() |
|
41 | - { |
|
42 | - self::setup_option(); |
|
43 | - echo "Retrieving data from \033[96m".self::$url."...\033[0m".PHP_EOL; |
|
44 | - CacheCurl::caching(self::get_province())->province(); |
|
45 | - } |
|
46 | - |
|
47 | - protected static function cacheCity() |
|
48 | - { |
|
49 | - self::setup_option(); |
|
50 | - echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL; |
|
51 | - CacheCurl::caching(self::get_city())->city(); |
|
52 | - } |
|
53 | - protected static function cacheSubDistrict($arr) |
|
54 | - { |
|
55 | - self::setup_option(); |
|
56 | - echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL; |
|
57 | - CacheCurl::caching(self::getSubdistrict($arr))->subdistrict(); |
|
58 | - } |
|
59 | - protected static function get_province($arr = null) |
|
60 | - { |
|
61 | - if ($arr != null) { |
|
62 | - $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null; |
|
63 | - } else { |
|
64 | - $province_id = null; |
|
65 | - } |
|
66 | - self::setup_option(); |
|
67 | - $curl = curl_init(); |
|
68 | - curl_setopt_array($curl, [ |
|
69 | - CURLOPT_URL => self::$url.'/province'.$province_id, |
|
70 | - CURLOPT_RETURNTRANSFER => true, |
|
71 | - CURLOPT_ENCODING => '', |
|
72 | - CURLOPT_MAXREDIRS => 10, |
|
73 | - CURLOPT_TIMEOUT => 30, |
|
74 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
75 | - CURLOPT_CUSTOMREQUEST => 'GET', |
|
76 | - CURLOPT_HTTPHEADER => [ |
|
77 | - 'key: '.self::$api_key, |
|
78 | - ], |
|
79 | - ]); |
|
80 | - $response = curl_exec($curl); |
|
81 | - $err = curl_error($curl); |
|
82 | - |
|
83 | - curl_close($curl); |
|
84 | - |
|
85 | - if ($err) { |
|
86 | - self::exceptCurl($err); |
|
87 | - } else { |
|
88 | - $json = json_decode($response, false)->rajaongkir; |
|
89 | - if ($json->status->code == '400') { |
|
90 | - throw new Exception($json->status->description); |
|
91 | - } else { |
|
92 | - $res = $json->results; |
|
93 | - |
|
94 | - return $res; |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - protected static function get_city($arr = null) |
|
100 | - { |
|
101 | - if ($arr != null) { |
|
102 | - $province_id = array_key_exists('province_id', $arr) ? '?province='.$arr['province_id'] : null; |
|
103 | - } else { |
|
104 | - $province_id = null; |
|
105 | - } |
|
106 | - self::setup_option(); |
|
107 | - $curl = curl_init(); |
|
108 | - curl_setopt_array($curl, [ |
|
109 | - CURLOPT_URL => self::$url.'/city'.$province_id, |
|
110 | - CURLOPT_RETURNTRANSFER => true, |
|
111 | - CURLOPT_ENCODING => '', |
|
112 | - CURLOPT_MAXREDIRS => 10, |
|
113 | - CURLOPT_TIMEOUT => 30, |
|
114 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
115 | - CURLOPT_CUSTOMREQUEST => 'GET', |
|
116 | - CURLOPT_HTTPHEADER => [ |
|
117 | - 'key: '.self::$api_key, |
|
118 | - ], |
|
119 | - ]); |
|
120 | - $response = curl_exec($curl); |
|
121 | - $err = curl_error($curl); |
|
122 | - |
|
123 | - curl_close($curl); |
|
124 | - |
|
125 | - if ($err) { |
|
126 | - self::exceptCurl($err); |
|
127 | - } else { |
|
128 | - $json = json_decode($response, false)->rajaongkir; |
|
129 | - if ($json->status->code == '400') { |
|
130 | - throw new Exception($json->status->description); |
|
131 | - } else { |
|
132 | - $res = $json->results; |
|
133 | - |
|
134 | - return $res; |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - protected static function get_courier($arr) |
|
140 | - { |
|
141 | - $origin = $arr['origin']; |
|
142 | - $destination = $arr['destination']; |
|
143 | - $weight = $arr['weight']; |
|
144 | - $courier = $arr['courier']; |
|
145 | - $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
146 | - |
|
147 | - return $res; |
|
148 | - } |
|
149 | - |
|
150 | - protected static function get_cost_details($arr) |
|
151 | - { |
|
152 | - $origin = $arr['origin']; |
|
153 | - $destination = $arr['destination']; |
|
154 | - $weight = $arr['weight']; |
|
155 | - $courier = $arr['courier']; |
|
156 | - $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
157 | - |
|
158 | - return $res[0]->costs; |
|
159 | - } |
|
160 | - |
|
161 | - private static function curl_cost_get($origin, $destination, $weight, $courier) |
|
162 | - { |
|
163 | - $curl = curl_init(); |
|
164 | - |
|
165 | - curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier)); |
|
166 | - |
|
167 | - $response = curl_exec($curl); |
|
168 | - $err = curl_error($curl); |
|
169 | - |
|
170 | - curl_close($curl); |
|
171 | - |
|
172 | - if ($err) { |
|
173 | - echo "Can't connect to server, please check your internet connection."; |
|
174 | - exit(); |
|
175 | - } else { |
|
176 | - $json = json_decode($response, false)->rajaongkir; |
|
177 | - if ($json->status->code == '400') { |
|
178 | - throw new Exception($json->status->description); |
|
179 | - } else { |
|
180 | - $res = $json->results; |
|
181 | - |
|
182 | - return $res; |
|
183 | - } |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - private static function curl_cost_option($origin, $destination, $weight, $courier) |
|
188 | - { |
|
189 | - self::setup_option(); |
|
190 | - |
|
191 | - return [ |
|
192 | - CURLOPT_URL => self::$url.'/cost', |
|
193 | - CURLOPT_RETURNTRANSFER => true, |
|
194 | - CURLOPT_ENCODING => '', |
|
195 | - CURLOPT_MAXREDIRS => 10, |
|
196 | - CURLOPT_TIMEOUT => 30, |
|
197 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
198 | - CURLOPT_CUSTOMREQUEST => 'POST', |
|
199 | - CURLOPT_POSTFIELDS => 'origin='.$origin.'&destination='.$destination.'&weight='.$weight.'&courier='.strtolower($courier), |
|
200 | - CURLOPT_HTTPHEADER => [ |
|
201 | - 'content-type: application/x-www-form-urlencoded', |
|
202 | - 'key: '.self::$api_key, |
|
203 | - ], |
|
204 | - ]; |
|
205 | - } |
|
15 | + private static $account_type; |
|
16 | + private static $api_key; |
|
17 | + private static $api_version; |
|
18 | + private static $url; |
|
19 | + private static $count = 0; |
|
20 | + |
|
21 | + private static function setup_option() |
|
22 | + { |
|
23 | + if (function_exists('config') and function_exists('app')) {//Load Config For Laravel |
|
24 | + self::$account_type = strtolower(config('irfa.rajaongkir.account_type')); |
|
25 | + self::$api_key = config('irfa.rajaongkir.api_key'); |
|
26 | + self::$api_version = config('irfa.rajaongkir.api_version'); |
|
27 | + } else {//Load config For PHP Native |
|
28 | + require __DIR__.'../../../../config/config.php'; |
|
29 | + self::$account_type = strtolower($config['account_type']); |
|
30 | + self::$api_key = $config['api_key']; |
|
31 | + self::$api_version = $config['api_version']; |
|
32 | + } |
|
33 | + if (self::$account_type == 'pro') { |
|
34 | + self::$url = 'https://pro.rajaongkir.com/api'; |
|
35 | + } else { |
|
36 | + self::$url = 'https://api.rajaongkir.com/'.self::$account_type; |
|
37 | + } |
|
38 | + } |
|
39 | + |
|
40 | + protected static function cacheProvince() |
|
41 | + { |
|
42 | + self::setup_option(); |
|
43 | + echo "Retrieving data from \033[96m".self::$url."...\033[0m".PHP_EOL; |
|
44 | + CacheCurl::caching(self::get_province())->province(); |
|
45 | + } |
|
46 | + |
|
47 | + protected static function cacheCity() |
|
48 | + { |
|
49 | + self::setup_option(); |
|
50 | + echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL; |
|
51 | + CacheCurl::caching(self::get_city())->city(); |
|
52 | + } |
|
53 | + protected static function cacheSubDistrict($arr) |
|
54 | + { |
|
55 | + self::setup_option(); |
|
56 | + echo "Retrieving data from\033[96m ".self::$url."...\033[0m".PHP_EOL; |
|
57 | + CacheCurl::caching(self::getSubdistrict($arr))->subdistrict(); |
|
58 | + } |
|
59 | + protected static function get_province($arr = null) |
|
60 | + { |
|
61 | + if ($arr != null) { |
|
62 | + $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null; |
|
63 | + } else { |
|
64 | + $province_id = null; |
|
65 | + } |
|
66 | + self::setup_option(); |
|
67 | + $curl = curl_init(); |
|
68 | + curl_setopt_array($curl, [ |
|
69 | + CURLOPT_URL => self::$url.'/province'.$province_id, |
|
70 | + CURLOPT_RETURNTRANSFER => true, |
|
71 | + CURLOPT_ENCODING => '', |
|
72 | + CURLOPT_MAXREDIRS => 10, |
|
73 | + CURLOPT_TIMEOUT => 30, |
|
74 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
75 | + CURLOPT_CUSTOMREQUEST => 'GET', |
|
76 | + CURLOPT_HTTPHEADER => [ |
|
77 | + 'key: '.self::$api_key, |
|
78 | + ], |
|
79 | + ]); |
|
80 | + $response = curl_exec($curl); |
|
81 | + $err = curl_error($curl); |
|
82 | + |
|
83 | + curl_close($curl); |
|
84 | + |
|
85 | + if ($err) { |
|
86 | + self::exceptCurl($err); |
|
87 | + } else { |
|
88 | + $json = json_decode($response, false)->rajaongkir; |
|
89 | + if ($json->status->code == '400') { |
|
90 | + throw new Exception($json->status->description); |
|
91 | + } else { |
|
92 | + $res = $json->results; |
|
93 | + |
|
94 | + return $res; |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + protected static function get_city($arr = null) |
|
100 | + { |
|
101 | + if ($arr != null) { |
|
102 | + $province_id = array_key_exists('province_id', $arr) ? '?province='.$arr['province_id'] : null; |
|
103 | + } else { |
|
104 | + $province_id = null; |
|
105 | + } |
|
106 | + self::setup_option(); |
|
107 | + $curl = curl_init(); |
|
108 | + curl_setopt_array($curl, [ |
|
109 | + CURLOPT_URL => self::$url.'/city'.$province_id, |
|
110 | + CURLOPT_RETURNTRANSFER => true, |
|
111 | + CURLOPT_ENCODING => '', |
|
112 | + CURLOPT_MAXREDIRS => 10, |
|
113 | + CURLOPT_TIMEOUT => 30, |
|
114 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
115 | + CURLOPT_CUSTOMREQUEST => 'GET', |
|
116 | + CURLOPT_HTTPHEADER => [ |
|
117 | + 'key: '.self::$api_key, |
|
118 | + ], |
|
119 | + ]); |
|
120 | + $response = curl_exec($curl); |
|
121 | + $err = curl_error($curl); |
|
122 | + |
|
123 | + curl_close($curl); |
|
124 | + |
|
125 | + if ($err) { |
|
126 | + self::exceptCurl($err); |
|
127 | + } else { |
|
128 | + $json = json_decode($response, false)->rajaongkir; |
|
129 | + if ($json->status->code == '400') { |
|
130 | + throw new Exception($json->status->description); |
|
131 | + } else { |
|
132 | + $res = $json->results; |
|
133 | + |
|
134 | + return $res; |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + protected static function get_courier($arr) |
|
140 | + { |
|
141 | + $origin = $arr['origin']; |
|
142 | + $destination = $arr['destination']; |
|
143 | + $weight = $arr['weight']; |
|
144 | + $courier = $arr['courier']; |
|
145 | + $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
146 | + |
|
147 | + return $res; |
|
148 | + } |
|
149 | + |
|
150 | + protected static function get_cost_details($arr) |
|
151 | + { |
|
152 | + $origin = $arr['origin']; |
|
153 | + $destination = $arr['destination']; |
|
154 | + $weight = $arr['weight']; |
|
155 | + $courier = $arr['courier']; |
|
156 | + $res = self::curl_cost_get($origin, $destination, $weight, $courier); |
|
157 | + |
|
158 | + return $res[0]->costs; |
|
159 | + } |
|
160 | + |
|
161 | + private static function curl_cost_get($origin, $destination, $weight, $courier) |
|
162 | + { |
|
163 | + $curl = curl_init(); |
|
164 | + |
|
165 | + curl_setopt_array($curl, self::curl_cost_option($origin, $destination, $weight, $courier)); |
|
166 | + |
|
167 | + $response = curl_exec($curl); |
|
168 | + $err = curl_error($curl); |
|
169 | + |
|
170 | + curl_close($curl); |
|
171 | + |
|
172 | + if ($err) { |
|
173 | + echo "Can't connect to server, please check your internet connection."; |
|
174 | + exit(); |
|
175 | + } else { |
|
176 | + $json = json_decode($response, false)->rajaongkir; |
|
177 | + if ($json->status->code == '400') { |
|
178 | + throw new Exception($json->status->description); |
|
179 | + } else { |
|
180 | + $res = $json->results; |
|
181 | + |
|
182 | + return $res; |
|
183 | + } |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + private static function curl_cost_option($origin, $destination, $weight, $courier) |
|
188 | + { |
|
189 | + self::setup_option(); |
|
190 | + |
|
191 | + return [ |
|
192 | + CURLOPT_URL => self::$url.'/cost', |
|
193 | + CURLOPT_RETURNTRANSFER => true, |
|
194 | + CURLOPT_ENCODING => '', |
|
195 | + CURLOPT_MAXREDIRS => 10, |
|
196 | + CURLOPT_TIMEOUT => 30, |
|
197 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
198 | + CURLOPT_CUSTOMREQUEST => 'POST', |
|
199 | + CURLOPT_POSTFIELDS => 'origin='.$origin.'&destination='.$destination.'&weight='.$weight.'&courier='.strtolower($courier), |
|
200 | + CURLOPT_HTTPHEADER => [ |
|
201 | + 'content-type: application/x-www-form-urlencoded', |
|
202 | + 'key: '.self::$api_key, |
|
203 | + ], |
|
204 | + ]; |
|
205 | + } |
|
206 | 206 | ///PRO |
207 | - protected static function getSubdistrict($arr = null) |
|
208 | - { |
|
209 | - if ($arr != null) { |
|
210 | - $city = array_key_exists('city', $arr) ? '?city='.$arr['city'] : null; |
|
211 | - } else { |
|
212 | - $city = null; |
|
213 | - } |
|
214 | - self::setup_option(); |
|
215 | - $curl = curl_init(); |
|
216 | - curl_setopt_array($curl, [ |
|
217 | - CURLOPT_URL => self::$url.'/subdistrict'.$city, |
|
218 | - CURLOPT_RETURNTRANSFER => true, |
|
219 | - CURLOPT_ENCODING => '', |
|
220 | - CURLOPT_MAXREDIRS => 10, |
|
221 | - CURLOPT_TIMEOUT => 30, |
|
222 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
223 | - CURLOPT_CUSTOMREQUEST => 'GET', |
|
224 | - CURLOPT_HTTPHEADER => [ |
|
225 | - 'key: '.self::$api_key, |
|
226 | - ], |
|
227 | - ]); |
|
228 | - $response = curl_exec($curl); |
|
229 | - $err = curl_error($curl); |
|
230 | - |
|
231 | - curl_close($curl); |
|
232 | - |
|
233 | - if ($err) { |
|
234 | - self::exceptCurl($err); |
|
235 | - } else { |
|
236 | - $json = json_decode($response, false)->rajaongkir; |
|
237 | - if ($json->status->code == '400') { |
|
238 | - throw new Exception($json->status->description); |
|
239 | - } else { |
|
240 | - $res = $json->results; |
|
241 | - |
|
242 | - return $res; |
|
243 | - } |
|
244 | - } |
|
245 | - } |
|
207 | + protected static function getSubdistrict($arr = null) |
|
208 | + { |
|
209 | + if ($arr != null) { |
|
210 | + $city = array_key_exists('city', $arr) ? '?city='.$arr['city'] : null; |
|
211 | + } else { |
|
212 | + $city = null; |
|
213 | + } |
|
214 | + self::setup_option(); |
|
215 | + $curl = curl_init(); |
|
216 | + curl_setopt_array($curl, [ |
|
217 | + CURLOPT_URL => self::$url.'/subdistrict'.$city, |
|
218 | + CURLOPT_RETURNTRANSFER => true, |
|
219 | + CURLOPT_ENCODING => '', |
|
220 | + CURLOPT_MAXREDIRS => 10, |
|
221 | + CURLOPT_TIMEOUT => 30, |
|
222 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
223 | + CURLOPT_CUSTOMREQUEST => 'GET', |
|
224 | + CURLOPT_HTTPHEADER => [ |
|
225 | + 'key: '.self::$api_key, |
|
226 | + ], |
|
227 | + ]); |
|
228 | + $response = curl_exec($curl); |
|
229 | + $err = curl_error($curl); |
|
230 | + |
|
231 | + curl_close($curl); |
|
232 | + |
|
233 | + if ($err) { |
|
234 | + self::exceptCurl($err); |
|
235 | + } else { |
|
236 | + $json = json_decode($response, false)->rajaongkir; |
|
237 | + if ($json->status->code == '400') { |
|
238 | + throw new Exception($json->status->description); |
|
239 | + } else { |
|
240 | + $res = $json->results; |
|
241 | + |
|
242 | + return $res; |
|
243 | + } |
|
244 | + } |
|
245 | + } |
|
246 | 246 | |
247 | 247 | private static function exceptCurl($err){ |
248 | - if(php_sapi_name() == "cli"){ |
|
249 | - echo "Can't connect to server, please check your internet connection.\n"; |
|
250 | - echo "Exception: \033[31m".$err; |
|
251 | - exit(); |
|
252 | - } else{ |
|
253 | - throw new Exception($err); |
|
254 | - } |
|
248 | + if(php_sapi_name() == "cli"){ |
|
249 | + echo "Can't connect to server, please check your internet connection.\n"; |
|
250 | + echo "Exception: \033[31m".$err; |
|
251 | + exit(); |
|
252 | + } else{ |
|
253 | + throw new Exception($err); |
|
254 | + } |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | protected static function test_connection($arr = null) |
258 | 258 | { |
259 | - if ($arr != null) { |
|
260 | - $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null; |
|
261 | - } else { |
|
262 | - $province_id = null; |
|
263 | - } |
|
264 | - self::setup_option(); |
|
265 | - $curl = curl_init(); |
|
266 | - curl_setopt_array($curl, [ |
|
267 | - CURLOPT_URL => self::$url.'/province'.$province_id, |
|
268 | - CURLOPT_RETURNTRANSFER => true, |
|
269 | - CURLOPT_ENCODING => '', |
|
270 | - CURLOPT_MAXREDIRS => 10, |
|
271 | - CURLOPT_TIMEOUT => 30, |
|
272 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
273 | - CURLOPT_CUSTOMREQUEST => 'GET', |
|
274 | - CURLOPT_HTTPHEADER => [ |
|
275 | - 'key: '.self::$api_key, |
|
276 | - ], |
|
277 | - ]); |
|
278 | - $response = curl_exec($curl); |
|
279 | - $err = curl_error($curl); |
|
280 | - |
|
281 | - curl_close($curl); |
|
282 | - |
|
283 | - if ($err) { |
|
284 | - $result = false; |
|
285 | - return $result; |
|
286 | - } else { |
|
287 | - $data = json_decode($response, false); |
|
288 | - if(!empty($data)){ |
|
289 | - $json = $data->rajaongkir; |
|
290 | - if ($json->status->code == '400') { |
|
291 | - $result = ['res' => $json->status->code,'success'=> false]; |
|
292 | - return $result; |
|
293 | - } else { |
|
294 | - $result = ['res' => "Connected to server.",'success'=> true]; |
|
295 | - return $result; |
|
296 | - } |
|
297 | - } else{ |
|
298 | - $result = ['res' => "Data is Empty.",'success'=> false]; |
|
299 | - return $result; |
|
300 | - } |
|
301 | - } |
|
302 | - } |
|
259 | + if ($arr != null) { |
|
260 | + $province_id = array_key_exists('province_id', $arr) ? '?id='.$arr['province_id'] : null; |
|
261 | + } else { |
|
262 | + $province_id = null; |
|
263 | + } |
|
264 | + self::setup_option(); |
|
265 | + $curl = curl_init(); |
|
266 | + curl_setopt_array($curl, [ |
|
267 | + CURLOPT_URL => self::$url.'/province'.$province_id, |
|
268 | + CURLOPT_RETURNTRANSFER => true, |
|
269 | + CURLOPT_ENCODING => '', |
|
270 | + CURLOPT_MAXREDIRS => 10, |
|
271 | + CURLOPT_TIMEOUT => 30, |
|
272 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
273 | + CURLOPT_CUSTOMREQUEST => 'GET', |
|
274 | + CURLOPT_HTTPHEADER => [ |
|
275 | + 'key: '.self::$api_key, |
|
276 | + ], |
|
277 | + ]); |
|
278 | + $response = curl_exec($curl); |
|
279 | + $err = curl_error($curl); |
|
280 | + |
|
281 | + curl_close($curl); |
|
282 | + |
|
283 | + if ($err) { |
|
284 | + $result = false; |
|
285 | + return $result; |
|
286 | + } else { |
|
287 | + $data = json_decode($response, false); |
|
288 | + if(!empty($data)){ |
|
289 | + $json = $data->rajaongkir; |
|
290 | + if ($json->status->code == '400') { |
|
291 | + $result = ['res' => $json->status->code,'success'=> false]; |
|
292 | + return $result; |
|
293 | + } else { |
|
294 | + $result = ['res' => "Connected to server.",'success'=> true]; |
|
295 | + return $result; |
|
296 | + } |
|
297 | + } else{ |
|
298 | + $result = ['res' => "Data is Empty.",'success'=> false]; |
|
299 | + return $result; |
|
300 | + } |
|
301 | + } |
|
302 | + } |
|
303 | 303 | } |
@@ -244,12 +244,12 @@ discard block |
||
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | -private static function exceptCurl($err){ |
|
248 | - if(php_sapi_name() == "cli"){ |
|
247 | +private static function exceptCurl($err) { |
|
248 | + if (php_sapi_name() == "cli") { |
|
249 | 249 | echo "Can't connect to server, please check your internet connection.\n"; |
250 | 250 | echo "Exception: \033[31m".$err; |
251 | 251 | exit(); |
252 | - } else{ |
|
252 | + } else { |
|
253 | 253 | throw new Exception($err); |
254 | 254 | } |
255 | 255 | } |
@@ -285,17 +285,17 @@ discard block |
||
285 | 285 | return $result; |
286 | 286 | } else { |
287 | 287 | $data = json_decode($response, false); |
288 | - if(!empty($data)){ |
|
288 | + if (!empty($data)) { |
|
289 | 289 | $json = $data->rajaongkir; |
290 | 290 | if ($json->status->code == '400') { |
291 | - $result = ['res' => $json->status->code,'success'=> false]; |
|
291 | + $result = ['res' => $json->status->code, 'success'=> false]; |
|
292 | 292 | return $result; |
293 | 293 | } else { |
294 | - $result = ['res' => "Connected to server.",'success'=> true]; |
|
294 | + $result = ['res' => "Connected to server.", 'success'=> true]; |
|
295 | 295 | return $result; |
296 | 296 | } |
297 | - } else{ |
|
298 | - $result = ['res' => "Data is Empty.",'success'=> false]; |
|
297 | + } else { |
|
298 | + $result = ['res' => "Data is Empty.", 'success'=> false]; |
|
299 | 299 | return $result; |
300 | 300 | } |
301 | 301 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - /* |
|
4 | + /* |
|
5 | 5 | |-------------------------------------------------------------------------- |
6 | 6 | | End Point Api ( Server Configuration ) |
7 | 7 | |-------------------------------------------------------------------------- |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | | Pro : http://pro.rajaongkir.com/api |
12 | 12 | | |
13 | 13 | */ |
14 | - 'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'), |
|
15 | - /* |
|
14 | + 'account_type' => env('RAJAONGKIR_ACCOUNT_TYPE', 'starter'), |
|
15 | + /* |
|
16 | 16 | |-------------------------------------------------------------------------- |
17 | 17 | | API key |
18 | 18 | |-------------------------------------------------------------------------- |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | | |
21 | 21 | */ |
22 | 22 | |
23 | - 'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'), |
|
24 | - /* |
|
23 | + 'api_key' => env('RAJAONGKIR_API_KEY', 'your-api-key'), |
|
24 | + /* |
|
25 | 25 | |-------------------------------------------------------------------------- |
26 | 26 | | API Version (for account type basic and pro) |
27 | 27 | |-------------------------------------------------------------------------- |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | | |
30 | 30 | */ |
31 | 31 | |
32 | - 'api_version' => env('RAJAONGKIR_API_VERSION', 'v2'), |
|
33 | - /* |
|
32 | + 'api_version' => env('RAJAONGKIR_API_VERSION', 'v2'), |
|
33 | + /* |
|
34 | 34 | |-------------------------------------------------------------------------- |
35 | 35 | | For Caching |
36 | 36 | |-------------------------------------------------------------------------- |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | | Cache supported database,and file. If you can't use cache, set value to null |
43 | 43 | */ |
44 | 44 | |
45 | - 'province_table' => env('RAJAONGKIR_PROV_TABLE', 'ro_province'), |
|
45 | + 'province_table' => env('RAJAONGKIR_PROV_TABLE', 'ro_province'), |
|
46 | 46 | |
47 | - 'city_table' => env('RAJAONGKIR_CITY_TABLE', 'ro_city'), |
|
47 | + 'city_table' => env('RAJAONGKIR_CITY_TABLE', 'ro_city'), |
|
48 | 48 | |
49 | - 'subdistrict_table' => env('RAJAONGKIR_SUBDISTRICT_TABLE', 'ro_subdistrict'), |
|
49 | + 'subdistrict_table' => env('RAJAONGKIR_SUBDISTRICT_TABLE', 'ro_subdistrict'), |
|
50 | 50 | |
51 | - 'cache_type' => env('RAJAONGKIR_CACHE', 'database'), |
|
51 | + 'cache_type' => env('RAJAONGKIR_CACHE', 'database'), |
|
52 | 52 | |
53 | 53 | ]; |
@@ -12,221 +12,221 @@ |
||
12 | 12 | |
13 | 13 | class Ongkir extends Api |
14 | 14 | { |
15 | - private static $arr; |
|
16 | - private static $return; |
|
17 | - private static $province; |
|
18 | - private static $city; |
|
19 | - private static $cacheType; |
|
20 | - |
|
21 | - public static function find($arr) |
|
22 | - { |
|
23 | - if (is_array($arr)) { |
|
24 | - self::$arr = $arr; |
|
25 | - |
|
26 | - return new static(); |
|
27 | - } else { |
|
28 | - throw new Exception('Parameter must be an array.'); |
|
29 | - |
|
30 | - return false; |
|
31 | - } |
|
32 | - } |
|
33 | - |
|
34 | - public static function get() |
|
35 | - { |
|
36 | - self::$arr = null; //Clear parameter |
|
37 | - if (empty(self::$return)) { |
|
38 | - throw new Exception('Data is not defined.'); |
|
39 | - |
|
40 | - return false; |
|
41 | - } |
|
42 | - $ret = self::$return; |
|
43 | - self::$return = null; |
|
44 | - |
|
45 | - return $ret; |
|
46 | - } |
|
47 | - |
|
48 | - public static function cachingProvince() |
|
49 | - { |
|
50 | - self::cacheProvince(); |
|
51 | - } |
|
52 | - |
|
53 | - public static function cachingSubDistrict() |
|
54 | - { |
|
55 | - if(strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
56 | - { |
|
57 | - echo "Tidak dapat mengambil SubDistrict dikarenakan akun yg anda pakai tipe starter."; |
|
58 | - return true; |
|
59 | - } |
|
60 | - $get = self::cityData(); |
|
61 | - $count = count($get); |
|
62 | - $i=0; |
|
63 | - echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m"; |
|
64 | - foreach($get as $city){ |
|
65 | - $i++; |
|
66 | - echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m"; |
|
67 | - echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL; |
|
68 | - self::cacheSubDistrict(['city' => $city->city_id]); |
|
69 | - echo PHP_EOL; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - public static function cachingCity() |
|
74 | - { |
|
75 | - self::cacheCity(); |
|
76 | - } |
|
77 | - |
|
78 | - public static function costDetails() |
|
79 | - { |
|
80 | - self::$return = self::get_cost_details(self::$arr); |
|
81 | - |
|
82 | - return new static(); |
|
83 | - } |
|
84 | - public static function testConnection() |
|
85 | - { |
|
86 | - self::$return = self::test_connection(self::$arr); |
|
87 | - |
|
88 | - return new static(); |
|
89 | - } |
|
90 | - |
|
91 | - public static function courier() |
|
92 | - { |
|
93 | - self::$return = self::get_courier(self::$arr); |
|
94 | - |
|
95 | - return new static(); |
|
96 | - } |
|
15 | + private static $arr; |
|
16 | + private static $return; |
|
17 | + private static $province; |
|
18 | + private static $city; |
|
19 | + private static $cacheType; |
|
20 | + |
|
21 | + public static function find($arr) |
|
22 | + { |
|
23 | + if (is_array($arr)) { |
|
24 | + self::$arr = $arr; |
|
25 | + |
|
26 | + return new static(); |
|
27 | + } else { |
|
28 | + throw new Exception('Parameter must be an array.'); |
|
29 | + |
|
30 | + return false; |
|
31 | + } |
|
32 | + } |
|
33 | + |
|
34 | + public static function get() |
|
35 | + { |
|
36 | + self::$arr = null; //Clear parameter |
|
37 | + if (empty(self::$return)) { |
|
38 | + throw new Exception('Data is not defined.'); |
|
39 | + |
|
40 | + return false; |
|
41 | + } |
|
42 | + $ret = self::$return; |
|
43 | + self::$return = null; |
|
44 | + |
|
45 | + return $ret; |
|
46 | + } |
|
47 | + |
|
48 | + public static function cachingProvince() |
|
49 | + { |
|
50 | + self::cacheProvince(); |
|
51 | + } |
|
52 | + |
|
53 | + public static function cachingSubDistrict() |
|
54 | + { |
|
55 | + if(strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
56 | + { |
|
57 | + echo "Tidak dapat mengambil SubDistrict dikarenakan akun yg anda pakai tipe starter."; |
|
58 | + return true; |
|
59 | + } |
|
60 | + $get = self::cityData(); |
|
61 | + $count = count($get); |
|
62 | + $i=0; |
|
63 | + echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m"; |
|
64 | + foreach($get as $city){ |
|
65 | + $i++; |
|
66 | + echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m"; |
|
67 | + echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL; |
|
68 | + self::cacheSubDistrict(['city' => $city->city_id]); |
|
69 | + echo PHP_EOL; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + public static function cachingCity() |
|
74 | + { |
|
75 | + self::cacheCity(); |
|
76 | + } |
|
77 | + |
|
78 | + public static function costDetails() |
|
79 | + { |
|
80 | + self::$return = self::get_cost_details(self::$arr); |
|
81 | + |
|
82 | + return new static(); |
|
83 | + } |
|
84 | + public static function testConnection() |
|
85 | + { |
|
86 | + self::$return = self::test_connection(self::$arr); |
|
87 | + |
|
88 | + return new static(); |
|
89 | + } |
|
90 | + |
|
91 | + public static function courier() |
|
92 | + { |
|
93 | + self::$return = self::get_courier(self::$arr); |
|
94 | + |
|
95 | + return new static(); |
|
96 | + } |
|
97 | 97 | |
98 | - public static function province() |
|
99 | - { |
|
100 | - $ret = self::provinceData(); |
|
101 | - self::$return = $ret; |
|
102 | - |
|
103 | - return new static(); |
|
104 | - } |
|
105 | - |
|
106 | - public static function subDistrict() |
|
107 | - { |
|
108 | - $ret = self::subDistrictData(); |
|
109 | - self::$return = $ret; |
|
110 | - |
|
111 | - return new static(); |
|
112 | - } |
|
113 | - public static function internationalOrigin() |
|
114 | - { |
|
115 | - $ret = self::internationalOriginData(); |
|
116 | - self::$return = $ret; |
|
117 | - |
|
118 | - return new static(); |
|
119 | - } |
|
120 | - |
|
121 | - public static function city() |
|
122 | - { |
|
123 | - $ret = self::cityData(); |
|
124 | - self::$return = $ret; |
|
125 | - |
|
126 | - return new static(); |
|
127 | - } |
|
128 | - |
|
129 | - private static function setupConfig() |
|
130 | - { |
|
131 | - self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type')); |
|
132 | - self::$province = config('irfa.rajaongkir.province_table'); |
|
133 | - self::$city = config('irfa.rajaongkir.city_table'); |
|
134 | - } |
|
135 | - |
|
136 | - private static function provinceData() |
|
137 | - { |
|
138 | - if (function_exists('config') && function_exists('app')) { |
|
139 | - self::setupConfig(); |
|
140 | - $cache_type = self::$cacheType; |
|
141 | - if ($cache_type == 'database') { |
|
142 | - if (ROCache::checkProv()) { |
|
143 | - if (count(ROCache::getProv(self::$arr)) > 0) { |
|
144 | - $ret = ROCache::getProv(self::$arr); |
|
145 | - } else { |
|
146 | - $ret = self::get_province(self::$arr); |
|
147 | - } |
|
148 | - } |
|
149 | - } elseif ($cache_type == 'file') { |
|
150 | - $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
151 | - if ($ret == null) { |
|
152 | - self::exceptionCache(); |
|
153 | - } |
|
154 | - } else { |
|
155 | - $ret = self::get_province(self::$arr); |
|
156 | - } |
|
157 | - } else { |
|
158 | - $ret = self::get_province(self::$arr); |
|
159 | - } |
|
160 | - |
|
161 | - return $ret; |
|
162 | - } |
|
163 | - private static function subDistrictData() |
|
164 | - { |
|
165 | - if (function_exists('config') && function_exists('app')) { |
|
166 | - self::setupConfig(); |
|
167 | - $cache_type = self::$cacheType; |
|
168 | - if ($cache_type == 'database') { |
|
169 | - if (ROCache::checkProv()) { |
|
170 | - if (count(ROCache::getSubdistrict(self::$arr)) > 0) { |
|
171 | - $ret = ROCache::getSubdistrict(self::$arr); |
|
172 | - } else { |
|
173 | - $ret = self::getSubdistrict(self::$arr); |
|
174 | - } |
|
175 | - } |
|
176 | - } elseif ($cache_type == 'file') { |
|
177 | - $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
178 | - if ($ret == null) { |
|
179 | - self::exceptionCache(); |
|
180 | - } |
|
181 | - } else { |
|
182 | - $ret = self::getSubdistrict(self::$arr); |
|
183 | - } |
|
184 | - } else { |
|
185 | - $ret = self::getSubdistrict(self::$arr); |
|
186 | - } |
|
187 | - |
|
188 | - return $ret; |
|
189 | - } |
|
190 | - private static function internationalOriginData() |
|
191 | - { |
|
98 | + public static function province() |
|
99 | + { |
|
100 | + $ret = self::provinceData(); |
|
101 | + self::$return = $ret; |
|
102 | + |
|
103 | + return new static(); |
|
104 | + } |
|
105 | + |
|
106 | + public static function subDistrict() |
|
107 | + { |
|
108 | + $ret = self::subDistrictData(); |
|
109 | + self::$return = $ret; |
|
110 | + |
|
111 | + return new static(); |
|
112 | + } |
|
113 | + public static function internationalOrigin() |
|
114 | + { |
|
115 | + $ret = self::internationalOriginData(); |
|
116 | + self::$return = $ret; |
|
117 | + |
|
118 | + return new static(); |
|
119 | + } |
|
120 | + |
|
121 | + public static function city() |
|
122 | + { |
|
123 | + $ret = self::cityData(); |
|
124 | + self::$return = $ret; |
|
125 | + |
|
126 | + return new static(); |
|
127 | + } |
|
128 | + |
|
129 | + private static function setupConfig() |
|
130 | + { |
|
131 | + self::$cacheType = strtolower(config('irfa.rajaongkir.cache_type')); |
|
132 | + self::$province = config('irfa.rajaongkir.province_table'); |
|
133 | + self::$city = config('irfa.rajaongkir.city_table'); |
|
134 | + } |
|
135 | + |
|
136 | + private static function provinceData() |
|
137 | + { |
|
138 | + if (function_exists('config') && function_exists('app')) { |
|
139 | + self::setupConfig(); |
|
140 | + $cache_type = self::$cacheType; |
|
141 | + if ($cache_type == 'database') { |
|
142 | + if (ROCache::checkProv()) { |
|
143 | + if (count(ROCache::getProv(self::$arr)) > 0) { |
|
144 | + $ret = ROCache::getProv(self::$arr); |
|
145 | + } else { |
|
146 | + $ret = self::get_province(self::$arr); |
|
147 | + } |
|
148 | + } |
|
149 | + } elseif ($cache_type == 'file') { |
|
150 | + $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
151 | + if ($ret == null) { |
|
152 | + self::exceptionCache(); |
|
153 | + } |
|
154 | + } else { |
|
155 | + $ret = self::get_province(self::$arr); |
|
156 | + } |
|
157 | + } else { |
|
158 | + $ret = self::get_province(self::$arr); |
|
159 | + } |
|
160 | + |
|
161 | + return $ret; |
|
162 | + } |
|
163 | + private static function subDistrictData() |
|
164 | + { |
|
165 | + if (function_exists('config') && function_exists('app')) { |
|
166 | + self::setupConfig(); |
|
167 | + $cache_type = self::$cacheType; |
|
168 | + if ($cache_type == 'database') { |
|
169 | + if (ROCache::checkProv()) { |
|
170 | + if (count(ROCache::getSubdistrict(self::$arr)) > 0) { |
|
171 | + $ret = ROCache::getSubdistrict(self::$arr); |
|
172 | + } else { |
|
173 | + $ret = self::getSubdistrict(self::$arr); |
|
174 | + } |
|
175 | + } |
|
176 | + } elseif ($cache_type == 'file') { |
|
177 | + $ret = ROCache::cacheFile(self::$province, self::$arr); |
|
178 | + if ($ret == null) { |
|
179 | + self::exceptionCache(); |
|
180 | + } |
|
181 | + } else { |
|
182 | + $ret = self::getSubdistrict(self::$arr); |
|
183 | + } |
|
184 | + } else { |
|
185 | + $ret = self::getSubdistrict(self::$arr); |
|
186 | + } |
|
187 | + |
|
188 | + return $ret; |
|
189 | + } |
|
190 | + private static function internationalOriginData() |
|
191 | + { |
|
192 | 192 | |
193 | - $ret = self::get_international_origin(self::$arr); |
|
193 | + $ret = self::get_international_origin(self::$arr); |
|
194 | 194 | |
195 | 195 | |
196 | - return $ret; |
|
197 | - } |
|
198 | - private static function cityData() |
|
199 | - { |
|
200 | - if (function_exists('config') && function_exists('app')) { |
|
201 | - self::setupConfig(); |
|
202 | - $cache_type = self::$cacheType; |
|
203 | - if ($cache_type == 'database') { |
|
204 | - if (ROCache::checkCity()) { |
|
205 | - if (count(ROCache::getCity(self::$arr)) > 0) { |
|
206 | - $ret = ROCache::getCity(self::$arr); |
|
207 | - } else { |
|
208 | - $ret = self::get_city(self::$arr); |
|
209 | - } |
|
210 | - } |
|
211 | - } elseif ($cache_type == 'file') { |
|
212 | - $ret = ROCache::cacheFile(self::$city, self::$arr); |
|
213 | - if ($ret == null) { |
|
214 | - self::exceptionCache(); |
|
215 | - } |
|
216 | - } else { |
|
217 | - $ret = self::get_city(self::$arr); |
|
218 | - } |
|
219 | - } else { |
|
220 | - $ret = self::get_city(self::$arr); |
|
221 | - } |
|
222 | - |
|
223 | - return $ret; |
|
224 | - } |
|
225 | - |
|
226 | - private static function exceptionCache() |
|
227 | - { |
|
228 | - throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache'); |
|
229 | - |
|
230 | - return false; |
|
231 | - } |
|
196 | + return $ret; |
|
197 | + } |
|
198 | + private static function cityData() |
|
199 | + { |
|
200 | + if (function_exists('config') && function_exists('app')) { |
|
201 | + self::setupConfig(); |
|
202 | + $cache_type = self::$cacheType; |
|
203 | + if ($cache_type == 'database') { |
|
204 | + if (ROCache::checkCity()) { |
|
205 | + if (count(ROCache::getCity(self::$arr)) > 0) { |
|
206 | + $ret = ROCache::getCity(self::$arr); |
|
207 | + } else { |
|
208 | + $ret = self::get_city(self::$arr); |
|
209 | + } |
|
210 | + } |
|
211 | + } elseif ($cache_type == 'file') { |
|
212 | + $ret = ROCache::cacheFile(self::$city, self::$arr); |
|
213 | + if ($ret == null) { |
|
214 | + self::exceptionCache(); |
|
215 | + } |
|
216 | + } else { |
|
217 | + $ret = self::get_city(self::$arr); |
|
218 | + } |
|
219 | + } else { |
|
220 | + $ret = self::get_city(self::$arr); |
|
221 | + } |
|
222 | + |
|
223 | + return $ret; |
|
224 | + } |
|
225 | + |
|
226 | + private static function exceptionCache() |
|
227 | + { |
|
228 | + throw new Exception('Cache file is empty. Try php artisan raja-ongkir:cache'); |
|
229 | + |
|
230 | + return false; |
|
231 | + } |
|
232 | 232 | } |
@@ -52,16 +52,16 @@ |
||
52 | 52 | |
53 | 53 | public static function cachingSubDistrict() |
54 | 54 | { |
55 | - if(strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
55 | + if (strtolower(config('irfa.rajaongkir.account_type')) == "starter") |
|
56 | 56 | { |
57 | 57 | echo "Tidak dapat mengambil SubDistrict dikarenakan akun yg anda pakai tipe starter."; |
58 | 58 | return true; |
59 | 59 | } |
60 | 60 | $get = self::cityData(); |
61 | 61 | $count = count($get); |
62 | - $i=0; |
|
62 | + $i = 0; |
|
63 | 63 | echo PHP_EOL."\033[42mThis may take longer, please wait.\033[0m"; |
64 | - foreach($get as $city){ |
|
64 | + foreach ($get as $city) { |
|
65 | 65 | $i++; |
66 | 66 | echo PHP_EOL."Remaining City\033[96m ".$i."/".$count."\033[0m"; |
67 | 67 | echo PHP_EOL."Get Subdistrict\033[96m ".$city->city_name."...\033[0m".PHP_EOL; |