Class: Xively::Resource
- Includes:
- Validations
- Defined in:
- lib/xively-rb/resource.rb
Constant Summary collapse
- ALLOWED_KEYS =
%w(feed_id datastream_id datastream_trigger_id)
Instance Attribute Summary
Attributes included from Validations
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(input) ⇒ Object
-
#initialize(input = {}) ⇒ Resource
constructor
A new instance of Resource.
- #valid? ⇒ Boolean
Constructor Details
#initialize(input = {}) ⇒ Resource
Returns a new instance of Resource.
23 24 25 |
# File 'lib/xively-rb/resource.rb', line 23 def initialize(input = {}) self.attributes = input end |
Instance Method Details
#attributes ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/xively-rb/resource.rb', line 27 def attributes h = {} ALLOWED_KEYS.each do |key| value = self.send(key) h[key] = value unless value.nil? end return h end |
#attributes=(input) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/xively-rb/resource.rb', line 36 def attributes=(input) return if input.nil? input.deep_stringify_keys! ALLOWED_KEYS.each { |key| self.send("#{key}=", input[key]) } return attributes end |
#valid? ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/xively-rb/resource.rb', line 8 def valid? pass = true if feed_id.blank? && datastream_id.blank? && datastream_trigger_id.blank? errors[:feed_id] = "Must supply at least one of feed_id (optionally with a datastream_id) or datastream_trigger_id" pass = false end if feed_id.blank? && !datastream_id.blank? errors[:feed_id] = ["can't be blank if we have supplied a datastream_id"] pass = false end return pass end |