Class: EmailHunter::Search

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, key, params = {}) ⇒ Search

Returns a new instance of Search.



12
13
14
15
16
# File 'lib/email_hunter/search.rb', line 12

def initialize(domain, key, params = {})
  @domain = domain
  @key = key
  @params = params
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def domain
  @domain
end

#emailsObject (readonly)

Returns the value of attribute emails.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def emails
  @emails
end

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def key
  @key
end

#metaObject (readonly)

Returns the value of attribute meta.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def meta
  @meta
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def params
  @params
end

#patternObject (readonly)

Returns the value of attribute pattern.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def pattern
  @pattern
end

#webmailObject (readonly)

Returns the value of attribute webmail.



10
11
12
# File 'lib/email_hunter/search.rb', line 10

def webmail
  @webmail
end

Instance Method Details

#dataObject



30
31
32
33
34
35
36
37
38
# File 'lib/email_hunter/search.rb', line 30

def data
  @data ||= begin
    response = Faraday.new("#{API_SEARCH_URL}domain=#{domain}&api_key=#{key}&type=#{params[:type]}&offset=#{offset}&limit=#{limit}").get

    return {} unless response.success?

    JSON.parse(response.body, { symbolize_names: true })
  end
end

#huntObject



18
19
20
# File 'lib/email_hunter/search.rb', line 18

def hunt
  Struct.new(*data.keys).new(*data.values)
end

#limitObject



22
23
24
# File 'lib/email_hunter/search.rb', line 22

def limit
  params[:limit] || 10
end

#offsetObject



26
27
28
# File 'lib/email_hunter/search.rb', line 26

def offset
  params[:offset] || 0
end