Class: ESearchy
- Inherits:
-
Object
- Object
- ESearchy
- Defined in:
- lib/esearchy.rb
Constant Summary collapse
- LIBRARY =
Constants
1- APP =
2- DELAY =
4- 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
-
#depth_search ⇒ Object
Attributes.
-
#engines ⇒ Object
Attributes.
-
#maxhits ⇒ Object
Returns the value of attribute maxhits.
-
#query ⇒ Object
Attributes.
-
#threads ⇒ Object
Attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #bing_key=(value) ⇒ Object
-
#clean(&block) ⇒ Object
Filter methods ##.
- #company_name ⇒ Object
- #company_name=(company) ⇒ Object
-
#emails ⇒ Object
retrieve emails.
- #filter(regex) ⇒ Object
- #filter_by_score(score) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ESearchy
constructor
Need to find another way of fixing this.
- #linkedin_credentials ⇒ Object
- #linkedin_credentials=(*args) ⇒ Object
- #log_file=(value) ⇒ Object
-
#log_type=(value) ⇒ Object
End Constants.
- #people ⇒ Object
-
#save_to_file(file, list = nil) ⇒ Object
Saving methods.
- #save_to_sqlite(file) ⇒ Object
- #search(query = nil) ⇒ Object
- #search_engine(key, value) ⇒ Object
- #verify_domain!(e) ⇒ Object
-
#verify_email!(arg = emails) ⇒ Object
checking methods ##.
- #yahoo_key=(value) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ ESearchy
Need to find another way of fixing this. def delay=(value)
ESearch::DELAY = value
end
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/esearchy.rb', line 38 def initialize(={}, &block) @query = [:query] @depth_search = [:depth] || true @maxhits = [:maxhits] || 0 @engines = [:engines] ? eng([: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_search ⇒ Object
Attributes
59 60 61 |
# File 'lib/esearchy.rb', line 59 def depth_search @depth_search end |
#engines ⇒ Object
Attributes
59 60 61 |
# File 'lib/esearchy.rb', line 59 def engines @engines end |
#maxhits ⇒ Object
Returns the value of attribute maxhits.
60 61 62 |
# File 'lib/esearchy.rb', line 60 def maxhits @maxhits end |
#query ⇒ Object
Attributes
59 60 61 |
# File 'lib/esearchy.rb', line 59 def query @query end |
#threads ⇒ Object
Attributes
59 60 61 |
# File 'lib/esearchy.rb', line 59 def threads @threads end |
Class Method Details
.create(query = nil, &block) ⇒ Object
62 63 64 65 66 |
# File 'lib/esearchy.rb', line 62 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
119 120 121 |
# File 'lib/esearchy.rb', line 119 def bing_key=(value) @engines[:Bing].appid = value end |
#clean(&block) ⇒ Object
Filter methods ##
94 95 96 97 98 |
# File 'lib/esearchy.rb', line 94 def clean(&block) emails.each do |e| e.delete_if block.call end end |
#company_name ⇒ Object
140 141 142 143 144 |
# File 'lib/esearchy.rb', line 140 def company_name (@engines[:LinkedIn] || @engines[:GoogleProfiles] || @engines[:Naymz]).company_name || nil end |
#company_name=(company) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/esearchy.rb', line 146 def company_name=(company) [:LinkedIn, :GoogleProfiles, :Naymz].each do |e| @engines[e].company_name = company if @engines[e] end end |
#emails ⇒ Object
retrieve emails
77 78 79 80 81 82 83 |
# File 'lib/esearchy.rb', line 77 def emails emails = [] @engines.each do |n,e| emails.concat(@engines[n].emails).uniq! end emails end |
#filter(regex) ⇒ Object
100 101 102 |
# File 'lib/esearchy.rb', line 100 def filter(regex) emails.each.select { |email| email =~ regex } end |
#filter_by_score(score) ⇒ Object
104 105 106 |
# File 'lib/esearchy.rb', line 104 def filter_by_score(score) emails.each.select { |email| score >= calculate_score(emails) } end |
#linkedin_credentials ⇒ Object
123 124 125 |
# File 'lib/esearchy.rb', line 123 def linkedin_credentials return @engines[:LinkedIn].username, @engines[:LinkedIn].password end |
#linkedin_credentials=(*args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/esearchy.rb', line 127 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
30 31 32 |
# File 'lib/esearchy.rb', line 30 def log_file=(value) ESearchy::LOG.file = value end |
#log_type=(value) ⇒ Object
End Constants
26 27 28 |
# File 'lib/esearchy.rb', line 26 def log_type=(value) ESearchy::LOG.level = value end |
#people ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/esearchy.rb', line 85 def people people = [] [:LinkedIn, :GoogleProfiles, :Naymz].each do |e| people.concat(@engines[e].people) if @engines[e] end people.uniq! end |
#save_to_file(file, list = nil) ⇒ Object
Saving methods
176 177 178 179 180 |
# File 'lib/esearchy.rb', line 176 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
182 183 184 185 |
# File 'lib/esearchy.rb', line 182 def save_to_sqlite(file) # TODO save to sqlite3 # table esearchy with fields (id, Domain, email, score) end |
#search(query = nil) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/esearchy.rb', line 68 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
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/esearchy.rb', line 153 def search_engine(key, value) if [:Google, :Bing, :Yahoo, :PGP, :LinkedIn, :GoogleGroups, :Altavista, :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
197 198 199 |
# File 'lib/esearchy.rb', line 197 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 ##
189 190 191 192 193 194 195 |
# File 'lib/esearchy.rb', line 189 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
115 116 117 |
# File 'lib/esearchy.rb', line 115 def yahoo_key=(value) @engines[:Yahoo].appid = value end |