Class: EmailListVerify

Inherits:
Object
  • Object
show all
Defined in:
lib/email_list_verify.rb,
lib/email_list_verify/version.rb

Constant Summary collapse

BASE =
'https://app.emaillistverify.com/api'
ONE_BY_ONE_PATH =
BASE + "/verifEmail"
UPLOAD_FILE_PATH =
BASE + "/verifApiFile"
FILE_INFO_PATH =
BASE + "/getApiFileInfo"
BULK_ERRORS =
["no_credit","cannot_upload_file","key_not_valid","missing_parameters"]
VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ EmailListVerify

Returns a new instance of EmailListVerify.



11
12
13
# File 'lib/email_list_verify.rb', line 11

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#bulk_status(file_id = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/email_list_verify.rb', line 28

def bulk_status(file_id=nil)
  unless file_id or @id
    return "Please provide the file_id or call the upload_file with a success"
  end
  id = file_id
  id ||= @id
  options = {params: {id: id, secret: @api_key}}
  RestClient.get(FILE_INFO_PATH, options)
end

#one_by_one(email) ⇒ Object



14
15
16
17
# File 'lib/email_list_verify.rb', line 14

def one_by_one(email)
  options = {params: {email: email, secret: @api_key}}
  RestClient.get(ONE_BY_ONE_PATH, options)
end

#upload_file(file_name, file_path = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/email_list_verify.rb', line 18

def upload_file(file_name, file_path=nil)
  file_path ||= file_name
  options = {file_contents: File.new(file_path)}
  url = UPLOAD_FILE_PATH+"?secret=#{@api_key}&filename=#{file_name}"
  res = RestClient.post(url, options)
  unless BULK_ERRORS.include? (res.to_s)
    @id = res
  end
  res
end