Class: AmbientIot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ambient_iot/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel_id, options = {}) ⇒ Client

Returns a new instance of Client.



31
32
33
34
35
36
37
38
39
# File 'lib/ambient_iot/client.rb', line 31

def initialize channel_id, options={}
  @channel_id = channel_id
  @write_key = options[:write_key]
  @read_key = options[:read_key]
  @user_key = options[:user_key]

  @post_data = []
  @append_timestamp = true
end

Instance Method Details

#<<(data) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/ambient_iot/client.rb', line 41

def << data
  data = [data] unless data.is_a? Array
  if append_timestamp?
    now = time_to_s Time.now
    data.each{|d| d["created"] = now}
  end
  @post_data += data
end

#append_timestamp=(flag) ⇒ Object



54
55
56
# File 'lib/ambient_iot/client.rb', line 54

def append_timestamp= flag
  @append_timestamp = flag
end

#append_timestamp?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ambient_iot/client.rb', line 50

def append_timestamp?
  @append_timestamp
end

#infoObject Also known as: prop, property



68
69
70
# File 'lib/ambient_iot/client.rb', line 68

def info
  get_property
end

#read(options = {}) ⇒ Object



64
65
66
# File 'lib/ambient_iot/client.rb', line 64

def read options={}
  get options
end

#writeObject Also known as: sync, synchronize



58
59
60
# File 'lib/ambient_iot/client.rb', line 58

def write
  post
end