Class: Roast::Resources::UrlResource
Overview
Resource implementation for URLs
Instance Attribute Summary
Attributes inherited from BaseResource
#target
Instance Method Summary
collapse
#initialize
Instance Method Details
#contents ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/roast/resources/url_resource.rb', line 35
def contents
return unless target
begin
uri = URI.parse(target)
Net::HTTP.get(uri)
rescue StandardError => e
Roast::Helpers::Logger.error("Error fetching URL contents: #{e.message}")
nil
end
end
|
#exists? ⇒ Boolean
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/roast/resources/url_resource.rb', line 15
def exists?
return false unless target
begin
uri = URI.parse(target)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")
response = http.request_head(uri.path.empty? ? "/" : uri.path)
response.code.to_i < 400
rescue StandardError => e
Roast::Helpers::Logger.error("Error checking URL existence: #{e.message}")
false
end
end
|
#name ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/roast/resources/url_resource.rb', line 48
def name
if target
URI.parse(target).host
else
"Unnamed URL"
end
rescue URI::InvalidURIError
"Invalid URL"
end
|
#process ⇒ Object
10
11
12
13
|
# File 'lib/roast/resources/url_resource.rb', line 10
def process
target
end
|
#type ⇒ Object
58
59
60
|
# File 'lib/roast/resources/url_resource.rb', line 58
def type
:url
end
|