Class: Acoustid::API::Request::Base
- Inherits:
-
Object
- Object
- Acoustid::API::Request::Base
- Extended by:
- ParamAttributes, ParamValidations
- Defined in:
- lib/acoustid/api/request/base.rb
Direct Known Subclasses
Constant Summary
Constants included from ParamValidations
ParamValidations::VALID_META_VALUES
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #uri ⇒ Object
- #valid? ⇒ Boolean
Methods included from ParamAttributes
param, param_reader, param_writer, required_params
Methods included from ParamValidations
serialize_integer, serialize_meta, serialize_string, validate_duration, validate_format, validate_meta
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
33 34 35 36 37 38 |
# File 'lib/acoustid/api/request/base.rb', line 33 def initialize(params={}) raise TypeError, 'params must respond to :to_hash or :to_h' unless params.respond_to?(:to_hash) || params.respond_to?(:to_h) params = params.to_hash rescue params.to_h params.each { |param, value| send("#{param}=", value) } end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
28 29 30 |
# File 'lib/acoustid/api/request/base.rb', line 28 def params @params end |
Class Method Details
.base_uri ⇒ Object
16 17 18 |
# File 'lib/acoustid/api/request/base.rb', line 16 def base_uri URI.parse('http://api.acoustid.org/v2/') end |
.path(value = nil) ⇒ Object
20 21 22 23 24 |
# File 'lib/acoustid/api/request/base.rb', line 20 def path(value=nil) @path = value.to_s.strip unless value.nil? @path end |
Instance Method Details
#uri ⇒ Object
40 41 42 43 44 45 |
# File 'lib/acoustid/api/request/base.rb', line 40 def uri uri = self.class.base_uri.dup uri.path += self.class.path uri end |
#valid? ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/acoustid/api/request/base.rb', line 47 def valid? self.class.required_params.none? do |required_param| param = send(required_param) param.nil? || param.empty?# rescue true end end |