Module: Acoustid::API::Request::ParamValidations

Included in:
Base
Defined in:
lib/acoustid/api/request/param_validations.rb

Constant Summary collapse

VALID_META_VALUES =
%W[recordings recordingids releases releaseids releasegroups releasegroupids tracks compress usermeta sources]

Instance Method Summary collapse

Instance Method Details

#serialize_integer(value) ⇒ Object



13
14
15
# File 'lib/acoustid/api/request/param_validations.rb', line 13

def serialize_integer(value)
  value.nil? ? nil : value.to_i
end

#serialize_meta(value) ⇒ Object



17
18
19
# File 'lib/acoustid/api/request/param_validations.rb', line 17

def serialize_meta(value)
  value.nil? ? nil : value.to_a.collect { |value| value.to_s.strip }
end

#serialize_string(value) ⇒ Object



9
10
11
# File 'lib/acoustid/api/request/param_validations.rb', line 9

def serialize_string(value)
  value.nil? ? nil : value.to_s.strip
end

#validate_duration(value) ⇒ Object

Raises:

  • (TypeError)


25
26
27
# File 'lib/acoustid/api/request/param_validations.rb', line 25

def validate_duration(value)
  raise TypeError, 'duration must respond to :to_i' unless value.respond_to?(:to_i)
end

#validate_format(value) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
# File 'lib/acoustid/api/request/param_validations.rb', line 21

def validate_format(value)
  raise ArgumentError, '' unless %W[json jsonp xml].include?(value.to_s.strip)
end

#validate_meta(value) ⇒ Object

Raises:

  • (TypeError)


29
30
31
32
33
34
# File 'lib/acoustid/api/request/param_validations.rb', line 29

def validate_meta(value)
  raise TypeError, 'meta must respond to :to_a or be nil' unless value.nil? || value.respond_to?(:to_a)
  raise TypeError, "meta must only include #{ VALID_META_VALUES.join(', ') }" unless value.nil? || serialize_meta(value).all? { |meta| VALID_META_VALUES.include?(meta) }
  
  # TODO
end