Class: Snov::GetProspectList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/snov/get_prospect_list.rb

Defined Under Namespace

Classes: ProspectEmail, ProspectResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_id:, page:, per_page: 100, client: Snov.client) ⇒ GetProspectList

Returns a new instance of GetProspectList.



9
10
11
12
13
14
# File 'lib/snov/get_prospect_list.rb', line 9

def initialize(list_id:, page:, per_page: 100, client: Snov.client)
  @client = client
  @list_id = list_id
  @page = page
  @per_page = per_page
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#list_idObject (readonly)

Returns the value of attribute list_id.



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

def list_id
  @list_id
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

Instance Method Details

#each(&block) ⇒ Object



16
17
18
# File 'lib/snov/get_prospect_list.rb', line 16

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

#prospectsObject



20
21
22
23
24
# File 'lib/snov/get_prospect_list.rb', line 20

def prospects
  @prospects ||= raw_result.fetch('prospects').map do |result|
    ProspectResult.new(result)
  end
end

#raw_resultObject



26
27
28
29
30
31
32
# File 'lib/snov/get_prospect_list.rb', line 26

def raw_result
  @raw_result ||= client.post("/v1/prospect-list",
                              'listId' => list_id.to_s,
                              'page' => page.to_s,
                              'perPage' => per_page.to_s)
                        .deep_transform_keys! { |key| key.underscore }
end