rajaongkir 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rajaongkir.rb +15 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3913666ea8fc38b8382896ef17c6d50f11793b6a
|
4
|
+
data.tar.gz: dd33cddea57c84c1d56d20021df284c353232f73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0168a4bcc3e63fde9165c1daf5f29591a28ed6719cf5d000c6213f03c715707723596b3c0bb0ea1693ed2a35cfdd70f38690567327a595d6bfc0a6c88617fc17
|
7
|
+
data.tar.gz: c16f558c50d30104431421b9aea24d97f1e5ead0e0312e5625d5defd9d331361d96e00ffd730d557a6f0366c917902ec33cf503d8dc7f5fcf083f25914f3b0ee
|
data/lib/rajaongkir.rb
CHANGED
@@ -5,8 +5,9 @@ require 'unirest'
|
|
5
5
|
# http://rajaongkir.com/dokumentasi
|
6
6
|
|
7
7
|
class Rajaongkir
|
8
|
+
|
8
9
|
# key = API KEY dari rajaongkir
|
9
|
-
def initialize
|
10
|
+
def initialize(key = nil)
|
10
11
|
$key = key
|
11
12
|
$base_url = "http://rajaongkir.com/api/"
|
12
13
|
end
|
@@ -16,8 +17,6 @@ class Rajaongkir
|
|
16
17
|
# params = {'province' => '6', 'id' => '161'}
|
17
18
|
def city(params = nil)
|
18
19
|
execute "city",params
|
19
|
-
|
20
|
-
$response
|
21
20
|
end
|
22
21
|
|
23
22
|
# fungsi untuk mendapatkan data provinsi
|
@@ -25,8 +24,6 @@ class Rajaongkir
|
|
25
24
|
# params = {'id' => '6'}
|
26
25
|
def province(params = nil)
|
27
26
|
execute "province", params
|
28
|
-
|
29
|
-
$response
|
30
27
|
end
|
31
28
|
|
32
29
|
# fungsi untuk mendapatkan data ongkos kirim
|
@@ -34,22 +31,25 @@ class Rajaongkir
|
|
34
31
|
# origin ID kota asal
|
35
32
|
# destination ID kota tujuan
|
36
33
|
# weight Berat kiriman dalam gram
|
37
|
-
# courier Kode kurir (jne, pos, tiki)
|
38
|
-
def cost(origin, destination, weight, courier)
|
34
|
+
# courier Kode kurir (jne, pos, tiki)
|
35
|
+
def cost(origin, destination, weight, courier = 'pos')
|
39
36
|
params = {:origin => origin, :destination => destination, :weight => weight, :courier => courier}
|
40
37
|
|
41
38
|
execute "cost", params, 'post'
|
42
|
-
|
43
|
-
$response
|
44
39
|
end
|
45
40
|
|
41
|
+
# fungsi untuk mengirimkan request ke rajaongkir
|
46
42
|
private
|
47
43
|
def execute(function, params = nil, http_method = 'get')
|
48
|
-
$
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
if $key.nil? || $key == ''
|
45
|
+
return "API-KEY tidak boleh kosong"
|
46
|
+
else
|
47
|
+
return Unirest.send(
|
48
|
+
http_method.to_sym,
|
49
|
+
$base_url + function,
|
50
|
+
headers:{"key" => $key},
|
51
|
+
parameters: params
|
52
|
+
)
|
53
|
+
end
|
54
54
|
end
|
55
55
|
end
|