Sha256: adfee87a899b9b2c7d3319b804c11f9d1736393c043e62c53d1a56fafeae3a81

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'active_support/core_ext/array'
require 'camel_snake_struct'

module Snov
  class DomainSearch
    Response = Class.new(CamelSnakeStruct)
    Response.example(MultiJson.load(File.read("#{__dir__}/fake_client/get_v2_domain-emails-with-info.json")))
    include Enumerable

    attr_reader :client, :domain, :type, :limit

    def initialize(domain:, type: 'all', limit: 10, last_id: 0, client: Snov.client)
      @client = client
      @domain = domain
      @type = type
      @limit = limit
      @last_id = last_id
    end

    def each(&block)
      raw_result.emails.each(&block)
    end

    def success
      raw_result.success
    end

    def webmail
      raw_result.webmail
    end

    def result
      raw_result.result
    end

    def last_id
      raw_result.last_id
    end

    def company_name
      raw_result.company_name
    end

    def raw_result
      @raw_result ||= Response.new(client.get("/v2/domain-emails-with-info",
                                              'lastId' => @last_id,
                                              'limit' => @limit,
                                              'type' => type.to_s,
                                              'domain' => domain.to_s))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snov-0.2.3 lib/snov/domain_search.rb