Class: Connfu::Provisioning::Phone

Inherits:
Object
  • Object
show all
Defined in:
lib/connfu/provisioning/phone.rb

Overview

connFu Phone (belongs to a Voice channel)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(voice, phone_number, country = "") ⇒ Phone

Returns a new instance of Phone.

Parameters:

  • voice

    voice channel identifier

  • phone_number
  • country (defaults to: "")


22
23
24
25
26
# File 'lib/connfu/provisioning/phone.rb', line 22

def initialize(voice, phone_number, country = "")
  @voice = voice
  @phone_number = phone_number
  @country = country
end

Instance Attribute Details

#countryObject

specific country where the phone is allocated



11
12
13
# File 'lib/connfu/provisioning/phone.rb', line 11

def country
  @country
end

#phone_numberObject

phone number



14
15
16
# File 'lib/connfu/provisioning/phone.rb', line 14

def phone_number
  @phone_number
end

#voiceObject (readonly)

voice channel unique identifier



17
18
19
# File 'lib/connfu/provisioning/phone.rb', line 17

def voice
  @voice
end

Class Method Details

.unmarshal(voice, data) ⇒ Object

Creates a Phone object using the raw data from the provisioning API

Parameters:

  • voice

    channel unique identifier

  • data

    Hash containing the raw data



45
46
47
48
49
50
51
# File 'lib/connfu/provisioning/phone.rb', line 45

def self.unmarshal(voice, data)
  if data.is_a?(Array)
    data.map{|item| Phone.new(voice, item["phone_number"], item["country"])}
  else
    Phone.new(voice, data["phone_number"], data["country"])
  end
end

Instance Method Details

#[](value) ⇒ Object

Hash way to retrieve attributes



29
30
31
# File 'lib/connfu/provisioning/phone.rb', line 29

def [](value)
  self.respond_to?(value.to_sym) ? self.send(value.to_sym) : nil
end

#to_hashObject



33
34
35
# File 'lib/connfu/provisioning/phone.rb', line 33

def to_hash
  {"country" => country, "phone_number" => phone_number}
end

#to_sObject



37
38
39
# File 'lib/connfu/provisioning/phone.rb', line 37

def to_s
  "#{self.class.to_s}: #{to_hash}"
end