Class: Embiggen::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/embiggen/uri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ URI

Returns a new instance of URI.



11
12
13
14
# File 'lib/embiggen/uri.rb', line 11

def initialize(uri)
  @uri = URI(::Addressable::URI.parse(uri).normalize.to_s)
  @http_client = HttpClient.new(@uri)
end

Instance Attribute Details

#http_clientObject (readonly)

Returns the value of attribute http_client.



9
10
11
# File 'lib/embiggen/uri.rb', line 9

def http_client
  @http_client
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/embiggen/uri.rb', line 9

def uri
  @uri
end

Instance Method Details

#expand(request_options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/embiggen/uri.rb', line 16

def expand(request_options = {})
  return uri unless shortened?

  redirects = extract_redirects(request_options)
  location = follow(request_options)

  self.class.new(location).
    expand(request_options.merge(:redirects => redirects - 1))
end

#shortened?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/embiggen/uri.rb', line 26

def shortened?
  Configuration.shorteners.include?(uri)
end