Class: BasicResponse
- Inherits:
-
Object
- Object
- BasicResponse
- Defined in:
- lib/basic_response.rb
Overview
Base class for service responses.
Direct Known Subclasses
AccountBalanceResponse, CallStatusResponse, ConferenceCallService::AddConferenceTemplateParticipantResponse, ConferenceCallService::CommitConferenceResponse, ConferenceCallService::CreateConferenceResponse, ConferenceCallService::CreateConferenceTemplateResponse, ConferenceCallService::GetConferenceListResponse, ConferenceCallService::GetConferenceStatusResponse, ConferenceCallService::GetConferenceTemplateListResponse, ConferenceCallService::GetConferenceTemplateParticipantResponse, ConferenceCallService::GetConferenceTemplateResponse, ConferenceCallService::GetParticipantStatusResponse, ConferenceCallService::GetRunningConferenceResponse, ConferenceCallService::NewParticipantResponse, ConferenceCallService::RemoveConferenceResponse, ConferenceCallService::RemoveConferenceTemplateParticipantResponse, ConferenceCallService::RemoveConferenceTemplateResponse, ConferenceCallService::RemoveParticipantResponse, ConferenceCallService::UpdateConferenceResponse, ConferenceCallService::UpdateConferenceTemplateParticipantResponse, ConferenceCallService::UpdateConferenceTemplateResponse, ConferenceCallService::UpdateParticipantResponse, IpLocationService::IpLocationResponse, LocalSearchService::LocalSearchResponse, QuotaService::QuotaInformation, SmsGetValidatedNumbersResponse, SmsResponse, SmsSendValidationResponse, VoiceCallResponse
Instance Attribute Summary collapse
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
Instance Method Summary collapse
-
#initialize(response_xml, raise_exception_on_error = true) ⇒ BasicResponse
constructor
Constructor.
-
#inizialize ⇒ Object
Constructor.
-
#raise_on_error(response_xml) ⇒ Object
Raises an exception if the response is an error.
-
#to_s ⇒ Object
Returns
self.inspect
.
Constructor Details
#initialize(response_xml, raise_exception_on_error = true) ⇒ BasicResponse
Constructor.
Parameters
response_xml
-
Xml as returned by a
status
-method call. raise_exception_on_error
-
Xml as returned by a
status
-method call.
15 16 17 18 19 20 |
# File 'lib/basic_response.rb', line 15 def initialize(response_xml, raise_exception_on_error = true) doc = response_xml.document @error_code = doc.xpath("//errorCode").to_s || doc.xpath("//statusCode").to_s @error_message = doc.xpath("//errorMessage").to_s || doc.xpath("//statusMessage").to_s raise_on_error(response_xml) if raise_exception_on_error end |
Instance Attribute Details
#error_code ⇒ Object
Returns the value of attribute error_code.
5 6 7 |
# File 'lib/basic_response.rb', line 5 def error_code @error_code end |
#error_message ⇒ Object
Returns the value of attribute error_message.
5 6 7 |
# File 'lib/basic_response.rb', line 5 def @error_message end |
Instance Method Details
#inizialize ⇒ Object
Constructor
8 9 |
# File 'lib/basic_response.rb', line 8 def inizialize end |
#raise_on_error(response_xml) ⇒ Object
Raises an exception if the response is an error. Since in some response types the error code is not named “errorCode” it is not possible to call this method only in the constructur of this base class. This is sufficient for services using the BaseResponse directly but subclasses of BaseResponse need to call this method at the end of their constructure initialize
.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/basic_response.rb', line 32 def raise_on_error(response_xml) if @error_code && !@error_code.empty? && @error_code != "0000" then # It is important to create the exception with self.class.new and not only BasicResponse.new # This is because this method can be also invoked from a subclass. If a VoiceCallResponse object for example # raises an exception you will receive "VoiceCallResponse" from self.class. This is very important because # only the VoiceCallResponse knows that in this case the response code is called <tt>status</tt>. # This is because there is an inconsistency within the different service responses. raise(ServiceException.new( self.class.new(response_xml, false) ), "The developer garden service you invoked responded with an error: " + @error_message.to_s) end end |
#to_s ⇒ Object
Returns self.inspect
. Good for debugging purposes.
23 24 25 |
# File 'lib/basic_response.rb', line 23 def to_s return self.inspect end |