Class: SignalApi::Carrier
- Inherits:
-
SignalHttpApi
- Object
- SignalHttpApi
- SignalApi::Carrier
- Defined in:
- lib/signal_api/carrier.rb
Overview
Managed carrier from signal api
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The Carrier id from Signal.
-
#name ⇒ Object
readonly
The Carrier name from Signal.
Class Method Summary collapse
-
.lookup(mobile_phone) ⇒ carrier
Lookup a carrier on textme.
Instance Method Summary collapse
-
#initialize(id, name) ⇒ Carrier
constructor
A new instance of Carrier.
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
#id ⇒ Object (readonly)
The Carrier id from Signal
7 8 9 |
# File 'lib/signal_api/carrier.rb', line 7 def id @id end |
#name ⇒ Object (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
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 |