Class: IccsSoap::CustomerService
- Inherits:
-
Object
- Object
- IccsSoap::CustomerService
- Defined in:
- lib/iccs-soap/customer_service.rb
Constant Summary collapse
- @@client =
Savon.client(:wsdl => IccsSoap::Config.customer_service.document_url, :endpoint => IccsSoap::Config.customer_service.endpoint_url, :namespace => IccsSoap::Config.customer_service.namespace_url, :log => $soap_log, :soap_header => %Q(<simpleAuth xmlns="http://xsoap.iccs.de/v1" username="#{IccsSoap::Config.security_service.user}" password="#{IccsSoap::Config.security_service.password}" />))
Class Method Summary collapse
-
.create_customer(*params) ⇒ Object
create a new customer on the remote system, there are lots of mandatory parameters: :first_name :last_name :externalId (our id, we’ll need it to find the customers later) :ndc (National Destination Code which is usually the area code without the leading zero) :street :house_number :zip_code :city.
-
.delete_customer(id) ⇒ Object
deletes the customer on the remote system using your (read: “foreignNr”) id note this will only succeed if no remnants are left there (e.g. assigned phone numbers).
- .external_id(id, hostname, app_id) ⇒ Object
-
.get_customer(id) ⇒ Object
finds the customer on the remote system using your (read: “foreignNr”) id.
-
.update_customer(*params) ⇒ Object
updates an existing customer on the remote system :id (mandatory, our id to find the customer) :first_name :last_name :external_id (we can change our customer_id) :ndc (National Destination Code which is usually the area code without the leading zero) :street :house_number :zip_code :city.
Class Method Details
.create_customer(*params) ⇒ Object
create a new customer on the remote system, there are lots of mandatory parameters:
:first_name
:last_name
:externalId (our id, we'll need it to find the customers later)
:ndc (National Destination Code which is usually the area code without the leading zero)
:street
:house_number
:zip_code
:city
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/iccs-soap/customer_service.rb', line 44 def create_customer(*params) params = params[0].inject({}) { |start, accu| start.merge({accu[0].to_sym => accu[1]})} response = @@client.call(:create_customer, :message => { :externalId => params[:external_id], :customer => { :first_name => params[:first_name], :foreign_nr => params[:external_id], :last_name => params[:last_name], :ndc => params[:ndc], :state => "ACTIVE", :type => "PRIVATE" }, :addresses => { :address => { :city => params[:city], :country => 'DE', :house_number => params[:house_number].to_s[0..3], :house_number_addon => params[:house_number].to_s[4..9], :street=> params[:street], :type=> "PRIMARY", :zip_code=> params[:zip_code] } } }) response.body[:create_customer_response][:customer] rescue Savon::SOAPFault => e $soap_log.error("soap error in create_customer(#{params}) #{e.to_hash[:fault][:faultcode]}: #{e.to_hash[:fault][:faultstring]}") raise end |
.delete_customer(id) ⇒ Object
deletes the customer on the remote system using your (read: “foreignNr”) id note this will only succeed if no remnants are left there (e.g. assigned phone numbers). find and remove these first
27 28 29 30 31 32 33 |
# File 'lib/iccs-soap/customer_service.rb', line 27 def delete_customer(id) response = @@client.call(:delete_customer, :message => {:foreignNr => id}) response.body[:delete_customer_response][:customer] rescue Savon::SOAPFault => e $soap_log.error("soap error in delete_customer(#{id}) #{e.to_hash[:fault][:faultcode]}: #{e.to_hash[:fault][:faultstring]}") raise end |
.external_id(id, hostname, app_id) ⇒ Object
10 11 12 |
# File 'lib/iccs-soap/customer_service.rb', line 10 def external_id(id, hostname, app_id) app_id == "Talkyoo_dev" || app_id == "Talkyoo_pre" ? "#{id}-#{app_id}-#{hostname[0..5]}" : id end |
.get_customer(id) ⇒ Object
finds the customer on the remote system using your (read: “foreignNr”) id
15 16 17 18 19 20 21 22 |
# File 'lib/iccs-soap/customer_service.rb', line 15 def get_customer(id) response = @@client.call(:get_customer, :message => {:customerNr => id}) response.body[:get_customer_response] rescue Savon::SOAPFault => e return nil if e.to_hash[:fault][:faultstring].match(/Kunde nicht gefunden/) $soap_log.error("soap error in get_customer(#{id}) #{e.to_hash[:fault][:faultcode]}: #{e.to_hash[:fault][:faultstring]}") raise end |
.update_customer(*params) ⇒ Object
updates an existing customer on the remote system
:id (mandatory, our id to find the customer)
:first_name
:last_name
:external_id (we can change our customer_id)
:ndc (National Destination Code which is usually the area code without the leading zero)
:street
:house_number
:zip_code
:city
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/iccs-soap/customer_service.rb', line 85 def update_customer(*params) params = params[0].inject({}) { |start, accu| start.merge({accu[0].to_sym => accu[1]})} response = @@client.call(:update_customer, :message => { :foreignNr => params[:external_id], :customer => { :first_name => params[:first_name], :external_id => params[:external_id], :last_name => params[:last_name], :ndc => params[:ndc], :state => "ACTIVE", :type => "PRIVATE" }, :addresses => { :address => { :city => params[:city], :country => 'DE', :house_number => params[:house_number], :street=> params[:street], :type=> "PRIMARY", :zip_code=> params[:zip_code] } } }) if response.body[:update_customer_response][:customer].present? return response.body[:update_customer_response][:customer] else return false end rescue Savon::SOAPFault => e $soap_log.error("soap error in create_customer(#{params}) #{e.to_hash[:fault][:faultcode]}: #{e.to_hash[:fault][:faultstring]}") false end |