class EmailHunter::Search
Constants
- API_URL
Attributes
Public Class Methods
Source
# File lib/email_hunter/search.rb, line 12 def initialize(domain, key, params = {}) @domain = domain @key = key @params = params end
Public Instance Methods
Source
# File lib/email_hunter/search.rb, line 18 def hunt response_data = fetch_search_data return nil if response_data.empty? Struct.new(*response_data.keys).new(*response_data.values) end
Private Instance Methods
Source
# File lib/email_hunter/search.rb, line 35 def fetch_search_data @fetch_search_data ||= begin connection = Faraday.new request_params = { domain: domain, api_key: key, offset: offset, limit: limit } request_params[:type] = params[:type] if params[:type] response = connection.get(API_URL, request_params) return {} unless response.success? JSON.parse(response.body, symbolize_names: true) end end
Source
# File lib/email_hunter/search.rb, line 27 def limit params.fetch(:limit, 10).to_i end
Source
# File lib/email_hunter/search.rb, line 31 def offset params.fetch(:offset, 0).to_i end