Class: Snov::GetProfileByEmail

Inherits:
Object
  • Object
show all
Defined in:
lib/snov/get_profile_by_email.rb

Defined Under Namespace

Classes: List, ProspectResult, Social

Constant Summary collapse

Job =
Class.new(CamelSnakeStruct)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email:, client: Snov.client) ⇒ GetProfileByEmail

Returns a new instance of GetProfileByEmail.



7
8
9
10
# File 'lib/snov/get_profile_by_email.rb', line 7

def initialize(email:, client: Snov.client)
  @client = client
  @email = email.to_str
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/snov/get_profile_by_email.rb', line 22

def method_missing(method_name, *arguments, &block)
  if prospect.respond_to?(method_name)
    prospect.public_send(method_name, *arguments, &block)
  else
    super
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/snov/get_profile_by_email.rb', line 5

def client
  @client
end

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/snov/get_profile_by_email.rb', line 5

def email
  @email
end

Instance Method Details

#each(&block) ⇒ Object



12
13
14
# File 'lib/snov/get_profile_by_email.rb', line 12

def each(&block)
  prospects.each(&block)
end

#prospectObject



16
17
18
19
20
# File 'lib/snov/get_profile_by_email.rb', line 16

def prospect
  @prospect ||= ProspectResult.new(raw_result)
rescue ActiveModel::UnknownAttributeError, ArgumentError, NoMethodError => e
  raise InvalidResponseError.new(e.message, response: raw_result)
end

#raw_resultObject



34
35
36
37
38
# File 'lib/snov/get_profile_by_email.rb', line 34

def raw_result
  @raw_result ||= client.post("/v1/get-profile-by-email",
                              'email' => email)
                        .deep_transform_keys! { |key| key.underscore }
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/snov/get_profile_by_email.rb', line 30

def respond_to_missing?(method_name, include_private = false)
  prospect.respond_to?(method_name) || super
end