Module: InterakthqRails::UserValidator

Included in:
Import
Defined in:
lib/interakthq_rails/user_validator.rb

Constant Summary collapse

EXPECTED_ATTRIBUTES =
['email', 'name', 'first_name', 'last_name','firstname', 'lastname', 'created_at']

Instance Method Summary collapse

Instance Method Details

#availabe_model_attributesObject



25
26
27
# File 'lib/interakthq_rails/user_validator.rb', line 25

def availabe_model_attributes
  @availabe_model_attributes ||= EXPECTED_ATTRIBUTES.select{ |attribute| model_name.new.respond_to? attribute}
end

#check_basic_validationObject



5
6
7
8
9
10
11
# File 'lib/interakthq_rails/user_validator.rb', line 5

def check_basic_validation
  raise 'We only supports ActiveRecord' unless (defined?(ActiveRecord::Base) && (model_name < ActiveRecord::Base))
  raise "You have to add 'app_id' in your 'config/initializers/interakthq.rb' file first" unless InterakthqRails.config.app_id.present?
  raise "You have to add 'api_key' in your 'config/initializers/interakthq.rb' file first" unless InterakthqRails.config.api_key.present?
  raise "Your model must have 'email' field" unless model_name.new.respond_to? :email

end

#model_nameObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/interakthq_rails/user_validator.rb', line 13

def model_name
  unless @model_name
    begin
      InterakthqRails.config.user.model.call
    rescue Exception => e
      raise "Model doesn't exists"
    end
  else
    @model_name
  end
end

#verify_reponse(response) ⇒ Object



29
30
31
32
33
# File 'lib/interakthq_rails/user_validator.rb', line 29

def verify_reponse( response)
  raise "Your 'app_id' is not corrent. Please correct it in 'config/initializers/interakthq.rb'" if response.code.to_i == 401
  raise "Something went wrong. Please report the issue." if response.code.to_i == 500
  response_verified = true
end