class MotionConcierge
Public Class Methods
check_interval()
click to toggle source
# File lib/project/motion-concierge.rb, line 48 def check_interval debug? ? debug_fetch_interval : fetch_interval end
debug=(debug)
click to toggle source
Debugging
# File lib/project/motion-concierge.rb, line 100 def debug=(debug) @_debug = !!debug end
debug?()
click to toggle source
# File lib/project/motion-concierge.rb, line 104 def debug? @_debug || false end
debug_fetch_interval()
click to toggle source
# File lib/project/motion-concierge.rb, line 32 def debug_fetch_interval @_debug_fetch_interval || 30 end
debug_fetch_interval=(interval)
click to toggle source
# File lib/project/motion-concierge.rb, line 28 def debug_fetch_interval=(interval) @_debug_fetch_interval = interval end
downloaded_file_exists?()
click to toggle source
# File lib/project/motion-concierge.rb, line 44 def downloaded_file_exists? local_file_path.file_exists? end
fetch()
click to toggle source
# File lib/project/motion-concierge.rb, line 60 def fetch if debug? puts "Fetching data from: #{@_remote_file_url}" puts " Saving it to: #{local_file_name}" puts " Every #{check_interval} seconds" end if should_fetch? puts "Data is #{time_offset} seconds old.\nDownloading new data file." if debug? AFMotion::HTTP.get(@_remote_file_url) do |result| if result.success? puts 'Got successful result from server.' if debug? result.object.write_to(local_file_path) last_fetch = Time.now.to_i NSNotificationCenter.defaultCenter.postNotificationName("MotionConciergeNewDataReceived", object:self) else if debug? puts "There was an error downloading the data from the server:" puts result.error.localizedDescription end end end else puts "Data is not stale. Not fetching." if debug? end end
fetch_interval()
click to toggle source
# File lib/project/motion-concierge.rb, line 24 def fetch_interval @_fetch_interval || 86400 end
fetch_interval=(interval)
click to toggle source
# File lib/project/motion-concierge.rb, line 20 def fetch_interval=(interval) @_fetch_interval = interval end
last_fetch()
click to toggle source
# File lib/project/motion-concierge.rb, line 94 def last_fetch NSUserDefaults.standardUserDefaults.integerForKey("motion_concierge_last_data_check") || 0 end
last_fetch=(last)
click to toggle source
# File lib/project/motion-concierge.rb, line 87 def last_fetch=(last) NSUserDefaults.standardUserDefaults.tap do |defaults| defaults.setInteger(last, forKey:"motion_concierge_last_data_check") defaults.synchronize end end
local_file_name()
click to toggle source
# File lib/project/motion-concierge.rb, line 8 def local_file_name @_local_file_name || @_remote_file_url.split("/").last end
local_file_name=(file_name)
click to toggle source
# File lib/project/motion-concierge.rb, line 4 def local_file_name=(file_name) @_local_file_name = file_name end
local_file_path()
click to toggle source
# File lib/project/motion-concierge.rb, line 36 def local_file_path local_file_name.document_path end
local_file_string()
click to toggle source
# File lib/project/motion-concierge.rb, line 40 def local_file_string NSString.stringWithContentsOfFile(local_file_path) end
remote_file_url()
click to toggle source
# File lib/project/motion-concierge.rb, line 16 def remote_file_url @_remote_file_url end
remote_file_url=(url)
click to toggle source
# File lib/project/motion-concierge.rb, line 12 def remote_file_url=(url) @_remote_file_url = url end
should_fetch?()
click to toggle source
# File lib/project/motion-concierge.rb, line 56 def should_fetch? last_fetch < time_offset end
time_offset()
click to toggle source
# File lib/project/motion-concierge.rb, line 52 def time_offset Time.now.to_i - check_interval end