class Getvideo::Response
Constants
- CONTENT_TYPE
- PARSERS
Attributes
response[R]
Public Class Methods
new(response)
click to toggle source
# File lib/getvideo/video.rb, line 62 def initialize(response) @response = response end
Public Instance Methods
body()
click to toggle source
# File lib/getvideo/video.rb, line 85 def body decode(response.body) end
content_type()
click to toggle source
# File lib/getvideo/video.rb, line 108 def content_type ((response.headers.values_at('content-type', 'Content-Type').compact.first || '').split(';').first || '').strip end
decode(body)
click to toggle source
# File lib/getvideo/video.rb, line 89 def decode(body) return '' if !body return body if json? charset = body.match(/charset\s*=[\s|\W]*([\w-]+)/) if charset[1].downcase != "utf-8" begin body.encode! "utf-8", charset[1], {:invalid => :replace} rescue body end else body end end
headers()
click to toggle source
# File lib/getvideo/video.rb, line 81 def headers response.headers end
json?()
click to toggle source
# File lib/getvideo/video.rb, line 112 def json? CONTENT_TYPE[content_type] == :json || !response.body.match(/\<html/) end
parsed()
click to toggle source
# File lib/getvideo/video.rb, line 122 def parsed return nil unless CONTENT_TYPE.key?(content_type) return nil unless PARSERS.key?(parser) @parsed ||= PARSERS[parser].call(body) end
parser()
click to toggle source
# File lib/getvideo/video.rb, line 116 def parser type = CONTENT_TYPE[content_type] type = :json if type == :html && !response.body.match(/\<html/) return type end
status()
click to toggle source
# File lib/getvideo/video.rb, line 104 def status response.status end