class DeviceCloud::DataStreamClient
Attributes
client[RW]
last_updated[R]
parsed_cache[R]
raw_cache[R]
ttl[RW]
Public Class Methods
new(config, client = nil)
click to toggle source
# File lib/device_cloud/data_stream_client.rb, line 9 def initialize(config, client = nil) @client = client || Client.new(config) @ttl = config["ttl"] || 60 @last_updated = nil end
Public Instance Methods
cache()
click to toggle source
# File lib/device_cloud/data_stream_client.rb, line 39 def cache if !valid? || parsed_cache.nil? # We need to update the cache # Get all streams, and we will parse it out using xpath. @raw_cache = client.get DataStream::RESOURCE_PATH @parsed_cache = DataStream.parse raw_cache #get the thing @last_updated = Time.now end parsed_cache end
devices()
click to toggle source
# File lib/device_cloud/data_stream_client.rb, line 22 def devices cache.map do |stream| { device_id: stream.device_id, path: stream.path } end.uniq end
invalidate()
click to toggle source
# File lib/device_cloud/data_stream_client.rb, line 31 def invalidate @last_updated = nil end
match(regex)
click to toggle source
match the stream_id against regex
# File lib/device_cloud/data_stream_client.rb, line 16 def match(regex) cache.select do |stream| stream.stream_id.match regex end end
valid?()
click to toggle source
# File lib/device_cloud/data_stream_client.rb, line 35 def valid? !@last_updated.nil? and (Time.now - @ttl) < @last_updated end