class Atlas::Client
Constants
- API
Attributes
key[RW]
Public Class Methods
new(key = nil)
click to toggle source
# File lib/ripe-atlas/client.rb, line 7 def initialize(key = nil) if key.is_a? String and key != nil send("key=", key) end end
Public Instance Methods
get_measurement(id)
click to toggle source
# File lib/ripe-atlas/client.rb, line 46 def get_measurement(id) @url = API + "measurement/#{id}/" @res = RestClient.get(@url, {:accept => :json}) if @res.code == 200 @json = JSON.parse @res.body end @measurement = Atlas::Measurement.new(@json["object"]) return @measurement end
get_measurements(p)
click to toggle source
# File lib/ripe-atlas/client.rb, line 41 def get_measurements(p) @measurements = get_object("measurement", p) return @measurements end
get_object(type, p)
click to toggle source
# File lib/ripe-atlas/client.rb, line 13 def get_object(type, p) @url = API + "#{type}/" @res = RestClient.get(@url, {:accept => :json, :params => p}) if @res.code == 200 @json = JSON.parse @res.body end @objects = Array.new @json["objects"].each do |n| case type when "probe" @objects << Atlas::Probe.new(n) when "measurement" @objects << Atlas::Measurement.new(n) else raise "F*** you all!" end end return @objects end
get_probes(p)
click to toggle source
# File lib/ripe-atlas/client.rb, line 36 def get_probes(p) @probes = get_object("probe", p) return @probes end
stop_measurement(id)
click to toggle source
# File lib/ripe-atlas/client.rb, line 58 def stop_measurement(id) if self.key == nil raise "Specify an API key!" end @url = API + "measurement/" + "#{id}/" + "?key=" + self.key @res = RestClient.delete(@url) p @res puts @res.code if @res.code == 204 return true else return false end end