Class: Tigre::Url

Inherits:
Object
  • Object
show all
Extended by:
AnalysisComponents, CommonGetters, CommonParams, TagComponents
Defined in:
lib/tigre-client/url.rb

Class Method Summary collapse

Methods included from CommonParams

before_after, before_after_page_per, common_params, get_klass, get_logic_param, package_array_list, page_per

Methods included from CommonGetters

count, index

Methods included from TagComponents

not_tagged, not_tagged_with, remove_tags, tagged_count, tagged_with

Methods included from AnalysisComponents

add_analysis, get_analyses

Class Method Details

.add_tags(sha256, tags) ⇒ Object

required

sha256 => String
tags => String => I.E 'foo'
tags => String (comma seperated) => I.E 'foo,bar,baz'
tags => Array => ['foo', 'bar', 'baz']


56
57
58
59
60
61
62
63
64
# File 'lib/tigre-client/url.rb', line 56

def self.add_tags(sha256, tags)
  if sha256 == '' || tags == '' 
    raise ArguementError, "Missing tags parameter"
  end

  update_data = {"tag_list" => package_array_list(tags)}

  Tigre.put_connection("/urls/#{sha256}/add_tags", update_data)
end

.daterange(options = {}) ⇒ Object

DEPRECATED => use Tigre::Url.index(options)

required params

options => Hash
  :after  => Ruby DateTime object OR Integer (epoch time)
  :before => Ruby DateTime object OR Integer (epoch time)


102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/tigre-client/url.rb', line 102

def self.daterange(options={})
  # if options.nil? || (options[:after].nil? && options[:before].nil?)
  #   raise ArguementError, "Missing proper parameters (:start_date or :end_date required)"
  # end

  Tigre.logger.warn "** DEPRECATED ** Use Tigre::Url.index(options) " if Tigre.logger
  
  self.index(options)
  # common_params(options)
  # 
  # Tigre.get_connection("/urls/daterange?after=#{@after}&before=#{@before}&page=#{@page}&per=#{@per}")
end

.domains(domain, options = {}) ⇒ Object

required params

domain => String

optional params

options => Hash
  :after  => Ruby DateTime object OR Integer (epoch time)
  :before => Ruby DateTime object OR Integer (epoch time)
  :page => Integer, :default => 0
  :per => Integer, :default => 50


123
124
125
126
127
128
129
130
# File 'lib/tigre-client/url.rb', line 123

def self.domains(domain, options={})
  if domain == ''
    raise ArguementError, "Missing domain parameter"
  end

  common_params(options)
  Tigre.get_connection("/urls/domains?domain=#{domain}&#{before_after_page_per}")
end

.get(hash) ⇒ Object

required params

sha256 => String ** DEPRECATED ** => use get(:digest => 'sha256', :value => 'your-sha256')
hash   => Hash
  :digest => String,  The digest type
  :value  => String,  The digest value


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tigre-client/url.rb', line 71

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

.get_md5(md5) ⇒ Object

DEPRECATED => use Tigre::Url.get(:digest => ‘md5’, :value => ‘your-md5’)

required params

md5 => String

Raises:

  • (ArguementError)


89
90
91
92
93
# File 'lib/tigre-client/url.rb', line 89

def self.get_md5(md5)
  raise ArguementError, "Missing md5 parameter" if md5 == ''
  Tigre.logger.warn "** DEPRECATED ** Use Tigre::Url.get(:digest => 'md5', :value => 'your-md5')" if Tigre.logger
  self.get(:digest => 'md5', :value => md5)
end

.post(url, options = {}) ⇒ Object

required params

url => String
options => Hash
  :source_name => String

optional params

options => Hash
  :shareable => Boolean, :default => false
  :tags => String => I.E 'foo'
  :tags => String (comma seperated) => I.E 'foo,bar,baz'
  :tags => Array => ['foo', 'bar', 'baz']


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tigre-client/url.rb', line 19

def self.post(url, options={})
  if url == ''
    raise  "Missing url parameter"
  end
  unless options[:source_name]
    raise "Missing source_name parameter"
  end

  # prepare post data
  post_data = {
    "url[original_url]" => url,
    "url[source_name]"  => options[:source_name],
    "url[shareable]"    => options[:shareable],
  }
  
  post_data["url[tags]"] = package_array_list(options[:tags]) if options[:tags]

  Tigre.post_connection('/urls', post_data)
end

.update(sha256, params_hash) ⇒ Object

required

sha256 => String
params_hash => Hash


42
43
44
45
46
47
48
49
# File 'lib/tigre-client/url.rb', line 42

def self.update(sha256, params_hash)
  if sha256 == '' || params_hash.empty?
    raise "Missing url parameter or params_hash is empty"
  end

  update_data = params_hash.map { |k, v| {"url[#{k.to_s}]" => v.to_s} }
  Tigre.put_connection("/urls/#{sha256}", update_data )
end