lib/mihari/structs/censys.rb in mihari-5.2.2 vs lib/mihari/structs/censys.rb in mihari-5.2.3
- old
+ new
@@ -20,20 +20,22 @@
#
def to_as
Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
end
- #
- # @param [Hash] d
- #
- # @return [AutonomousSystem]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- asn: d.fetch("asn")
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [AutonomousSystem]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ asn: d.fetch("asn")
+ )
+ end
end
end
class Location < Dry::Struct
attribute :country, Types::String.optional
@@ -65,21 +67,23 @@
country: country,
country_code: country_code
)
end
- #
- # @param [Hash] d
- #
- # @return [Location]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- country: d["country"],
- country_code: d["country_code"]
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [Location]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ country: d["country"],
+ country_code: d["country_code"]
+ )
+ end
end
end
class Service < Dry::Struct
attribute :port, Types::Integer
@@ -96,20 +100,22 @@
#
def to_port
Port.new(port: port)
end
- #
- # @param [Hash] d
- #
- # @return [Service]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- port: d.fetch("port")
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [Service]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ port: d.fetch("port")
+ )
+ end
end
end
class Hit < Dry::Struct
attribute :ip, Types::String
@@ -171,24 +177,26 @@
geolocation: location.to_geolocation,
ports: to_ports
)
end
- #
- # @param [Hash] d
- #
- # @return [Hit]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- ip: d.fetch("ip"),
- location: Location.from_dynamic!(d.fetch("location")),
- autonomous_system: AutonomousSystem.from_dynamic!(d.fetch("autonomous_system")),
- metadata: d,
- services: d.fetch("services", []).map { |x| Service.from_dynamic!(x) }
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [Hit]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ ip: d.fetch("ip"),
+ location: Location.from_dynamic!(d.fetch("location")),
+ autonomous_system: AutonomousSystem.from_dynamic!(d.fetch("autonomous_system")),
+ metadata: d,
+ services: d.fetch("services", []).map { |x| Service.from_dynamic!(x) }
+ )
+ end
end
end
class Links < Dry::Struct
attribute :next, Types::String.optional
@@ -206,21 +214,23 @@
#
def prev
attributes[:prev]
end
- #
- # @param [Hash] d
- #
- # @return [Links]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- next: d["next"],
- prev: d["prev"]
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [Links]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ next: d["next"],
+ prev: d["prev"]
+ )
+ end
end
end
class Result < Dry::Struct
attribute :query, Types::String
@@ -258,26 +268,28 @@
#
# @return [Array<Mihari::Artifact>]
#
def to_artifacts
- hits.map { |hit| hit.to_artifact }
+ hits.map(&:to_artifact)
end
- #
- # @param [Hash] d
- #
- # @return [Result]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- query: d.fetch("query"),
- total: d.fetch("total"),
- hits: d.fetch("hits", []).map { |x| Hit.from_dynamic!(x) },
- links: Links.from_dynamic!(d.fetch("links"))
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [Result]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ query: d.fetch("query"),
+ total: d.fetch("total"),
+ hits: d.fetch("hits", []).map { |x| Hit.from_dynamic!(x) },
+ links: Links.from_dynamic!(d.fetch("links"))
+ )
+ end
end
end
class Response < Dry::Struct
attribute :code, Types::Int
@@ -303,21 +315,23 @@
#
def result
attributes[:result]
end
- #
- # @param [Hash] d
- #
- # @return [Response]
- #
- def self.from_dynamic!(d)
- d = Types::Hash[d]
- new(
- code: d.fetch("code"),
- status: d.fetch("status"),
- result: Result.from_dynamic!(d.fetch("result"))
- )
+ class << self
+ #
+ # @param [Hash] d
+ #
+ # @return [Response]
+ #
+ def from_dynamic!(d)
+ d = Types::Hash[d]
+ new(
+ code: d.fetch("code"),
+ status: d.fetch("status"),
+ result: Result.from_dynamic!(d.fetch("result"))
+ )
+ end
end
end
end
end
end