Class: Ecircle::WrappedResponse

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

Instance Method Summary collapse

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 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

#member_does_not_exist?Boolean

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

#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]

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

#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]

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

#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

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

#not_authenticated?Boolean

Returns:

  • (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.

Returns:

  • (Boolean)


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

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

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  @success
end