Class: ChawkRemote::Addr

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/chawk_remote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, series_key, client_id, api_key) ⇒ Addr

Returns a new instance of Addr.



9
10
11
12
13
14
15
16
17
# File 'lib/chawk_remote.rb', line 9

def initialize(host, series_key, client_id, api_key)
  @host       = host
  @client_id  = client_id
  @api_key    = api_key
  @series_key = series_key

  #puts "#{@host} - #{@client_id} - #{@api_key} #{series_key}"

end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/chawk_remote.rb', line 7

def api_key
  @api_key
end

#client_idObject

Returns the value of attribute client_id.



7
8
9
# File 'lib/chawk_remote.rb', line 7

def client_id
  @client_id
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/chawk_remote.rb', line 7

def host
  @host
end

#series_keyObject

Returns the value of attribute series_key.



7
8
9
# File 'lib/chawk_remote.rb', line 7

def series_key
  @series_key
end

Instance Method Details

#add_points(points) ⇒ Object



23
24
25
26
27
# File 'lib/chawk_remote.rb', line 23

def add_points(points)
  r = HTTParty.post "#{@host}/api/v1/nodes/#{@series_key}/add_points", 
    :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""},
    :body => {"payload" => "{\"data\":[#{points.join(',')}]}", :meta => "{\"source\":\"chawk_remote\"}"}
end

#clearObject



19
20
21
# File 'lib/chawk_remote.rb', line 19

def clear
  r = HTTParty.put "#{@host}/api/v1/nodes/#{@series_key}/clear", :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
end

#decrement(count) ⇒ Object



35
36
37
38
39
# File 'lib/chawk_remote.rb', line 35

def decrement(count)
  r = HTTParty.put "#{@host}/api/v1/nodes/#{@series_key}/decrement", 
    :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""},
    :body => {"payload" => "{\"data\":#{count}}", :meta => "{\"source\":\"chawk_remote\"}"}
end

#increment(count) ⇒ Object



29
30
31
32
33
# File 'lib/chawk_remote.rb', line 29

def increment(count)
  r = HTTParty.put "#{@host}/api/v1/nodes/#{@series_key}/increment", 
    :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""},
    :body => {"payload" => "{\"data\":#{count}}", :meta => "{\"source\":\"chawk_remote\"}"}
end

#last(length) ⇒ Object



41
42
43
44
# File 'lib/chawk_remote.rb', line 41

def last(length)
  r = HTTParty.get "#{@host}/api/v1/nodes/#{@series_key}/last", 
    :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
end

#range(from, to) ⇒ Object



46
47
48
49
# File 'lib/chawk_remote.rb', line 46

def range(from, to)
  r = HTTParty.get "#{@host}/api/v1/nodes/#{@series_key}/range?from=#{from}&to=#{to}", 
    :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
end

#since(from) ⇒ Object



51
52
53
54
# File 'lib/chawk_remote.rb', line 51

def since (from)
  r = HTTParty.get "#{@host}/api/v1/nodes/#{@series_key}/since?from=#{from}", 
    :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
end