Class: Zerobounce::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/zerobounce/configuration.rb

Overview

Configuration object for Zerobounce.

Author:

  • Aaron Frase

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/zerobounce/configuration.rb', line 39

def initialize
  self.host = 'https://api.zerobounce.net'
  self.apikey = ENV.fetch('ZEROBOUNCE_API_KEY', nil)
  self.api_version = 'v2'
  self.valid_statuses = %i[valid catch_all]
  self.headers = { user_agent: "ZerobounceRubyGem/#{Zerobounce::VERSION}" }

  self.middleware = proc do |builder|
    builder.response(:json, content_type: /\bjson$/, parser_options: { symbolize_names: true })
    builder.response(:logger) { |l| l.filter(/(api_?key=)(\w+)/, '\1[REMOVED]') } if ENV['ZEROBOUNCE_API_DEBUG']
    builder.use(Zerobounce::Middleware::RaiseHttpException)
    builder.adapter(Faraday.default_adapter)
  end
end

Instance Attribute Details

#api_versionString

The version of the API to use.

Returns:

  • (String)

    the current value of api_version



31
32
33
# File 'lib/zerobounce/configuration.rb', line 31

def api_version
  @api_version
end

#apikeyString

A Zerobounce API key.

Returns:

  • (String)

    the current value of apikey



31
32
33
# File 'lib/zerobounce/configuration.rb', line 31

def apikey
  @apikey
end

#headersHash

Headers to use in all requests.

Returns:

  • (Hash)

    the current value of headers



31
32
33
# File 'lib/zerobounce/configuration.rb', line 31

def headers
  @headers
end

#hostString

The Zerobounce API host.

Returns:

  • (String)

    the current value of host



31
32
33
# File 'lib/zerobounce/configuration.rb', line 31

def host
  @host
end

#middlewareProc

Note:

If you modify the default make sure to add middleware to parse the response as json and symbolize the keys.

The middleware used by Faraday for each request.

Returns:

  • (Proc)

    the current value of middleware



31
32
33
# File 'lib/zerobounce/configuration.rb', line 31

def middleware
  @middleware
end

#valid_statuesArray<Symbol>

The statuses that are considered valid by Response#valid?.

Returns:

  • (Array<Symbol>)

    the current value of valid_statues



31
32
33
# File 'lib/zerobounce/configuration.rb', line 31

def valid_statues
  @valid_statues
end

#valid_statusesObject

Returns the value of attribute valid_statuses.



37
38
39
# File 'lib/zerobounce/configuration.rb', line 37

def valid_statuses
  @valid_statuses
end