shipindo 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,15 @@ module Shipindo
4
4
 
5
5
  module ClassMethods
6
6
 
7
+ def find_city(options)
8
+ options[:carrier] ||= 'jne'
9
+
10
+ klass = find_carrier(options[:carrier])
11
+ city = klass.new.find_city(options[:name])
12
+
13
+ options.merge(city) if city
14
+ end
15
+
7
16
  def find_rates(options)
8
17
  # jne is default for 99% Indonesia online shop..
9
18
  options[:carrier] ||= 'jne'
@@ -17,10 +17,21 @@ module Shipindo::Carrier
17
17
  end
18
18
  end
19
19
 
20
+ def find_city(name)
21
+ city = list_city(name).first
22
+ city unless city[:code] == " null "
23
+ end
24
+
20
25
  def find_rates(options)
21
26
  if options[:origin] && options[:destination]
22
- options[:origin_code] = list_city(options[:origin]).first[:code]
23
- options[:destination_code] = list_city(options[:destination]).first[:code]
27
+
28
+ unless options[:origin_code]
29
+ options[:origin_code] = find_city(options[:origin])[:code]
30
+ end
31
+
32
+ unless options[:destination_code]
33
+ options[:destination_code] = find_city(options[:destination])[:code]
34
+ end
24
35
  # another jne server flunk, response city name is from request parameters,
25
36
  # if there isn't any eg. using only code if cities, then it's displayed as empty.
26
37
  options[:from] = options[:origin]
@@ -2,8 +2,8 @@ module Shipindo
2
2
  module Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 1
6
- TINY = 1
5
+ MINOR = 2
6
+ TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -25,6 +25,11 @@ class CarriersTest < Test::Unit::TestCase
25
25
  assert_equal 330_000, data[:response][:rates][0][:rate]
26
26
  end
27
27
 
28
+ should "find city" do
29
+ assert_equal("UERHMTAwMDBK", Shipindo.find_city(:name => 'padang')[:code])
30
+ assert_nil(Shipindo.find_city(:name => 'jogjakarta'))
31
+ end
32
+
28
33
  end
29
34
 
30
35
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - wynst
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-29 00:00:00 +07:00
17
+ date: 2010-07-30 00:00:00 +07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency