class Pingdom::Base
Attributes
additional_field[RW]
Public Class Methods
all()
click to toggle source
# File lib/pingdom/base.rb, line 16 def all parse client.get( params: params , path: path ) collection.map do |data| self.new data end end
body()
click to toggle source
# File lib/pingdom/base.rb, line 60 def body @@body end
client()
click to toggle source
# File lib/pingdom/base.rb, line 52 def client @@client end
collection()
click to toggle source
# File lib/pingdom/base.rb, line 76 def collection body[path[1..-1]] end
collection_type()
click to toggle source
# File lib/pingdom/base.rb, line 43 def collection_type path[1..-2] end
error?()
click to toggle source
# File lib/pingdom/base.rb, line 56 def error? body.has_key?'error' end
find(id, *args)
click to toggle source
# File lib/pingdom/base.rb, line 23 def find id, *args validator=Pingdom::Validator.new @@params=validator.validate input: args, permit: permit, params: params parse client.get( path: "#{path}/#{id}" , params: params) @@params={} raise "#{id} not found" if status!=200 self.new body[collection_type] end
limited()
click to toggle source
# File lib/pingdom/base.rb, line 84 def limited body['counts']['limited'] end
new(data)
click to toggle source
# File lib/pingdom/base.rb, line 92 def initialize data @additional_field={} data.each_pair do |k,v| v=Time.at(v) if is_time_attribute?(k) method="#{k}=".to_sym if self.methods.include?(method) self.send(method,v) else self.add(k, v) end end end
params()
click to toggle source
# File lib/pingdom/base.rb, line 68 def params @@params end
params=(value)
click to toggle source
# File lib/pingdom/base.rb, line 72 def params= value @@params=value end
parse(response)
click to toggle source
# File lib/pingdom/base.rb, line 47 def parse response @@body= JSON.parse response.body @@status = response.status end
path()
click to toggle source
# File lib/pingdom/base.rb, line 36 def path end
permit()
click to toggle source
# File lib/pingdom/base.rb, line 39 def permit {} end
status()
click to toggle source
# File lib/pingdom/base.rb, line 64 def status @@status end
total()
click to toggle source
# File lib/pingdom/base.rb, line 80 def total body['counts']['total'] end
update_client(username: , password: , key: @@client = Client.new u: username, p: password, k: key)
click to toggle source
# File lib/pingdom/base.rb, line 12 def update_client username: , password: , key: @@client = Client.new u: username, p: password, k: key end
Public Instance Methods
add(key, value)
click to toggle source
# File lib/pingdom/base.rb, line 106 def add key, value additional_field[key.to_sym]=value end
get(key)
click to toggle source
# File lib/pingdom/base.rb, line 110 def get key key=key.to_sym if self.methods.include?(key) self.send key else additional_field[key] end end
Private Instance Methods
is_time_attribute?(key)
click to toggle source
# File lib/pingdom/base.rb, line 124 def is_time_attribute? key time_attributes.include?(key) end
time_attributes()
click to toggle source
# File lib/pingdom/base.rb, line 120 def time_attributes [] end