Module: One::EmailDirect::Mixins::SourceFacade
- Included in:
- Facade
- Defined in:
- lib/one/email_direct/mixins/source.rb
Instance Method Summary collapse
-
#source_add(credentials, name, description) ⇒ Object
Creates a new source on the given EmailDirect account.
-
#source_delete(credentials, source_id) ⇒ Object
Deletes a source on the given EmailDirect account.
-
#source_get(credentials, name) ⇒ Hash
Returns the whole information of a source on the given EmailDirect account.
-
#source_getall(credentials) ⇒ Array
Returns all sources on the given EmailDirect account.
Instance Method Details
#source_add(credentials, name, description) ⇒ Object
Creates a new source on the given EmailDirect account.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/one/email_direct/mixins/source.rb', line 11 def source_add(credentials, name, description) response = send_soap( :source_add, {:soap_action => 'http://espapi.net/v1/Source_Add', :credentials => credentials, :source_name => name, :source_description => description} ) raise One::EmailDirect::EmailDirectException.new(response[:code], response[:message]) if response[:code] != '0' end |
#source_delete(credentials, source_id) ⇒ Object
Deletes a source on the given EmailDirect account.
31 32 33 34 35 36 37 38 39 |
# File 'lib/one/email_direct/mixins/source.rb', line 31 def source_delete(credentials, source_id) response = send_soap( :source_delete, {:soap_action => 'http://espapi.net/v1/Source_Delete', :credentials => credentials, :source_id => source_id} ) raise One::EmailDirect::EmailDirectException.new(response[:code], response[:message]) if response[:code] != '0' end |
#source_get(credentials, name) ⇒ Hash
Returns the whole information of a source on the given EmailDirect account.
51 52 53 54 |
# File 'lib/one/email_direct/mixins/source.rb', line 51 def source_get(credentials, name) source_getall(credentials).each {|element| return element if element[:element_name] == name} nil end |
#source_getall(credentials) ⇒ Array
Returns all sources on the given EmailDirect account.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/one/email_direct/mixins/source.rb', line 66 def source_getall(credentials) response = send_soap( :source_get_all, {:soap_action => 'http://espapi.net/v1/Source_GetAll', :credentials => credentials} ) # no elements were returned return [] if response.nil? # if it only has one element (Hash) you have to transform it to a single array element return [response[:element]] if response[:element].instance_of? Hash # more than 1 element if !block_given? elements = [] response[:element].each {|element| elements << element } elements else response[:element].each {|element| yield element } end end |