lib/ronin/url.rb in ronin-1.0.0 vs lib/ronin/url.rb in ronin-1.1.0.rc1

- old
+ new

@@ -16,24 +16,23 @@ # You should have received a copy of the GNU General Public License # along with Ronin. If not, see <http://www.gnu.org/licenses/>. # require 'ronin/model' +require 'ronin/url_scheme' +require 'ronin/url_query_param' +require 'ronin/host_name' +require 'ronin/tcp_port' +require 'ronin/web_credential' require 'dm-timestamps' require 'uri/http' require 'uri/https' require 'uri/ftp' require 'uri/query_params' module Ronin - autoload :URLScheme, 'ronin/url_scheme' - autoload :URLQueryParam, 'ronin/url_query_param' - autoload :HostName, 'ronin/host_name' - autoload :TCPPort, 'ronin/tcp_port' - autoload :WebCredential, 'ronin/web_credential' - # # Represents URLs that can be stored in the {Database}. # class URL @@ -83,10 +82,12 @@ # @return [Array<URL>] # The matching URLs. # # @since 1.0.0 # + # @api public + # def self.http all(:scheme => {:name => 'http'}) end # @@ -95,10 +96,12 @@ # @return [Array<URL>] # The matching URLs. # # @since 1.0.0 # + # @api public + # def self.https all(:scheme => {:name => 'https'}) end # @@ -110,10 +113,12 @@ # @return [Array<URL>] # The matching URLs. # # @since 1.0.0 # + # @api public + # def self.hosts(names) all(:host => {:address => names}) end # @@ -125,10 +130,12 @@ # @return [Array<URL>] # The matching URLs. # # @since 1.0.0 # + # @api public + # def self.ports(numbers) all(:port => {:number => numbers}) end # @@ -140,10 +147,12 @@ # @return [Array<URL>] # The URL with the common sub-directory. # # @since 1.0.0 # + # @api public + # def self.directory(sub_dir) all(:path => sub_dir) | all(:path.like => "#{sub_dir}/%") end # @@ -155,40 +164,46 @@ # @return [Array<URL>] # The URLs with the common file-extension. # # @since 1.0.0 # + # @api public + # def self.extension(ext) all(:path => "%.#{ext}") end # - # Searches for URLs with the given query-param. + # Searches for URLs with the given query param. # # @param [Array<String>, String] name - # The query-param name to search for. + # The query param name to search for. # # @return [Array<URL>] - # The URLs with the given query-param. + # The URLs with the given query param. # # @since 1.0.0 # + # @api public + # def self.query_param(name) all(:query_params => {:name => name}) end # - # Search for all URLs with a given query-param value. + # Search for all URLs with a given query param value. # # @param [Array<String>, String] value - # The query-param value to search for. + # The query param value to search for. # # @return [Array<URL>] - # The URLs with the given query-param value. + # The URLs with the given query param value. # # @since 1.0.0 # + # @api public + # def self.query_value(value) all(:query_params => {:value => value}) end # @@ -200,10 +215,12 @@ # @return [URL, nil] # The matching URL. # # @since 1.0.0 # + # @api public + # def self.[](url) return super(url) if url.kind_of?(Integer) # optionally parse the URL unless url.kind_of?(::URI) @@ -247,10 +264,12 @@ # @return [URL] # The new URL. # # @since 1.0.0 # + # @api public + # def self.from(uri) # find or create the URL scheme, host_name and port scheme = self.scheme.model.first_or_new(:name => uri.scheme) host_name = self.host_name.model.first_or_new(:address => uri.host) port = if uri.port @@ -294,10 +313,12 @@ # # @see URL.from # # @since 1.0.0 # + # @api public + # def self.parse(url) from(::URI.parse(url)) end # @@ -306,10 +327,12 @@ # @return [String] # The address of host name. # # @since 1.0.0 # + # @api public + # def host self.host_name.address end # @@ -318,10 +341,12 @@ # @return [Integer, nil] # The port number. # # @since 1.0.0 # + # @api public + # def port_number self.port.number if self.port end # @@ -330,10 +355,12 @@ # @return [String] # The URI query string. # # @since 1.0.0 # + # @api public + # def query_string params = {} self.query_params.each do |param| params[param.name] = param.value @@ -351,10 +378,12 @@ # @return [String] # The given query string. # # @since 1.0.0 # + # @api public + # def query_string=(query) self.query_params.clear URI::QueryParams.parse(query).each do |name,value| self.query_params.new(:name => name, :value => value) @@ -369,10 +398,12 @@ # @return [URI::HTTP, URI::HTTPS] # The URI object created from the URL attributes. # # @since 1.0.0 # + # @api public + # def to_uri # map the URL scheme to a URI class url_class = (SCHEMES[self.scheme.name] || ::URI::Generic) host = if self.host_name @@ -403,10 +434,12 @@ # @return [String] # The string form of the URL. # # @since 1.0.0 # + # @api public + # def to_s self.to_uri.to_s end protected @@ -419,9 +452,11 @@ # # @return [String, nil] # The normalized path. # # @since 1.0.0 + # + # @api private # def self.normalized_path(uri) case uri when URI::HTTP # map empty HTTP paths to '/'