module Himawari::NetUtils

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)

Public Instance Methods

internet_connection?() click to toggle source

Checks our connection and as a bonus… @return [DateTime] timestamp of the latest himawari image; also as a side-efffect:

true, false whether we even have connection to the website
# 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

Private Instance Methods

blacklisted_wifi?() click to toggle source

Sometimes we don't want to use a particular network to download large amounts of data… @return [true, false] whether the current (wifi) network is blacklisted in the blacklist_wifi [Array]

# File lib/himawari/net_utils.rb, line 26
def blacklisted_wifi?
  current_wifi = case OsUtils.os
                 when :mac
                   `networksetup -getairportnetwork en0`
                 when :linux
                   `iwgetid -r`
                 end
  puts current_wifi if verbose
  current_wifi && blacklist_wifi.any? { |wifi| current_wifi.include?(wifi) }
end