Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Add error handling #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 62 additions & 17 deletions lib/n_able_rails.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "n_able_rails/version"
require 'n_able_rails/version'
require 'savon'

module NAbleRails
Expand All @@ -11,6 +11,12 @@ def self.initialize(sas_url, username, password)

# create a client for the service
@client = Savon.client(wsdl: "#{sas_url}/dms/services/ServerEI?wsdl")
# test connection to the api
version_info
rescue HTTPI::SSLError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
Net::ProtocolError, Errno::ECONNREFUSED => error
return error
end

# List all available operations for the api.
Expand All @@ -24,39 +30,78 @@ def self.version_info
end

def self.list_devices(customer_id)
@client.call(:device_list, message: { Username: @username, Password: @password, Settings:
{ "@xsi:type" => "impl:ArrayOf_tns1_T_KeyPair", "@env:arrayType" => "impl:T_KeyPair[]",
Setting:{key: "customerID", value: customer_id} }
@client.call(:device_list, message: { Username: @username,
Password: @password,
Settings:
{ '@xsi:type' => 'impl:ArrayOf_tns1_T_KeyPair',
'@env:arrayType' => 'impl:T_KeyPair[]',
Setting: { key: 'customerID',
value: customer_id } }
})
rescue Savon::SOAPFault => error
return 'Invalid username-password combination.' if error.to_hash[:fault][:detail].nil?
return "Customer with id #{customer_id} could not be found."
end

def self.get_device_info(device_id)
@client.call(:device_get, message: { Username: @username, Password: @password, Settings:
{ Setting:{key: "deviceID", value: device_id} }
} )
@client.call(:device_get, message: { Username: @username,
Password: @password,
Settings: { Setting: { key: 'deviceID',
value: device_id } }
})
rescue Savon::SOAPFault => error
return "Device with id #{device_id} could not be found." if error.to_hash[:fault][:faultstring] == '5000 Query failed.'
return 'Invalid username-password combination.'
end

def self.list_device_property(device_id)
@client.call(:device_property_list, message: { Username: @username, Password: @password, DeviceIDs: { DeviceID: device_id}, DeviceNames:{}, FilterIDs:{}, FilterNames:{}, ReverseOrder: false })
@client.call(:device_property_list, message: { Username: @username,
Password: @password,
DeviceIDs: { DeviceID: device_id },
DeviceNames: {},
FilterIDs: {},
FilterNames: {},
ReverseOrder: false })
rescue Savon::SOAPFault => error
return "Device with id #{device_id} could not be found." if error.to_hash[:fault][:faultstring] == '5000 Query failed.'
return 'Invalid username-password combination.'
end

def self.list_customers
@client.call(:customer_list, message: { Username: @username, Password: @password, Settings: { } })
@client.call(:customer_list, message: { Username: @username,
Password: @password,
Settings: {} })
rescue Savon::SOAPFault => error
return "Device with id #{device_id} could not be found." if error.to_hash[:fault][:faultstring] == '5000 Query failed.'
return 'Invalid username-password combination.'
end

def self.device_asset_info_export2ById(device_id)
@client.call(:device_asset_info_export2, message: { Version: "0.0", Username: @username, Password: @password, Settings:
{ Setting:{Key: 'TargetByDeviceID', Value: {Value: device_id} } }
} )
@client.call(:device_asset_info_export2, message: { Version: '0.0',
Username: @username,
Password: @password,
Settings: { Setting: { Key: 'TargetByDeviceID',
Value: { Value: device_id } } }
})
rescue Savon::SOAPFault
return 'Invalid username-password combination.'
end

def self.device_asset_info_export2()
@client.call(:device_asset_info_export2, message: { Version: "0.0", Username: @username, Password: @password })
def self.device_asset_info_export2
@client.call(:device_asset_info_export2, message: { Version: '0.0',
Username: @username,
Password: @password })
rescue Savon::SOAPFault
return 'Invalid username-password combination.'
end

def self.device_status(device_id)
@client.call(:device_get_status, message: { Username: @username, Password: @password, Settings:
{ Setting:{key: "deviceID", value: device_id} }
} )
@client.call(:device_get_status, message: { Username: @username,
Password: @password,
Settings: { Setting: { key: 'deviceID',
value: device_id } }
})
rescue Savon::SOAPFault
return 'Invalid username-password combination.'
end
end
2 changes: 1 addition & 1 deletion lib/n_able_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NAbleRails
VERSION = "0.1.0"
VERSION = '0.1.1'.freeze
end
22 changes: 12 additions & 10 deletions n_able_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'n_able_rails/version'

Gem::Specification.new do |spec|
spec.name = "n_able_rails"
spec.name = 'n_able_rails'
spec.version = NAbleRails::VERSION
spec.authors = ["Alex Myers"]
spec.email = ["[email protected]"]
spec.description = "An Api wrapper for N-Able from SolarWinds"
spec.authors = ['Alex Myers']
spec.email = ['[email protected]']
spec.description = 'An Api wrapper for N-Able from SolarWinds'

spec.summary = %q{Ruby Wrapper for N-Able API}
spec.homepage = "https://github.com/enspiresoftware/n_able_rails"
spec.license = "MIT"
spec.homepage = 'https://github.com/enspiresoftware/n_able_rails'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_development_dependency "bundler", '~> 0'
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency 'bundler', '~> 0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'minitest-rails'
spec.add_development_dependency 'minitest-emoji'

spec.add_runtime_dependency 'savon', '~> 2.3'
spec.add_runtime_dependency 'wasabi', '~> 3.2'
Expand Down