Class: Teliaxr::API
- Inherits:
-
Object
- Object
- Teliaxr::API
- Defined in:
- lib/teliaxr.rb
Instance Attribute Summary collapse
-
#account_number(force_update = false) ⇒ Object
readonly
returns account number.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#account_balance(force_update = false) ⇒ Object
returns account balance as float.
-
#destination_for_number(nr, force_reload = false) ⇒ Object
returns current destination for this number.
-
#destinations ⇒ Object
returns list of teliax destinations.
-
#get_menu_links ⇒ Object
returns list of links this is test code.
-
#initialize(username, password, url = nil) ⇒ API
constructor
takes a username and password to log in to the teliax dashboard.
-
#numbers(force_reload = false) ⇒ Object
returns numbers list as an array, pass parameter force_reload to update list.
-
#proxies ⇒ Object
returns list of teliax proxies.
-
#proxy_for_number(nr, force_reload = false) ⇒ Object
returns proxy that is setup to originate calls to this number.
-
#search_for_new_numbers(area_code) ⇒ Object
returns list of new numbers based on area code.
-
#set_destination_for_number(nr, destination_name) ⇒ Object
sets rings to destination for this number, weather is a device or another ring number.
-
#set_proxy_for_number(nr, proxy_name) ⇒ Object
set the proxy this number will be get originated from.
Constructor Details
#initialize(username, password, url = nil) ⇒ API
takes a username and password to log in to the teliax dashboard
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/teliaxr.rb', line 16 def initialize(username, password, url=nil) @username = username @password = password @teliax_url = url @teliax_url ||= "https://www.teliax.com" @agent = WWW::Mechanize.new @numbers_list = {} @destinations_list = {} @proxies = { "denver" => {:proxy_url => "den.teliax.net", :proxy_id => "1"}, "new york" => {:proxy_url => "nyc.teliax.net", :proxy_id => "2"}, "los angeles" => {:proxy_url => "lax.teliax.net", :proxy_id => "3"}, "atlanta" => {:proxy_url => "atl.teliax.net", :proxy_id => "4"}, "fax" => {:proxy_url => "fax.teliax.net", :proxy_id => "7"} } @balance = nil @account = nil get_page(@teliax_url) login account_balance account_number end |
Instance Attribute Details
#account_number(force_update = false) ⇒ Object (readonly)
returns account number
80 81 82 |
# File 'lib/teliaxr.rb', line 80 def account_number @account_number end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
12 13 14 |
# File 'lib/teliaxr.rb', line 12 def page @page end |
Instance Method Details
#account_balance(force_update = false) ⇒ Object
returns account balance as float
71 72 73 74 75 |
# File 'lib/teliaxr.rb', line 71 def account_balance(force_update=false) #should check if force update has been requested return @balance unless @balance.nil? @balance = @page.search("div#site_left_nav_headerBlack a").first.content.gsub(/Balance \$/,'').to_f end |
#destination_for_number(nr, force_reload = false) ⇒ Object
returns current destination for this number
115 116 117 |
# File 'lib/teliaxr.rb', line 115 def destination_for_number(nr,force_reload=false) numbers(force_reload)[nr][:destination_name] end |
#destinations ⇒ Object
returns list of teliax destinations
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/teliaxr.rb', line 147 def destinations # unless @destinations_list.empty? return @destinations_list end click_link_by_name "Numbers" #goes to the numbers website @destinations_list={} @page.search('div#site_content_container_center table tbody tr:first-of-type td:nth-child(4) option').each do |opt| destination_id = opt.search('@value').text if destination_id == "_" destination_type = "nowhere" destination_name = opt.text else destination_type = destination_id.split("_").first.downcase.strip if destination_type == "number" destination_name = opt.text.gsub(/\D/,'') else destination_name = opt.text.split(":").last.strip end end #puts destination_type #puts destination_name #puts destination_id @destinations_list[destination_name] = {:destination_id => destination_id, :destination_type => destination_type } end @destinations_list end |
#get_menu_links ⇒ Object
returns list of links this is test code
186 187 188 189 190 191 192 |
# File 'lib/teliaxr.rb', line 186 def @page.search('div#site_left_nav_content div').each do |nav| nav.search('ul li a').each do |link| puts link.content end end end |
#numbers(force_reload = false) ⇒ Object
returns numbers list as an array, pass parameter force_reload to update list
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/teliaxr.rb', line 88 def numbers(force_reload=false) unless @numbers_list.empty? if force_reload == false return @numbers_list end end #puts "RELOADING: force: #{force_reload} list.empty?: #{@numbers_list.empty?}" click_link_by_name "Numbers" #goes to the numbers website @numbers_list={} @page.search('div#site_content_container_center table tbody tr').each do |tr| @numbers_list[tr.search('td:nth-child(1)').first.content.gsub(/\D/,'')] = { :number_id => tr.search('td:nth-child(3) @id').text.split("_").last.strip, :gateway_id => tr.search('td:nth-child(3) option[selected] @value'), :gateway_name => tr.search('td:nth-child(3) option[selected]').text, :destination_id => tr.search('td:nth-child(4) option[selected] @value'), :destination_name => tr.search('td:nth-child(4) option[selected]').text.split(":").last.strip } end @numbers_list end |
#proxies ⇒ Object
returns list of teliax proxies
141 142 143 |
# File 'lib/teliaxr.rb', line 141 def proxies @proxies end |
#proxy_for_number(nr, force_reload = false) ⇒ Object
returns proxy that is setup to originate calls to this number
129 130 131 |
# File 'lib/teliaxr.rb', line 129 def proxy_for_number(nr,force_reload=false) numbers(force_reload)[nr][:gateway_name] end |
#search_for_new_numbers(area_code) ⇒ Object
returns list of new numbers based on area code
181 182 |
# File 'lib/teliaxr.rb', line 181 def search_for_new_numbers(area_code) end |
#set_destination_for_number(nr, destination_name) ⇒ Object
sets rings to destination for this number, weather is a device or another ring number
122 123 124 125 |
# File 'lib/teliaxr.rb', line 122 def set_destination_for_number(nr,destination_name) @page = @agent.post(url_for_number(nr), {"number[destination]" => destinations[destination_name][:destination_id], "_method" => "put"}) end |
#set_proxy_for_number(nr, proxy_name) ⇒ Object
set the proxy this number will be get originated from
135 136 137 |
# File 'lib/teliaxr.rb', line 135 def set_proxy_for_number(nr,proxy_name) @page = @agent.post(url_for_number(nr), {"number[proxy_id]" => proxies[proxy_name][:proxy_id], "_method" => "put"}) end |