lib/ronin/url.rb in ronin-1.5.0.rc2 vs lib/ronin/url.rb in ronin-1.5.0
- old
+ new
@@ -41,12 +41,12 @@
include Model::Importable
# Mapping of URL Schemes and URI classes
SCHEMES = {
'https' => ::URI::HTTPS,
- 'http' => ::URI::HTTP,
- 'ftp' => ::URI::FTP
+ 'http' => ::URI::HTTP,
+ 'ftp' => ::URI::FTP
}
# Primary key of the URL
property :id, Serial
@@ -98,11 +98,11 @@
# @since 1.3.0
#
# @api public
#
def self.extract(text)
- return enum_for(:extract,text).to_a unless block_given?
+ return enum_for(__method__,text).to_a unless block_given?
::URI.extract(text) do |uri|
uri = begin
::URI.parse(uri)
rescue URI::InvalidURIError
@@ -285,27 +285,27 @@
# optionally parse the URL
url = ::URI.parse(url.to_s) unless url.kind_of?(::URI)
# create the initial query
query = all(
- 'scheme.name' => url.scheme,
+ 'scheme.name' => url.scheme,
'host_name.address' => url.host,
- :path => normalized_path(url),
- :fragment => url.fragment
+ :path => normalized_path(url),
+ :fragment => url.fragment
)
if url.port
# query the port
query = query.all('port.number' => url.port)
end
if url.query
# add the query params to the query
- URI::QueryParams.parse(url.query).each do |name,value|
+ ::URI::QueryParams.parse(url.query).each do |name,value|
query = query.all(
'query_params.name.name' => name,
- 'query_params.value' => value
+ 'query_params.value' => value
)
end
end
return query.first
@@ -324,38 +324,38 @@
#
# @api public
#
def self.from(uri)
# find or create the URL scheme, host_name and port
- scheme = URLScheme.first_or_new(:name => uri.scheme)
+ scheme = URLScheme.first_or_new(:name => uri.scheme)
host_name = HostName.first_or_new(:address => uri.host)
- port = if uri.port
- TCPPort.first_or_new(:number => uri.port)
- end
+ port = if uri.port
+ TCPPort.first_or_new(:number => uri.port)
+ end
- path = normalized_path(uri)
+ path = normalized_path(uri)
fragment = uri.fragment
query_params = []
if uri.respond_to?(:query_params)
# find or create the URL query params
uri.query_params.each do |name,value|
query_params << {
- :name => URLQueryParamName.first_or_new(:name => name),
+ :name => URLQueryParamName.first_or_new(:name => name),
:value => value
}
end
end
# find or create the URL
return first_or_new(
- :scheme => scheme,
- :host_name => host_name,
- :port => port,
- :path => path,
- :fragment => fragment,
+ :scheme => scheme,
+ :host_name => host_name,
+ :port => port,
+ :path => path,
+ :fragment => fragment,
:query_params => query_params
)
end
#
@@ -420,11 +420,11 @@
self.query_params.each do |param|
params[param.name] = param.value
end
- return URI::QueryParams.dump(params)
+ return ::URI::QueryParams.dump(params)
end
#
# Sets the query params of the URL.
#
@@ -439,13 +439,13 @@
# @api public
#
def query_string=(query)
self.query_params.clear
- URI::QueryParams.parse(query).each do |name,value|
+ ::URI::QueryParams.parse(query).each do |name,value|
self.query_params.new(
- :name => URLQueryParamName.first_or_new(:name => name),
+ :name => URLQueryParamName.first_or_new(:name => name),
:value => value
)
end
return query
@@ -476,15 +476,15 @@
self.query_string
end
# build the URI
return url_class.build(
- :scheme => self.scheme.name,
- :host => host,
- :port => port,
- :path => self.path,
- :query => query,
+ :scheme => self.scheme.name,
+ :host => host,
+ :port => port,
+ :path => self.path,
+ :query => query,
:fragment => self.fragment
)
end
#
@@ -530,10 +530,10 @@
#
# @api private
#
def self.normalized_path(uri)
case uri
- when URI::HTTP
+ when ::URI::HTTP
# map empty HTTP paths to '/'
unless uri.path.empty?
uri.path
else
'/'