Class: ESearchy

Inherits:
Object
  • Object
show all
Defined in:
lib/esearchy.rb

Constant Summary collapse

LIBRARY =

Constants

1
APP =
2
LOG =
Logger.new(1, $stdout)
BUGMENOT =
BMN::fetch_user("linkedin.com")
DEFAULT_ENGINES =
[:Google, :Bing, :Yahoo, :PGP, :LinkedIn, 
:GoogleGroups, :Altavista, :Usenet, :GoogleProfiles, :Naymz]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ ESearchy

Returns a new instance of ESearchy.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/esearchy.rb', line 33

def initialize(options={}, &block)
  @query = options[:query]
  @depth_search = options[:depth] || true
  @maxhits = options[:maxhits] || 0
  @engines = options[:engines] ? eng(options[:engines]) : 
                                 { :Google => Google, 
                                   :Bing => Bing, 
                                   :Yahoo => Yahoo,
                                   :PGP => PGP, 
                                   :LinkedIn => LinkedIn,
                                   :GoogleGroups => GoogleGroups,
                                   :Altavista => Altavista,
                                   :Usenet => Usenet,
                                   :GoogleProfiles => GoogleProfiles,
                                   :Naymz => Naymz }
  @engines.each {|n,e| @engines[n] = e.new(@maxhits)}
  @threads = Array.new
  block.call(self) if block_given?
end

Instance Attribute Details

#depth_searchObject

Attributes



54
55
56
# File 'lib/esearchy.rb', line 54

def depth_search
  @depth_search
end

#enginesObject

Attributes



54
55
56
# File 'lib/esearchy.rb', line 54

def engines
  @engines
end

#maxhitsObject

Returns the value of attribute maxhits.



55
56
57
# File 'lib/esearchy.rb', line 55

def maxhits
  @maxhits
end

#queryObject

Attributes



54
55
56
# File 'lib/esearchy.rb', line 54

def query
  @query
end

#threadsObject

Attributes



54
55
56
# File 'lib/esearchy.rb', line 54

def threads
  @threads
end

Class Method Details

.create(query = nil, &block) ⇒ Object



57
58
59
60
61
# File 'lib/esearchy.rb', line 57

def self.create(query=nil, &block)
  self.new :query => query do |search|
    block.call(search) if block_given?
  end
end

Instance Method Details

#bing_key=(value) ⇒ Object



114
115
116
# File 'lib/esearchy.rb', line 114

def bing_key=(value)
  @engines[:Bing].appid = value
end

#clean(&block) ⇒ Object

Filter methods ##



89
90
91
92
93
# File 'lib/esearchy.rb', line 89

def clean(&block)
  emails.each do |e|
    e.delete_if block.call
  end
end

#company_nameObject



135
136
137
138
139
# File 'lib/esearchy.rb', line 135

def company_name
  (@engines[:LinkedIn] || 
   @engines[:GoogleProfiles] || 
   @engines[:Naymz]).company_name || nil
end

#company_name=(company) ⇒ Object



141
142
143
144
145
146
# File 'lib/esearchy.rb', line 141

def company_name=(company)
  [:LinkedIn, :GoogleProfiles, :Naymz].each do |e| 
    @engines[e].company_name = company if @engines[e]
  end
  
end

#emailsObject

retrieve emails



72
73
74
75
76
77
78
# File 'lib/esearchy.rb', line 72

def emails
  emails = []
  @engines.each do |n,e|
    emails.concat(@engines[n].emails).uniq!
  end
  emails
end

#filter(regex) ⇒ Object



95
96
97
# File 'lib/esearchy.rb', line 95

def filter(regex)
  emails.each.select { |email| email =~ regex }
end

#filter_by_score(score) ⇒ Object



99
100
101
# File 'lib/esearchy.rb', line 99

def filter_by_score(score)
  emails.each.select { |email| score >= calculate_score(emails) }
end

#linkedin_credentialsObject



118
119
120
# File 'lib/esearchy.rb', line 118

def linkedin_credentials
  return @engines[:LinkedIn].username, @engines[:LinkedIn].password
end

#linkedin_credentials=(*args) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/esearchy.rb', line 122

def linkedin_credentials=(*args)
  if args.size == 2
    @engines[:LinkedIn].username = args[0]
    @engines[:LinkedIn].password = args[1]
    return true
  elsif args.size == 1
    @engines[:LinkedIn].username = args[0][0]
    @engines[:LinkedIn].password = args[0][1]
    return true
  end
  false
end

#log_file=(value) ⇒ Object



29
30
31
# File 'lib/esearchy.rb', line 29

def log_file=(value)
  ESearchy::LOG.file = value
end

#log_type=(value) ⇒ Object

End Constants



25
26
27
# File 'lib/esearchy.rb', line 25

def log_type=(value)
  ESearchy::LOG.level = value
end

#peopleObject



80
81
82
83
84
85
86
# File 'lib/esearchy.rb', line 80

def people
  people = []
  [:LinkedIn, :GoogleProfiles].each do |e| 
    people.concat(@engines[e].people) if @engines[e]
  end
  people.uniq!
end

#save_to_file(file, list = nil) ⇒ Object

Saving methods



171
172
173
174
175
# File 'lib/esearchy.rb', line 171

def save_to_file(file, list=nil)
  open(file,"a") do |f|
    list ? list.each { |e| f << e + "\n" } : emails.each { |e| f << e + "\n" }
  end
end

#save_to_sqlite(file) ⇒ Object



177
178
179
180
# File 'lib/esearchy.rb', line 177

def save_to_sqlite(file)
  # TODO save to sqlite3
  # table esearchy with fields (id, Domain, email, score)
end

#search(query = nil) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/esearchy.rb', line 63

def search(query=nil)
  @engines.each do |n,e|
    LOG.puts "+--- Launching Search for #{n} ---+\n"
    e.search(query || @query)
    e.search_depth if depth_search?
    LOG.puts "+--- Finishing Search for #{n} ---+\n"
  end
end

#search_engine(key, value) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/esearchy.rb', line 148

def search_engine(key, value)
  if [:Google, :Bing, :Yahoo, :PGP, :LinkedIn, 
      :GoogleGroups, :AltaVisa, :Usenet, :GoogleProfiles, Naymz].include?(key)
    if value == true 
      unless @engines[key]
        @engines[key] = instance_eval "#{key}.new(@maxhits)"
      end
    elsif value == false
      @engines.delete(key)
    end
  else
    raise(ArgumentError, "No plugin with that Key")
  end
end

#verify_domain!(e) ⇒ Object



192
193
194
# File 'lib/esearchy.rb', line 192

def verify_domain!(e)
  Resolv::DNS.open.getresources(e.split('@')[-1],Resolv::DNS::Resource::IN::MX) > 0 ? true : false
end

#verify_email!(arg = emails) ⇒ Object

checking methods ##



184
185
186
187
188
189
190
# File 'lib/esearchy.rb', line 184

def verify_email!(arg = emails)
  # TODO
  # Connect to mail server if possible verify else 
  # return 0 for false  2 for true or 1 for error.
  # VRFY & EXPN & 'RCPT TO:
  return false
end

#yahoo_key=(value) ⇒ Object



110
111
112
# File 'lib/esearchy.rb', line 110

def yahoo_key=(value)
  @engines[:Yahoo].appid = value
end