Sha256: ba1ca802fc4e3ec46c359f13f6b24c8a856ada9ac7b68112c166d080009cdd09

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module SecurityTrails
  module Clients
    class History < Client
      def get_dns_history(hostname, type, page = 1)
        raise ArgumentError, "The API currently supports a, aaaa, mx, ns, soa and txt records." unless valid_type?(type)

        get("/history/#{hostname}/dns/#{type.downcase}", page: page) { |json| json }
      end

      def get_all_dns_history(hostname, type)
        first_page = get_dns_history(hostname, type, 1)
        pages = first_page["pages"].to_i

        records = []
        records << first_page["records"]

        (2..pages).each do |page_idx|
          next_page = get_dns_history(hostname, type, page_idx)
          records << next_page["records"]
        end

        first_page["records"] = records.flatten
        first_page
      end

      def get_whois_history(hostname)
        get("/history/#{hostname}/whois/") { |json| json }
      end

      private

      def valid_type?(type)
        ["a", "aaaa", "mx", "ns", "soa", "txt"].include? type.downcase
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
securitytrails-0.2.0 lib/securitytrails/clients/history.rb
securitytrails-0.1.5 lib/securitytrails/clients/history.rb
securitytrails-0.1.4 lib/securitytrails/clients/history.rb
securitytrails-0.1.3 lib/securitytrails/clients/history.rb
securitytrails-0.1.2 lib/securitytrails/clients/history.rb
securitytrails-0.1.1 lib/securitytrails/clients/history.rb