Class: Connfu::Provisioning::Channel
- Inherits:
-
Object
- Object
- Connfu::Provisioning::Channel
- Defined in:
- lib/connfu/provisioning/channel.rb
Overview
Channel class models a connFu application channel. Its the superclass of Twitter and Voice and any other forthcoming connFu channel
Instance Attribute Summary collapse
-
#channel_type ⇒ Object
channel type.
-
#created_at ⇒ Object
created at timestamp.
-
#uid ⇒ Object
channel unique identifier.
-
#updated_at ⇒ Object
updated at timestamp.
Class Method Summary collapse
-
.unmarshal(data) ⇒ Object
Creates a Channel instance (or a Channel child class instance) object or an Array using a Hash values.
Instance Method Summary collapse
-
#initialize(params) ⇒ Channel
constructor
Creates a Channel instance using a Hash values It creates an instance variable per each hash key.
-
#to_hash ⇒ Object
Creates a hash with the instance info.
-
#to_s ⇒ Object
Print object using metaprogramming.
Constructor Details
#initialize(params) ⇒ Channel
Creates a Channel instance using a Hash values It creates an instance variable per each hash key
24 25 26 27 28 29 |
# File 'lib/connfu/provisioning/channel.rb', line 24 def initialize(params) self.channel_type = self.class.to_s.downcase params.each_pair { |key, value| self.instance_variable_set("@#{key}", value) } end |
Instance Attribute Details
#channel_type ⇒ Object
channel type
20 21 22 |
# File 'lib/connfu/provisioning/channel.rb', line 20 def channel_type @channel_type end |
#created_at ⇒ Object
created at timestamp
11 12 13 |
# File 'lib/connfu/provisioning/channel.rb', line 11 def created_at @created_at end |
#uid ⇒ Object
channel unique identifier
17 18 19 |
# File 'lib/connfu/provisioning/channel.rb', line 17 def uid @uid end |
#updated_at ⇒ Object
updated at timestamp
14 15 16 |
# File 'lib/connfu/provisioning/channel.rb', line 14 def updated_at @updated_at end |
Class Method Details
.unmarshal(data) ⇒ Object
Creates a Channel instance (or a Channel child class instance) object or an Array using a Hash values
Parameters
-
data- hash containing channel information retrieved using the connFu API
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/connfu/provisioning/channel.rb', line 54 def unmarshal(data) # Helper to get the channel class using the channel_type attribute (we are # retrieving all the channels) or the client class (we are retrieving # specific a channel type) create_channel = lambda { |channel| if channel.has_key?("type") && ListenerChannel::CHANNEL_TYPES.include?(channel["type"].to_sym) # get the class from type attribute (get all channels) channel_type = channel["type"].capitalize Connfu::Provisioning.const_get(channel_type).new(channel) else # get the class from class self.new(channel) end } if data.is_a?(Array) # more than one element data.map { |channel| create_channel.call(channel) } else # one element create_channel.call(data) end end |
Instance Method Details
#to_hash ⇒ Object
Creates a hash with the instance info
32 33 34 |
# File 'lib/connfu/provisioning/channel.rb', line 32 def to_hash {"uid" => uid} end |
#to_s ⇒ Object
Print object using metaprogramming. This method is used by any child class
37 38 39 40 41 42 43 |
# File 'lib/connfu/provisioning/channel.rb', line 37 def to_s value = [] self.instance_variables.each { |var| value << "#{var[1..-1]}: #{self.instance_variable_get(var)}" } self.class.name + "{\n" + value.join("\t\n").to_s + "\n}" end |