Class: Ecircle::WrappedResponse
- Inherits:
-
Object
- Object
- Ecircle::WrappedResponse
- Defined in:
- lib/ecircle/wrapped_response.rb
Instance Method Summary collapse
-
#initialize(options_or_exception) ⇒ WrappedResponse
constructor
We create a wrapped response in 2 cases: 1.) We get a Savon::SOAP::Fault exception, so something went wrong.
-
#member_does_not_exist? ⇒ Boolean
Useful for
delete_member
requests. -
#message_id_does_not_exist? ⇒ Boolean
This method will tell you if you referred to a message id that ecircle doesn't know about.
-
#message_triggered_too_often? ⇒ Boolean
In case we try to send the same message twice within one second ecircle raises an exception (using an extremely helpful response).
-
#no_such_user? ⇒ Boolean
This method will tell you if referred to a user id that doesn't exist for ecircle.
- #not_authenticated? ⇒ Boolean
-
#permission_problem? ⇒ Boolean
(also: #no_such_group?)
If you do a create_member request where the group id you pass in doesn't exist you get back a "permission problem".
- #success? ⇒ Boolean
Constructor Details
#initialize(options_or_exception) ⇒ WrappedResponse
We create a wrapped response in 2 cases: 1.) We get a Savon::SOAP::Fault exception, so something went wrong. In this we get passed an exception. 2.) We get back a "regular" response. In this we get passed an hash.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ecircle/wrapped_response.rb', line 9 def initialize if .kind_of? Exception attributes = .to_hash @success = false @error_message = attributes[:fault][:detail][:fault][:error_message] @fault_code = attributes[:fault][:detail][:fault][:code].to_i elsif .kind_of? Hash @success = [:success] @error_message = [:error_message] @fault_code = [:fault_code] ? [:fault_code].to_i : nil @ecircle_id = [:ecircle_id] else raise ArgumentError, "!!! Was either expecting a hash or an exception but got: #{.class} !!!" end end |
Instance Method Details
#member_does_not_exist? ⇒ Boolean
Useful for delete_member
requests.
27 28 29 |
# File 'lib/ecircle/wrapped_response.rb', line 27 def member_does_not_exist? @fault_code == 100 && @error_message == 'No Member Id' end |
#message_id_does_not_exist? ⇒ Boolean
This method will tell you if you referred to a message id that ecircle doesn't know about. Usefull for send_parametrized_message_to_user requests. @return[Boolean]
52 53 54 |
# File 'lib/ecircle/wrapped_response.rb', line 52 def !!(@error_message =~ /MessageInfo '(\d+)' not found/) end |
#message_triggered_too_often? ⇒ Boolean
In case we try to send the same message twice within one second ecircle raises an exception (using an extremely helpful response). @return[Boolean]
63 64 65 |
# File 'lib/ecircle/wrapped_response.rb', line 63 def @fault_code == 200 && @error_message == 'Unexpected eC-M Reply Code: 304' end |
#no_such_user? ⇒ Boolean
This method will tell you if referred to a user id that doesn't exist for ecircle. Usefull for create_member requests
33 34 35 |
# File 'lib/ecircle/wrapped_response.rb', line 33 def no_such_user? @fault_code == 103 && @error_message == 'No such User' end |
#not_authenticated? ⇒ Boolean
45 46 47 |
# File 'lib/ecircle/wrapped_response.rb', line 45 def not_authenticated? @fault_code == 501 && @error_message == 'Not authenticated' end |
#permission_problem? ⇒ Boolean Also known as: no_such_group?
If you do a create_member request where the group id you pass in doesn't exist you get back a "permission problem". Yes, I know. It hurts.
40 41 42 |
# File 'lib/ecircle/wrapped_response.rb', line 40 def @fault_code == 502 && @error_message = 'Permission Problem' end |
#success? ⇒ Boolean
56 57 58 |
# File 'lib/ecircle/wrapped_response.rb', line 56 def success? @success end |