rajaongkir 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rajaongkir.rb +15 -15
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a02359679ba0d07a19a50b82cfc97844aff06411
4
- data.tar.gz: 1b58fdc9b623c3173a549026b553db6a9460b752
3
+ metadata.gz: 3913666ea8fc38b8382896ef17c6d50f11793b6a
4
+ data.tar.gz: dd33cddea57c84c1d56d20021df284c353232f73
5
5
  SHA512:
6
- metadata.gz: eca89b9edb049e831605b2cde018677885770ed5418b886c9354cf38e5d6ef63c3aa44bda3ff7e40534dd797ca55a1fd7f478befa8a50280b0daefeed2716a36
7
- data.tar.gz: 3dcb7daa2a79942ee0fb85667d7e2d02e9173a7d11e453b0b318fdeccbcf8202882d53cfd1849db2989df0c79f437d206e844ac1262b6bf777b5ac951950de60
6
+ metadata.gz: 0168a4bcc3e63fde9165c1daf5f29591a28ed6719cf5d000c6213f03c715707723596b3c0bb0ea1693ed2a35cfdd70f38690567327a595d6bfc0a6c88617fc17
7
+ data.tar.gz: c16f558c50d30104431421b9aea24d97f1e5ead0e0312e5625d5defd9d331361d96e00ffd730d557a6f0366c917902ec33cf503d8dc7f5fcf083f25914f3b0ee
@@ -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 key
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), jika nil maka tampilkan semua kurir
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
- $response = Unirest.send(
49
- http_method.to_sym,
50
- $base_url + function,
51
- headers:{"key" => $key},
52
- parameters: params
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rajaongkir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Yunanto