Class: Ecircle::WrappedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/ecircle/wrapped_response.rb

Instance Method Summary (collapse)

Constructor Details

- (WrappedResponse) initialize(options_or_exception)

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 options_or_exception
  if options_or_exception.kind_of? Exception
    attributes = options_or_exception.to_hash
    @success       = false
    @error_message = attributes[:fault][:detail][:fault][:error_message]
    @fault_code    = attributes[:fault][:detail][:fault][:code].to_i
  elsif options_or_exception.kind_of? Hash
    @success       = options_or_exception[:success]
    @error_message = options_or_exception[:error_message]
    @fault_code    = options_or_exception[:fault_code] ? options_or_exception[:fault_code].to_i : nil
    @ecircle_id    = options_or_exception[:ecircle_id]
  else
    raise ArgumentError, "!!! Was either expecting a hash or an exception but got: #{options_or_exception.class} !!!"
  end
end

Instance Method Details

- (Boolean) member_does_not_exist?

Useful for delete_member requests.

Returns:

  • (Boolean)


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

- (Boolean) message_id_does_not_exist?

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]

Returns:

  • (Boolean)


52
53
54
# File 'lib/ecircle/wrapped_response.rb', line 52

def message_id_does_not_exist?
  !!(@error_message =~ /MessageInfo '(\d+)' not found/)
end

- (Boolean) message_triggered_too_often?

In case we try to send the same message twice within one second ecircle raises an exception (using an extremely helpful response). @return[Boolean]

Returns:

  • (Boolean)


63
64
65
# File 'lib/ecircle/wrapped_response.rb', line 63

def message_triggered_too_often?
  @fault_code == 200 && @error_message == 'Unexpected eC-M Reply Code: 304'
end

- (Boolean) no_such_user?

This method will tell you if referred to a user id that doesn't exist for ecircle. Usefull for create_member requests

Returns:

  • (Boolean)


33
34
35
# File 'lib/ecircle/wrapped_response.rb', line 33

def no_such_user?
  @fault_code == 103 && @error_message == 'No such User'
end

- (Boolean) not_authenticated?

Returns:

  • (Boolean)


45
46
47
# File 'lib/ecircle/wrapped_response.rb', line 45

def not_authenticated?
  @fault_code == 501 && @error_message == 'Not authenticated'
end

- (Boolean) permission_problem? 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.

Returns:

  • (Boolean)


40
41
42
# File 'lib/ecircle/wrapped_response.rb', line 40

def permission_problem?
  @fault_code == 502 && @error_message = 'Permission Problem'
end

- (Boolean) success?

Returns:

  • (Boolean)


56
57
58
# File 'lib/ecircle/wrapped_response.rb', line 56

def success?
  @success
end