Class: Oembed::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/oembed/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parserObject



10
11
12
# File 'lib/oembed/http.rb', line 10

def parser
  @parser ||= Oembed::Parser.new
end

Instance Method Details

#get(path, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oembed/http.rb', line 14

def get(path, options = {})
  uri        = URI.parse(path)
  connection = establish_connection(uri.host, uri.port)
  response   = connection.get(uri.request_uri)

  case response
  when Net::HTTPRedirection
    follow_redirection(response['location'], options.fetch(:limit, 10))
  when Net::HTTPSuccess
    parser.parse(response.body, response.content_type)
  else
    raise Oembed::ResponseError.new(response), 'HTTP error during request'
  end
end