Class: WADL::RequestFormat

Inherits:
HasDocs show all
Includes:
RepresentationContainer
Defined in:
lib/wadl/request_format.rb

Constant Summary

Constant Summary

Constants inherited from CheapSchema

CheapSchema::ATTRIBUTES

Instance Attribute Summary

Attributes inherited from CheapSchema

#attributes, #href, #index_key, #parent

Instance Method Summary collapse

Methods included from RepresentationContainer

#find_form, #find_representation_by_media_type

Methods inherited from HasDocs

#define_singleton

Methods inherited from CheapSchema

as_collection, as_member, contents_are_mixed_data, #dereference, #dereference_with_context, dereferencing_attr_accessor, dereferencing_instance_accessor, #each_attribute, #each_collection, #each_member, from_element, has_attributes, has_many, has_one, has_required, in_document, inherit, inherited, init, #initialize, #matches?, may_be_reference, may_be_reference?, #paths, #to_s

Constructor Details

This class inherits a constructor from WADL::CheapSchema

Instance Method Details

#uri(resource, args = {}) ⇒ Object

Returns a URI and a set of HTTP headers for this request.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/wadl/request_format.rb', line 39

def uri(resource, args = {})
  uri = resource.uri(args)

  query_values  = args[:query]   || {}
  header_values = args[:headers] || {}

  params.each { |param|
    name = param.name

    if param.style == 'header'
      value = header_values[name] || header_values[name.to_sym]
      value = param % value

      uri.headers[name] = value if value
    else
      value = query_values[name] || query_values[name.to_sym]
      value = param.format(value, nil, 'query')

      uri.query << value if value && !value.empty?
    end
  }

  uri
end