Sha256: 002551d7965469e373df8b17dd3e7a699825f75b5bb7a2850e3f69d655461e96

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "forwardable"

module SecurityTrails
  class API
    extend Forwardable

    attr_reader :api_key

    def initialize(api_key = ENV["SECURITYTRAILS_API_KEY"])
      @api_key = api_key
      raise ArgumentError, "'api_key' argument is required" unless api_key
    end

    #
    # General API client
    #
    # @return [SecurityTrails::Clients::General]
    #
    def general
      @general ||= Clients::General.new(api_key)
    end

    %w(ping usage scroll).each do |delegate_method|
      sym = delegate_method.to_sym
      def_delegator :general, sym, sym
    end

    #
    # Domain API client
    #
    # @return [SecurityTrails::Clients::Domain]
    #
    def domain
      @domain ||= Clients::Domain.new(api_key)
    end

    #
    # Domains API client
    #
    # @return [SecurityTrails::Clients::Domains]
    #
    def domains
      @domains ||= Clients::Domains.new(api_key)
    end

    #
    # History API client
    #
    # @return [SecurityTrails::Clients::History]
    #
    def history
      @history ||= Clients::History.new(api_key)
    end

    #
    # IPs API client
    #
    # @return [SecurityTrails::Clients::IPs]
    #
    def ips
      @ips ||= Clients::IPs.new(api_key)
    end

    #
    # Feed API client
    #
    # @return [SecurityTrails::Clients::Feeds]
    #
    def feeds
      @feeds ||= Clients::Feeds.new(api_key)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
securitytrails-1.0.0 lib/securitytrails/api.rb