Class: Connectwise::Connection
- Inherits:
-
Object
- Object
- Connectwise::Connection
- Defined in:
- lib/connectwise/connection.rb,
lib/connectwise/connectwise.rb
Instance Attribute Summary collapse
-
#custom_api_mapping ⇒ Object
readonly
Returns the value of attribute custom_api_mapping.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
- #call(api, action, message, options: {}, &err_handler) ⇒ Object
-
#initialize(host: '', company_name: '', integrator_login_id: '', integrator_password: '', custom_api_mapping: {}) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(host: '', company_name: '', integrator_login_id: '', integrator_password: '', custom_api_mapping: {}) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 |
# File 'lib/connectwise/connection.rb', line 6 def initialize(host: '', company_name: '', integrator_login_id: '', integrator_password: '', custom_api_mapping: {}) @custom_api_mapping = custom_api_mapping @host = host @credentials = {CompanyId: company_name, IntegratorLoginId: integrator_login_id, IntegratorPassword: integrator_password} HTTPI.adapter = :net_http end |
Instance Attribute Details
#custom_api_mapping ⇒ Object (readonly)
Returns the value of attribute custom_api_mapping.
3 4 5 |
# File 'lib/connectwise/connection.rb', line 3 def custom_api_mapping @custom_api_mapping end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/connectwise/connection.rb', line 3 def host @host end |
#log ⇒ Object
Returns the value of attribute log.
4 5 6 |
# File 'lib/connectwise/connection.rb', line 4 def log @log end |
Instance Method Details
#call(api, action, message, options: {}, &err_handler) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/connectwise/connection.rb', line 13 def call(api, action, , options: {}, &err_handler) err_handler ||= proc {|err| raise err} client = Savon.client(.merge().merge(wsdl: wsdl_url(api))) response = client.call action, message: credentials.merge() response.body["#{action}_response".to_sym]["#{action}_result".to_sym] rescue Savon::SOAPFault, Savon::UnknownOperationError, SocketError, URI::InvalidURIError => err begin case err. when /username or password is incorrect/i raise BadCredentialsError.new 'Login or Password are incorrect' when /hostname nor servname/i raise UnknownHostError.new "The host (#{@host}) is not reachable" when /cannot find company.*connectwise config/i raise UnknownCompanyError.new "The company (#{@credentials[:CompanyId]}) cannot be found by Connectwise" else raise ConnectionError.new "An unknown error occurred when contacting Connectwise : \n#{err.}" end rescue BadCredentialsError, UnknownHostError, UnknownCompanyError, ConnectionError => err err_handler.call(err) end end |