Sha256: da9c627e0ed1aeef94b76e32ec99e082b36c39973f142a470e2ed44be50d9c1b

Contents?: true

Size: 909 Bytes

Versions: 20

Compression:

Stored size: 909 Bytes

Contents

require 'faraday'
require 'faraday/cookie_jar'
require 'nokogiri'

module TakuhaiStatus
	class TMGCargo
		attr_reader :key, :time, :state
		@@conn = nil

		def initialize(key)
			@key = key.gsub(/[^0-9]/, '')
			@time, @state = check
		end

		def finish?
			return !!(@state =~ /配達完了|返品/)
		end

	private
		def check
			@@conn = Faraday.new(url: 'http://track-a.tmg-group.jp'){|builder|
				builder.use :cookie_jar
				builder.request :url_encoded
				builder.adapter :net_http
			} unless @@conn
			@@conn.get('/cts/TmgCargoSearchAction.do')
			res = @@conn.post('/cts/TmgCargoSearchAction.do', {
				'inputData[0].inq_no' => @key,
				'method_id' => 'POPUPSEA'
			})
			doc = Nokogiri(res.body)
			begin
				state = doc.css('#list tr td')[2].text.strip
				raise if state =~ /お荷物情報が見つかりません/
				return Time.now, state
			rescue
				raise NotMyKey
			end
		end
	end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
takuhai_status-1.7.4 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.7.3 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.7.2 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.7.1 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.7.0 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.6.0 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.5.5 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.5.4 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.5.3 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.5.2 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.5.1 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.5.0 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.4.2 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.4.1 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.4.0 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.3.2 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.3.1 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.3.0 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.2.0 lib/takuhai_status/tmg_cargo.rb
takuhai_status-1.1.3 lib/takuhai_status/tmg_cargo.rb