Class: Telein::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/telein/client.rb

Overview

Class used to query Telein servers for carrier codes

No API key given

The client doesn't make any request if the API key is missing, returning a 999 code immediately.

Invalid phones

Telein can tell if a given phone is invalid but each request is a credit spent so the class also encapsulates the code from Telein::Util::Phone to detect invalid ones preemptively.

All servers down

If all Registered servers are down, then the client return 101 for carrier_code

Examples:

Query servers for the carrier code of a given phone

client = Telein::Client.new
client.carrier_code_for('(12) 3434-5656') # => '41'

Instance Method Summary collapse

Instance Method Details

#carrier_code_for(value) ⇒ Integer

Deprecated.

Use #query for greater functionality.

Filters the query to the Telein servers so that it only returns the carrier code.

Parameters:

  • value (String)

    A string supposedly containing phone information

Returns:

  • (Integer)

    The carrier code for value



79
80
81
# File 'lib/telein/client.rb', line 79

def carrier_code_for(value)
  return query(value)[:carrier_code]
end

#query(value) ⇒ Object



69
70
71
72
# File 'lib/telein/client.rb', line 69

def query(value)
  carrier_code, number = raw_query(value)
  return { :carrier_code => carrier_code, :number => number }
end