class Databox::Client
Attributes
last_push_content[RW]
Public Class Methods
new()
click to toggle source
# File lib/databox/client.rb, line 14 def initialize Databox.configure unless Databox.configured? self.class.base_uri push_host self.class.basic_auth push_token, '' self.class.headers 'Content-Type' => 'application/json' self end
Public Instance Methods
handle(response)
click to toggle source
# File lib/databox/client.rb, line 36 def handle(response) response.parsed_response end
insert_all(rows=[])
click to toggle source
# File lib/databox/client.rb, line 63 def insert_all(rows=[]) self.last_push_content = raw_push('/', rows.map {|r| process_kpi(r) }) self.last_push_content.key?('id') end
last_push(n=1)
click to toggle source
# File lib/databox/client.rb, line 68 def last_push(n=1) handle self.class.get("/lastpushes?limit=#{n}") end
process_kpi(options={})
click to toggle source
# File lib/databox/client.rb, line 40 def process_kpi(options={}) %i{key value}.each do |k| raise("Missing '#{k}'") if (options[k] || options[k.to_s]).nil? end options["$#{(options['key'] || options[:key])}"] = options['value'] || options[:value] options.delete_if { |k, _| [:key, 'key', :value, 'value'].include?(k) } attributes = options[:attributes] || options['attributes'] unless attributes.nil? [:attributes, 'attributes'].each {|k| options.delete(k) } attributes.each { |k,v| options[k] = v } end options end
push(kpi={})
click to toggle source
# File lib/databox/client.rb, line 58 def push(kpi={}) self.last_push_content = raw_push('/', [process_kpi(kpi)]) self.last_push_content.key?('id') end
push_host()
click to toggle source
# File lib/databox/client.rb, line 23 def push_host Databox.configuration.push_host end
push_token()
click to toggle source
# File lib/databox/client.rb, line 27 def push_token Databox.configuration.push_token end
raw_push(path='/', data=nil)
click to toggle source
Sends data to actual end-point.
# File lib/databox/client.rb, line 32 def raw_push(path='/', data=nil) handle self.class.post(path, data.nil? ? {} : {body: JSON.dump({data: data})}) end