Sha256: 668394064fd27d901698c127d0465246be2c8ae929beabe0b5ab77876451dde7
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
require 'open-uri' require 'nokogiri' module TakuhaiStatus class JapanPost attr_reader :key, :time, :state def initialize(key) @key = key.gsub(/[^a-zA-Z0-9]/, '') @time, @state = check end def finish? return !!(@state =~ /差出人に返送済み|お届け済み|コンビニエンスストアに引渡|窓口でお渡し/) end private def check uri = "https://trackings.post.japanpost.jp/services/srv/search/direct?reqCodeNo1=#{@key}" doc = Nokogiri(open(uri, &:read)) begin begin # japanese baggage cols = doc.css('.tableType01')[1].css('tr') col = cols[cols.size - 2] stime = col.css('td')[0].text time = Time.parse(stime) station = " [#{col.css('td')[3].text}]" station = " [#{col.css('td')[4].text.strip}]" if station.size <= 4 station = "" if station.size <= 4 state = "#{col.css('td')[1].text}#{station}" rescue NoMethodError # international baggage cols = doc.css('.tableType01 tr') col = cols[cols.size - 2] stime = col.css('td')[2].text time = Time.parse(stime) station = " [#{col.css('td')[4].text}/#{col.css('td')[5].text}]" state = "#{col.css('td')[3].text}#{station}" end return time, state rescue NoMethodError raise NotMyKey rescue ArgumentError return Time.now, '' end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
takuhai_status-1.5.1 | lib/takuhai_status/japanpost.rb |
takuhai_status-1.5.0 | lib/takuhai_status/japanpost.rb |
takuhai_status-1.4.2 | lib/takuhai_status/japanpost.rb |