Class: Telein::Server

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

Overview

The class that encapsulates all code that build request queries made to Telein servers by the client

Examples:

Instantiate a server and build a query for phone

server = Telein::Server.new('consultanumero1.telein.com.br')
server.query_url_for('1234345656')
=> 'http://consultanumero1.telein.com.br/sistema/consulta_numero.php?numero=1234345656&chave=my_api_key'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Server

Returns a new instance of Server.

Parameters:

  • endpoint (String)

    The URL of the server



19
20
21
# File 'lib/telein/server.rb', line 19

def initialize(endpoint)
  self.endpoint = endpoint
end

Instance Attribute Details

#endpointString

Gets/sets the endpoint (an URL) representing a Telein Server

Returns:

  • (String)

    the endpoint



16
17
18
# File 'lib/telein/server.rb', line 16

def endpoint
  @endpoint
end

Instance Method Details

#query_url_for(phone) ⇒ String

Builds a request URL to be used by the client to fetch the carrier code

Parameters:

Returns:

  • (String)

    A URL the client will use to fetch the carrier code

See Also:



28
29
30
31
32
33
# File 'lib/telein/server.rb', line 28

def query_url_for(phone)
  url = URI::HTTP.build({:host  => self.endpoint,
                         :path  => '/sistema/consulta_numero.php',
                         :query => URI::encode_www_form({:numero => phone,:chave => Telein.api_key})})
  url.to_s
end