Class: Responsys::Api::Client

Inherits:
Object
  • Object
show all
Includes:
All, Singleton
Defined in:
lib/responsys/api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Campaign

#check_failures, #trigger_message

Methods included from Table

#create_table, #create_table_with_pk, #delete_profile_extension_members, #delete_table, #delete_table_records, #merge_into_profile_extension, #merge_table_records, #merge_table_records_with_pk, #retrieve_profile_extension_records, #retrieve_table_records, #truncate_table

Methods included from Session

#login, #logout

Methods included from List

#merge_list_members, #merge_list_members_riid, #retrieve_list_members

Methods included from Folder

#create_folder, #delete_folder, #folder_exists?, #list_folders

Constructor Details

#initializeClient

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/responsys/api/client.rb', line 16

def initialize
  settings = Responsys.configuration.settings
  @credentials = {
    username: settings[:username],
    password: settings[:password]
  }

  if settings[:debug]
    @client = Savon.client(wsdl: settings[:wsdl], element_form_default: :qualified, log_level: :debug, log: true, pretty_print_xml: true)
  else
    @client = Savon.client(wsdl: settings[:wsdl], element_form_default: :qualified)
  end

  
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



14
15
16
# File 'lib/responsys/api/client.rb', line 14

def client
  @client
end

#credentialsObject

Returns the value of attribute credentials.



14
15
16
# File 'lib/responsys/api/client.rb', line 14

def credentials
  @credentials
end

#headerObject

Returns the value of attribute header.



14
15
16
# File 'lib/responsys/api/client.rb', line 14

def header
  @header
end

#jsession_idObject

Returns the value of attribute jsession_id.



14
15
16
# File 'lib/responsys/api/client.rb', line 14

def jsession_id
  @jsession_id
end

#session_idObject

Returns the value of attribute session_id.



14
15
16
# File 'lib/responsys/api/client.rb', line 14

def session_id
  @session_id
end

Instance Method Details

#api_method(action, message = nil, response_type = :hash) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/responsys/api/client.rb', line 32

def api_method(action, message = nil, response_type = :hash)
  begin
    response = run_with_credentials(action, message, jsession_id, header)

    case response_type
    when :result
      Responsys::Helper.format_response_result(response, action)
    when :hash
      Responsys::Helper.format_response_hash(response, action)
    end

  rescue Exception => e
    error_response = Responsys::Helper.format_response_with_errors(e)

    if error_response[:error][:code] == "INVALID_SESSION_ID"
      
      api_method(action, message, response_type)
    else
      error_response
    end
  end
end

#available_operationsObject



55
56
57
# File 'lib/responsys/api/client.rb', line 55

def available_operations
  @client.operations
end