Module: Ur::RequestAndResponse

Includes:
FaradayEntity
Included in:
Request, Response
Defined in:
lib/ur/request_and_response.rb

Overview

functionality common to Request and Response

Defined Under Namespace

Modules: FaradayEntity

Instance Method Summary collapse

Methods included from FaradayEntity

#set_body_from_faraday

Instance Method Details

#content_typeUr::ContentType

the string value of the content type header. returns an ContentType, a subclass of String which additionally parses the Content-Type according to relevant RFCs.

Returns:



32
33
34
35
36
37
# File 'lib/ur/request_and_response.rb', line 32

def content_type
  headers.each do |k, v|
    return ContentType.new(v) if k =~ /\Acontent[-_]type\z/i
  end
  nil
end

#form_urlencoded?Boolean

is our content type x-www-form-urlencoded?

Returns:

  • (Boolean)


66
67
68
# File 'lib/ur/request_and_response.rb', line 66

def form_urlencoded?
  content_type && content_type.form_urlencoded?
end

#json?Boolean

is our content type JSON?

Returns:

  • (Boolean)


54
55
56
# File 'lib/ur/request_and_response.rb', line 54

def json?
  content_type && content_type.json?
end

Returns:



45
46
47
48
49
50
# File 'lib/ur/request_and_response.rb', line 45

def links
  headers.each do |k, v|
    return(Weblink.parse_link_value(v, ur.request.uri)) if k =~ /\Alink\z/i
  end
  [].freeze
end

#media_typeObject

the media type of the content type



40
41
42
# File 'lib/ur/request_and_response.rb', line 40

def media_type
  content_type ? content_type.media_type : nil
end

#xml?Boolean

is our content type XML?

Returns:

  • (Boolean)


60
61
62
# File 'lib/ur/request_and_response.rb', line 60

def xml?
  content_type && content_type.xml?
end