Class: Tigre::Occurrence

Inherits:
Object
  • Object
show all
Defined in:
lib/tigre-client/occurrence.rb

Class Method Summary collapse

Class Method Details

.all(hash) ⇒ Object

returns all the occurrences for a given URL required params

hash => Hash
  :digest => String, the digest type you wish to use
  :value  => String, the value of the URLs digest you are using


22
23
24
25
26
27
28
# File 'lib/tigre-client/occurrence.rb', line 22

def self.all(hash)
  unless hash[:digest] && hash[:value]
    raise 'Missing parameter :digest, :value'
  end
  
  Tigre.get_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}/occurrences")
end

.for_sha(sha256) ⇒ Object

DEPRECATED => Use Tigre::Occurrence.all(hash)

return all the occurrences for a given sha256 URL required params

sha256 => String


10
11
12
13
14
15
# File 'lib/tigre-client/occurrence.rb', line 10

def self.for_sha(sha256)
  Tigre.logger.warn "** DEPRECATED ** Use Tigre::Occurrence.all(:digest => 'sha256', :value => 'your-sha256')" if Tigre.logger
  
  raise "Missing sha256 parameter" if sha256 == ''
  self.all(:digest => 'sha256', :value => sha256)
end

.get(hash, occurrence_id = nil) ⇒ Object

return an individual occurrence for a given sha256 URL required params

sha256 => String ** DEPRECATED **
occurrence_id => String ** DEPRECATED **
hash => Hash
  :digest => String, the digest type you wish to use
  :value  => String, the value of the URLs digest you are using
  :occurrence_id => String, the ID of the specific occurrence


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tigre-client/occurrence.rb', line 38

def self.get(hash, occurrence_id=nil)
  if hash.is_a?(String)
    Tigre.logger.warn "** DEPRECATED PARAMETERS ** Use Tigre::Occurrence.get(:digest => 'sha256', :value => 'your-sha256', :occurrence_id => 'id')" if Tigre.logger
    hash = {:digest => 'sha256', :value => hash, :occurrence_id => occurrence_id}
  end
  
  unless hash[:digest] && hash[:value] && hash[:occurrence_id]
    raise 'Missing parameter :digest, :value or :occurrence_id'
  end
  
  Tigre.get_connection("/urls/#{hash[:digest]}/value/#{hash[:value]}/occurrences/#{hash[:occurrence_id]}")
end

.update(sha256, occurrence_id, params_hash = {}) ⇒ Object

updated an individual occurrence for a given sha256 URL required params

sha256 => String
occurrence_id => String
params_hash => Hash


57
58
59
60
61
62
# File 'lib/tigre-client/occurrence.rb', line 57

def self.update(sha256, occurrence_id, params_hash={})
  raise "Missing sha256 parameter" if sha256 == ''
  
  update_data = params_hash.map { |k, v| {"occurrence[#{k.to_s}]" => v.to_s} }
  Tigre.put_connection("/urls/#{sha256}/occurrences/#{occurrence_id}", update_data)
end