Module: Adafruit::IO::Client::Data
- Included in:
- Adafruit::IO::Client
- Defined in:
- lib/adafruit/io/client/data.rb
Instance Method Summary collapse
-
#data(*args) ⇒ Object
Get all data for a feed, may paginate.
-
#data_chart(*args) ⇒ Object
Get charting data for a feed.
-
#datum(*args) ⇒ Object
Get a single data point.
-
#last_data(*args) ⇒ Object
Move the stream processing pointer to and retrieve the last (newest) data point available.
-
#next_data(*args) ⇒ Object
Retrieve the next unprocessed data point.
-
#prev_data(*args) ⇒ Object
Retrieve the previously processed data point.
-
#send_batch_data(*args) ⇒ Object
Send a batch of data points.
-
#send_data(*args) ⇒ Object
Add data to a feed.
Instance Method Details
#data(*args) ⇒ Object
Get all data for a feed, may paginate.
68 69 70 71 72 73 74 |
# File 'lib/adafruit/io/client/data.rb', line 68 def data(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) query = get_query_from_arguments arguments, %w(start_time end_time limit) get api_url(username, 'feeds', feed_key, 'data'), query end |
#data_chart(*args) ⇒ Object
Get charting data for a feed.
77 78 79 80 81 82 83 |
# File 'lib/adafruit/io/client/data.rb', line 77 def data_chart(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) query = get_query_from_arguments arguments, %w(start_time end_time limit hours resolution) get api_url(username, 'feeds', feed_key, 'data', 'chart'), query end |
#datum(*args) ⇒ Object
Get a single data point.
86 87 88 89 90 91 92 |
# File 'lib/adafruit/io/client/data.rb', line 86 def datum(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) data_id = arguments.shift get api_url(username, 'feeds', feed_key, 'data', data_id) end |
#last_data(*args) ⇒ Object
Move the stream processing pointer to and retrieve the last (newest) data point available.
113 114 115 116 117 118 |
# File 'lib/adafruit/io/client/data.rb', line 113 def last_data(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) get api_url(username, 'feeds', feed_key, 'data', 'last') end |
#next_data(*args) ⇒ Object
Retrieve the next unprocessed data point.
95 96 97 98 99 100 |
# File 'lib/adafruit/io/client/data.rb', line 95 def next_data(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) get api_url(username, 'feeds', feed_key, 'data', 'next') end |
#prev_data(*args) ⇒ Object
Retrieve the previously processed data point. This method does not move the stream pointer.
104 105 106 107 108 109 |
# File 'lib/adafruit/io/client/data.rb', line 104 def prev_data(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) get api_url(username, 'feeds', feed_key, 'data', 'prev') end |
#send_batch_data(*args) ⇒ Object
Send a batch of data points.
Points can either be a list of strings, numbers, or hashes with the keys [ value, created_at OPTIONAL, lat OPTIONAL, lon OPTIONAL, ele OPTIONAL ]
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/adafruit/io/client/data.rb', line 50 def send_batch_data(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) values = arguments.shift if values.nil? || !values.is_a?(Array) raise "expected batch values to be an array" end if !values.first.is_a?(Hash) # convert values to hashes with single key: 'value' values = values.map {|val| {value: val}} end post api_url(username, 'feeds', feed_key, 'data', 'batch'), data: values end |
#send_data(*args) ⇒ Object
Add data to a feed.
Params:
- feed_key: string
- value: string or number
- location (optional): {lat: Number, lon: Number, ele: Number}
- created_at (optional): iso8601 date time string.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/adafruit/io/client/data.rb', line 14 def send_data(*args) username, arguments = extract_username(args) feed_key = get_key_from_arguments(arguments) value = arguments.shift attrs = { value: value } if arguments.size > 0 && arguments.first.is_a?(Hash) location = arguments.shift if location[:lat] && location[:lon] attrs[:lat] = location[:lat] attrs[:lon] = location[:lon] attrs[:ele] = location[:ele] end end if arguments.size > 0 if arguments.first.is_a?(String) created_at = arguments.shift attrs[:created_at] = created_at elsif arguments.first.is_a?(Time) created_at = arguments.shift attrs[:created_at] = created_at.utc.iso8601 end end post api_url(username, 'feeds', feed_key, 'data'), attrs end |