Module: Himawari::NetUtils

Included in:
Download
Defined in:
lib/himawari/net_utils.rb

Overview

Network-related methods to help establish whether there is network access and figure out if we are on a possibly “metered” connection (via a hard-coded SSID blacklist)

Instance Method Summary collapse

Instance Method Details

#internet_connection?DateTime

Checks our connection and as a bonus…

Returns:

  • (DateTime)

    timestamp of the latest himawari image; also as a side-efffect: true, false whether we even have connection to the website



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/himawari/net_utils.rb', line 10

def internet_connection?
  uid = now.to_i * 1_000
  r = HTTParty.get("#{HIMAWARI_URL}/latest.json?uid=#{uid}", { timeout: 10 })
  # puts "#{HIMAWARI_URL}/latest.json?uid=#{uid}" if verbose
  if r.code == 200
    puts "Latest Himawari: #{r['date']}" if verbose
    @latest_remote = Time.parse("#{r['date']}+00:00")
    return true
  end
  false
end