Class: Elk::Number
Overview
Allocate and manage numbers used for SMS/MMS/Voice
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
:nodoc:.
-
#country ⇒ Object
:nodoc:.
-
#loaded_at ⇒ Object
readonly
:nodoc:.
-
#number ⇒ Object
readonly
:nodoc:.
-
#number_id ⇒ Object
readonly
:nodoc:.
-
#sms_url ⇒ Object
:nodoc:.
-
#voice_start_url ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.all ⇒ Object
Returns all Elk::Numbers, regardless of status (allocated/deallocated).
-
.allocate(parameters) ⇒ Object
Allocates a phone number.
Instance Method Summary collapse
-
#deallocate! ⇒ Object
Deallocates a number, once allocated, a number cannot be used again, ever!.
-
#initialize(parameters) ⇒ Number
constructor
:nodoc:.
-
#reload ⇒ Object
Reloads a number from the API server.
-
#save ⇒ Object
Updates or allocates a number.
-
#set_paramaters(parameters) ⇒ Object
:nodoc:.
-
#status ⇒ Object
Status of a number, if it’s :active or :deallocated.
Methods included from Util
Constructor Details
#initialize(parameters) ⇒ Number
:nodoc:
7 8 9 |
# File 'lib/elk/number.rb', line 7 def initialize(parameters) #:nodoc: set_paramaters(parameters) end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/elk/number.rb', line 4 def capabilities @capabilities end |
#country ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/elk/number.rb', line 5 def country @country end |
#loaded_at ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/elk/number.rb', line 4 def loaded_at @loaded_at end |
#number ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/elk/number.rb', line 4 def number @number end |
#number_id ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/elk/number.rb', line 4 def number_id @number_id end |
#sms_url ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/elk/number.rb', line 5 def sms_url @sms_url end |
#voice_start_url ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/elk/number.rb', line 5 def voice_start_url @voice_start_url end |
Class Method Details
.all ⇒ Object
Returns all Elk::Numbers, regardless of status (allocated/deallocated)
73 74 75 76 77 78 79 |
# File 'lib/elk/number.rb', line 73 def all response = Elk.get('/Numbers') Elk.parse_json(response.body)[:data].collect do |n| self.new(n) end end |
.allocate(parameters) ⇒ Object
Allocates a phone number
-
Required parameters: :country
-
Optional parameters: :sms_url, :voice_start_url
66 67 68 69 70 |
# File 'lib/elk/number.rb', line 66 def allocate(parameters) verify_parameters(parameters, [:country]) response = Elk.post('/Numbers', parameters) self.new(Elk.parse_json(response.body)) end |
Instance Method Details
#deallocate! ⇒ Object
Deallocates a number, once allocated, a number cannot be used again, ever!
53 54 55 56 57 |
# File 'lib/elk/number.rb', line 53 def deallocate! response = Elk.post("/Numbers/#{self.number_id}", {:active => 'no'}) self.set_paramaters(Elk.parse_json(response.body)) response.code == 200 end |
#reload ⇒ Object
Reloads a number from the API server
35 36 37 38 39 |
# File 'lib/elk/number.rb', line 35 def reload response = Elk.get("/Numbers/#{self.number_id}") self.set_paramaters(Elk.parse_json(response.body)) response.code == 200 end |
#save ⇒ Object
Updates or allocates a number
42 43 44 45 46 47 48 49 50 |
# File 'lib/elk/number.rb', line 42 def save attributes = {:sms_url => self.sms_url, :voice_start => self.voice_start_url} # If new URL, send country, otherwise not if !self.number_id attributes[:country] = self.country end response = Elk.post("/Numbers/#{self.number_id}", attributes) response.code == 200 end |
#set_paramaters(parameters) ⇒ Object
:nodoc:
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/elk/number.rb', line 11 def set_paramaters(parameters) #:nodoc: @country = parameters[:country] @sms_url = parameters[:sms_url] @voice_start_url = parameters[:voice_start_url] @status = parameters[:active] @number_id = parameters[:id] @number = parameters[:number] @capabilities = parameters[:capabilities].collect {|c| c.to_sym } @loaded_at = Time.now end |
#status ⇒ Object
Status of a number, if it’s :active or :deallocated
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/elk/number.rb', line 23 def status case @status when 'yes' :active when 'no' :deallocated else nil end end |