Class: SignalApi::Carrier

Inherits:
SignalHttpApi show all
Defined in:
lib/signal_api/carrier.rb

Overview

Managed carrier from signal api

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name) ⇒ Carrier

Returns a new instance of Carrier.



12
13
14
15
# File 'lib/signal_api/carrier.rb', line 12

def initialize(id, name)
  @id = id
  @name = name
end

Instance Attribute Details

#idObject (readonly)

The Carrier id from Signal



7
8
9
# File 'lib/signal_api/carrier.rb', line 7

def id
  @id
end

#nameObject (readonly)

The Carrier name from Signal



10
11
12
# File 'lib/signal_api/carrier.rb', line 10

def name
  @name
end

Class Method Details

.lookup(mobile_phone) ⇒ carrier

Lookup a carrier on textme

Parameters:

  • mobile_phone (String)

    The mobile phone to lookup

Returns:

  • (carrier)

    A Carrier object representing the Carrier on the Signal platform

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/signal_api/carrier.rb', line 22

def self.lookup(mobile_phone)
  raise InvalidParameterException.new("mobile_phone cannot be blank") if mobile_phone.blank?

  SignalApi.logger.info "Attempting to lookup carrier for mobile phone #{mobile_phone}"

  with_retries do
    response = get("/app/carriers/lookup/#{mobile_phone}.xml",
                   :format => :xml,
                   :headers => common_headers)

    if response.code == 200 && response.parsed_response['carrier']
      Carrier.new(response.parsed_response['carrier']['id'], response.parsed_response['carrier']['name'])
    elsif response.code == 404
      raise InvalidMobilePhoneException.new("carrier for mobile phone #{mobile_phone} could not be found") 
    else
      handle_api_failure(response)
    end
  end
end