Module: KickboxRails

Defined in:
lib/kickbox_rails.rb,
lib/kickbox_rails/version.rb,
lib/generators/kickbox_rails/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Configuration

Constant Summary collapse

VERSION =
"1.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



8
9
10
# File 'lib/kickbox_rails.rb', line 8

def configuration
  @configuration
end

.providerObject

Returns the value of attribute provider.



8
9
10
# File 'lib/kickbox_rails.rb', line 8

def provider
  @provider
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



10
11
12
13
14
15
16
# File 'lib/kickbox_rails.rb', line 10

def configure
  @configuration ||= Configuration.new
  yield(configuration)
  @provider = KickboxApi.new(url: @configuration.api_url,
                                end_point: @configuration.api_resource,
                                token: @configuration.api_key)
end

.invalid?(email) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/kickbox_rails.rb', line 45

def invalid? email
  !valid? email
end

.valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/kickbox_rails.rb', line 32

def valid? email
  response = validate(email)
  valid_response?(response)
end

.valid_response?(response) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/kickbox_rails.rb', line 37

def valid_response?(response)
  if @configuration.treat_unknown_as_valid
    [ 'valid', 'unknown' ].include?(response['result'])
  else
    [ 'valid' ].include?(response['result'])
  end
end

.validate(email) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kickbox_rails.rb', line 18

def validate email
  begin
    response = @provider.verify(email||String.new)
    # fallbacks if provider return success = false
    throw Exception unless response['success'] == 'true' || response['success'] == true

    response

  rescue Exception => e
    # If Kickbox service respond with Error we do fallback to basic validation
    basic_email_validation email
  end
end