rajaongkir 0.1.2.1 → 0.1.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rajaongkir.rb +42 -4
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82d2b0f839c48a3e211e954b6bd6be0fccd624d7
4
- data.tar.gz: cbd5250d079a3a91aad95a99a47f950abaf40247
3
+ metadata.gz: 9a1b21b5c408cb35b14c53a0392bd94c4b2794f7
4
+ data.tar.gz: 9a9df072ad21fccb19d343dc6dffcda73d8a9036
5
5
  SHA512:
6
- metadata.gz: f5283ca7c718a17ec9f3bea07a4d28bb5ca8e056a1c62e671f1c9486c1742795084d5aef5aa6bb18d8bfcb9df1998f60687ade91399e0e3521ef7a52406df1d6
7
- data.tar.gz: c9ecd3315bc71b3fbac60859bb7179f54db91c6df2bfbcd2999b0873bc660fdcdd2f121a685cd456072dd054886210e608eb270f910d2f9bd26edf28e6575c10
6
+ metadata.gz: 4919f9b4a0d34279a98e91aebf1e92ecafff0bae87203120b5756d3d2ed8ce413a04456b9f9c9add473313388020dc2674cf56529c6066dbb44aba03b5f9bbc3
7
+ data.tar.gz: 02df35a3b1201f9d97e95d94304688ba3cc7380aaac3eb11054abdaa86a567a9283b14d1b061588e97846038d13a10ea0141e01b1e036797eca0e239b9616d2d
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'unirest'
3
+ require File.join(File.dirname(__FILE__), "response.rb")
3
4
 
4
5
  # simple class ruby untuk API Rajaongkir
5
6
  # http://rajaongkir.com/dokumentasi
@@ -13,6 +14,16 @@ class Rajaongkir
13
14
  @base_url = "http://rajaongkir.com/api/"
14
15
  end
15
16
 
17
+ # fungsi untuk mendapatkan API-KEY
18
+ def get_key
19
+ @key
20
+ end
21
+
22
+ # fungsi untuk mendapatkan base_url
23
+ def get_base_url
24
+ $base_url
25
+ end
26
+
16
27
  # fungsi untuk mendapatkan data kota
17
28
  #
18
29
  # params = {'province' => '6', 'id' => '161'}
@@ -33,17 +44,44 @@ class Rajaongkir
33
44
  # destination ID kota tujuan
34
45
  # weight Berat kiriman dalam gram
35
46
  # courier Kode kurir (jne, pos, tiki)
36
- def cost(origin, destination, weight, courier = 'pos')
37
- params = {:origin => origin, :destination => destination, :weight => weight, :courier => courier}
47
+ def cost(origin = '', destination = '', weight = 0, courier = 'pos')
48
+ error_message = Hash.new
49
+
50
+ if origin == ''
51
+ error = 1
52
+ error_message['origin'] = 'origin tidak boleh kosong'
53
+ end
54
+ if destination == ''
55
+ error = 1
56
+ error_message['destination'] = 'destination tidak boleh kosong'
57
+ end
58
+ if weight == 0
59
+ error = 1
60
+ error_message['weight'] = 'weight harus lebih besar dari 0'
61
+ end
62
+
63
+ if error == 1
64
+ params = Hash.new
65
+ params['code'] = 500
66
+ params['body'] = error_message
67
+ data_return = Response.new params
38
68
 
39
- request "cost", params, 'post'
69
+ return data_return
70
+ else
71
+ params = {:origin => origin, :destination => destination, :weight => weight, :courier => courier}
72
+
73
+ request "cost", params, 'post'
74
+ end
40
75
  end
41
76
 
42
77
  # fungsi untuk mengirimkan request ke rajaongkir
43
78
  private
44
79
  def request(function, params = nil, http_method = 'get')
45
80
  if @key.nil? || @key == ''
46
- return "API-KEY tidak boleh kosong"
81
+ params = Hash.new
82
+ params['code'] = 500
83
+ params['body'] = {"error" => "API-KEY tidak boleh kosong"}
84
+ data_return = Response.new params
47
85
  else
48
86
  return Unirest.send(
49
87
  http_method.to_sym,
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.2.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Yunanto
@@ -41,9 +41,9 @@ require_paths:
41
41
  - lib
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '2.0'
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="