Method: Threatinator::EventBuilder#build

Defined in:
lib/threatinator/event_builder.rb

#buildObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/threatinator/event_builder.rb', line 23

def build
  opts = {
    feed_provider: @feed_provider,
    feed_name: @feed_name,
  }
  opts[:type] = @type unless @type.nil?

  ret = Threatinator::Event.new(opts)

  @ipv4s.each do |ipv4, opts|
    opts = opts.dup
    if ipv4.is_a?(::String)
      ipv4 = ::IP::V4.parse(ipv4)
    end
    opts[:ipv4] = ipv4
    ret.ipv4s << Threatinator::Model::Observables::Ipv4.new(opts)
  end
  @fqdns.each do |fqdn|
    ret.fqdns << fqdn
  end
  @urls.each do |url|
    url = begin
      ::Addressable::URI.parse(url)
    rescue TypeError => e
      raise Threatinator::Exceptions::EventBuildError, "Failed to parse URL"
    end
    ret.urls << url
  end
  ret
rescue Threatinator::Exceptions::InvalidAttributeError => e
  raise Threatinator::Exceptions::EventBuildError, e.message
end