Module: Api::Extensions::Fields

Defined in:
lib/api/extensions/fields.rb

Instance Method Summary collapse

Instance Method Details

#parse_fields(fields_string) ⇒ Object

Parse a string for the fields functional extension

- Add the required fields if not present


20
21
22
# File 'lib/api/extensions/fields.rb', line 20

def parse_fields(fields_string)
  required_fields + fields_string.split(',')
end

#process_fields(keys, response, full_link = nil) ⇒ Object

Process the fields functional extension



10
11
12
13
14
15
16
# File 'lib/api/extensions/fields.rb', line 10

def process_fields(keys, response, full_link = nil)
  fields = parse_fields keys
  response.reject! { |k, v| !fields.include? k } if fields.length > 0
  response['links']['full'] = { 'href' => full_link } unless full_link.nil?

  response
end

#required_fieldsObject

Get the required fields for any response



25
26
27
# File 'lib/api/extensions/fields.rb', line 25

def required_fields
  ['links']
end