Sha256: 24cb188c242d101c9614fc2b07256dd0a2e4ef231e191103b946c05b87c7aad6

Contents?: true

Size: 820 Bytes

Versions: 16

Compression:

Stored size: 820 Bytes

Contents

require 'faraday'
require 'nokogiri'

module TakuhaiStatus
	class KuronekoYamato
		attr_reader :key, :time, :state

		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://toi.kuronekoyamato.co.jp/')
			res = conn.post('/cgi-bin/tneko', {number00: '1', number01: @key})
			doc = Nokogiri(res.body)

			begin
				tr = doc.css('.meisai')[0].css('tr').last
				state = tr.css('td')[1].text
				sday = tr.css('td')[2].text
				stime = tr.css('td')[3].text
				time = Time.parse("#{sday} #{stime}")

				return time, state
			rescue NoMethodError
				raise NotMyKey
			rescue ArgumentError
				return Time.now, state || ''
			end
		end
	end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
takuhai_status-1.5.3 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.5.2 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.5.1 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.5.0 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.4.2 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.4.1 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.4.0 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.3.2 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.3.1 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.3.0 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.2.0 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.1.3 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.1.2 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.1.1 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.1.0 lib/takuhai_status/kuronekoyamato.rb
takuhai_status-1.0.0 lib/takuhai_status/kuronekoyamato.rb