Module: Urifetch
- Defined in:
- lib/urifetch.rb,
lib/urifetch/router.rb,
lib/urifetch/version.rb,
lib/urifetch/response.rb,
lib/urifetch/strategy.rb,
lib/urifetch/strategy/base.rb
Defined Under Namespace
Modules: Strategy, Version
Classes: Response, Router
Constant Summary
collapse
- @@router =
Router.new()
Class Method Summary
collapse
Class Method Details
.fetch(url, args = {}) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/urifetch.rb', line 26
def self.fetch(url,args={})
if valid_url?(url)
uri = Addressable::URI.heuristic_parse(url.to_s)
@@router.find(uri).execute!
else
raise ArgumentError, "Invalid URL"
end
end
|
.route(args = {}, &block) ⇒ Object
40
41
42
43
44
|
# File 'lib/urifetch.rb', line 40
def self.route(args={},&block)
@@router = Router.new(args) do
instance_eval(&block)
end
end
|
.valid_url?(url) ⇒ Boolean
35
36
37
38
|
# File 'lib/urifetch.rb', line 35
def self.valid_url?(url)
!(url =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix).nil?
end
|