Class: Zerobounce::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/zerobounce/request.rb,
lib/zerobounce/request/v1_request.rb,
lib/zerobounce/request/v2_request.rb

Overview

Sends the HTTP request.

Author:

  • Aaron Frase

Defined Under Namespace

Modules: V1Request, V2Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Request

Set instance variables and extends the correct Zerobounce::Request

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zerobounce/request.rb', line 33

def initialize(params={})
  @middleware = params[:middleware] || Zerobounce.config.middleware
  @headers = params[:headers] || Zerobounce.config.headers
  @host = params[:host] || Zerobounce.config.host
  @api_version = params[:api_version] || Zerobounce.config.api_version

  case api_version
  when 'v2'
    extend(V2Request)
  else
    extend(V1Request)
  end
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



24
25
26
# File 'lib/zerobounce/request.rb', line 24

def api_version
  @api_version
end

#headersHash (readonly)

The headers used for the request.

Returns:

  • (Hash)

    the current value of headers



20
21
22
# File 'lib/zerobounce/request.rb', line 20

def headers
  @headers
end

#hostString (readonly)

The host to send the request to.

Returns:

  • (String)

    the current value of host



20
21
22
# File 'lib/zerobounce/request.rb', line 20

def host
  @host
end

#middlewareProc (readonly)

Faraday middleware used for the request.

Returns:

  • (Proc)

    the current value of middleware



20
21
22
# File 'lib/zerobounce/request.rb', line 20

def middleware
  @middleware
end

Instance Method Details

#credits(params = {}) ⇒ Integer

Get the number of remaining credits on the account.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :apikey (String)

Returns:

  • (Integer)

    A value of -1 can mean the API is invalid.



52
53
54
# File 'lib/zerobounce/request.rb', line 52

def credits(params={})
  get('getcredits', params).body[:Credits].to_i
end