handle

in api-reference-examples/ruby/te-tag-query/TETagQuery.rb [342:400]


  def handle(args, options)
    options['includeIndicatorInOutput'] = true
    options['pageSize'] = 10

    loop do
      break if args.length == 0
      break unless args[0][0] == '-'
      option = args.shift

      if option == '-h'
        self.usage(0)
      elsif option == '--help'
        self.usage(0)

      elsif option == '--tagged-since'
        self.usage(1) unless args.length >= 1
        options['taggedSince'] = args.shift;
      elsif option == '--tagged-until'
        self.usage(1) unless args.length >= 1
        options['taggedUntil'] = args.shift;

      elsif option == '--page-size'
        self.usage(1) unless args.length >= 1
        options['pageSize'] = args.shift;
      elsif option == '--no-print-indicator'
        self.usage(1) unless args.length >= 1
        options['includeIndicatorInOutput'] = false

      else
        $stderr.puts "#{$0} #{@verbName}: unrecognized  option #{option}"
        exit 1
      end
    end

    ids = []
    if args.length > 0
      ids = args
    else
      $stdin.readlines.each do |line|
        id = line.chomp
        ids.push(id)
      end
    end

    ids.each do |id|
      idBatch = [id]
      descriptors = ThreatExchange::TENet.getInfoForIDs(
        idBatch,
        verbose: options['verbose'],
        showURLs: options['showURLs'],
        includeIndicatorInOutput: options['includeIndicatorInOutput'])
      descriptors.each do |descriptor|
        # Stub processing -- one would perhaps integrate with one's own system
        puts descriptor.to_json
      end
    end

  end