Class: Shipindo::Carrier::Jne
- Inherits:
-
Object
- Object
- Shipindo::Carrier::Jne
- Defined in:
- lib/shipindo/carriers/jne.rb
Instance Method Summary collapse
Instance Method Details
#find_city(name) ⇒ Object
20 21 22 23 |
# File 'lib/shipindo/carriers/jne.rb', line 20 def find_city(name) city = list_city(name).first city unless city[:code] == " null " end |
#find_rates(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shipindo/carriers/jne.rb', line 25 def find_rates() if [:origin] && [:destination] unless [:origin_code] [:origin_code] = find_city([:origin])[:code] end unless [:destination_code] [:destination_code] = find_city([:destination])[:code] end # another jne server flunk, response city name is from request parameters, # if there isn't any eg. using only code if cities, then it's displayed as empty. [:from] = [:origin] [:to] = [:destination] end unless [:origin_code] && [:destination_code] raise(ArgumentError, "origin & destination or code must be defined") end [:weight] ||= 1 resp = RestClient.post "http://www.jne.co.id/index.php?mib=tariff&lang=IN", doc = Nokogiri::HTML.parse(resp.body) [:response] = parse_rates(doc) end |
#list_city(query, limit = 1) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/shipindo/carriers/jne.rb', line 10 def list_city(query, limit=1) # bug in JNE server, limit parameter is ignored resp = RestClient.get "http://www.jne.co.id/tariff.php?q=#{ query }&limit=#{ limit }" resp.body.split("\r\n").map do |item| city, code = item.split("|") { :city => city, :code => code } end end |