Class: ConnectStoopid::ReportingClient
- Inherits:
-
Object
- Object
- ConnectStoopid::ReportingClient
- Defined in:
- lib/connect-stoopid/reporting-client.rb
Instance Method Summary collapse
-
#get_all_report_fields(options = {}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “reportName” => “Some_Report” Returns: [String].
-
#get_all_report_types(options = {"includeFields" => "false"}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “includeFields” => “true” (or “false”) Defaults to “includeFields” => “false” Returns: If the “includeFields” option is set to “false”, returns an array of strings containing all report names in alphabetical order If set to “true”, returns an array of hashes of format => “Activity”, :fields => [“field1”, “field2”, …].
-
#initialize(psa_address, company, username, password, options = {}) ⇒ ReportingClient
constructor
Parameters: psa_address – The hostname of your ConnectWise PSA, ie.
-
#run_report_count(options = {}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “reportName” => “Some_Report”, and should probably include “conditions” => “some condition set” Returns: Integer.
-
#run_report_query(options = {}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “reportName” => “Some_Report”, and should probably (read: definitely) include “conditions” => “some condition set” Returns: [=> value1, field2 => value2].
Constructor Details
#initialize(psa_address, company, username, password, options = {}) ⇒ ReportingClient
Parameters: psa_address – The hostname of your ConnectWise PSA, ie. con.companyconnect.net company – Company id used when logging into ConnectWise username – ConnectWise Integration username password – ConnectWise Integration password options – Override the default ReportingClient options
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/connect-stoopid/reporting-client.rb', line 17 def initialize(psa_address, company, username, password, = {}) @wsdl = "https://#{psa_address}/v4_6_release/apis/1.5/ReportingApi.asmx?wsdl" @company = company @username = username @password = password @client_options = { :client_logging => true, :client_logging_level => :error, :soap_version => 2, :soap_logging => false, :soap_logging_level => :fatal } @client_options.merge!() @soap_client = Savon.client({ :wsdl => @wsdl, :soap_version => @client_options[:soap_version], :log => @client_options[:soap_logging], :log_level => @client_options[:soap_logging_level] }) end |
Instance Method Details
#get_all_report_fields(options = {}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “reportName” => “Some_Report” Returns: [String]
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/connect-stoopid/reporting-client.rb', line 89 def get_all_report_fields( = {}) ("Getting list of available fields for a given report type", :debug) = base_soap_hash .merge!() begin response = @soap_client.call(:get_report_fields, :message => ) rescue Savon::SOAPFault => error ("SOAP Fault\nError Message:\n#{error}", :error) else if response.success? report_fields = [] xml_doc = REXML::Document.new(response.to_xml) REXML::XPath.each(xml_doc, "//FieldInfo") do |field| report_fields << field.attributes["Name"].to_s end return report_fields.sort end end end |
#get_all_report_types(options = {"includeFields" => "false"}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “includeFields” => “true” (or “false”) Defaults to “includeFields” => “false” Returns: If the “includeFields” option is set to “false”, returns an array of strings containing all report names in alphabetical order If set to “true”, returns an array of hashes of format => “Activity”, :fields => [“field1”, “field2”, …]
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/connect-stoopid/reporting-client.rb', line 49 def get_all_report_types( = {"includeFields" => "false"}) ("Getting list of report types", :debug) = base_soap_hash .merge!() begin response = @soap_client.call(:get_reports, :message => ) rescue Savon::SOAPFault => error ("SOAP Fault\nError Message:\n#{error}", :error) else if response.success? report_types = [] xml_doc = REXML::Document.new(response.to_xml) if ["includeFields"] == "false" REXML::XPath.each(xml_doc, "//Report") do |report| report_types << report.attributes["Name"].to_s end return report_types.sort elsif ["includeFields"] == "true" REXML::XPath.each(xml_doc, "//Report") do |report| report_fields = [] REXML::XPath.each(report, "Field") do |field| report_fields << field.attributes["Name"].to_s end report_types << {:report_name => report.attributes["Name"], :fields => report_fields} end return report_types.sort_by! {|x| x[:report_name]} end end end end |
#run_report_count(options = {}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “reportName” => “Some_Report”, and should probably include “conditions” => “some condition set” Returns: Integer
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/connect-stoopid/reporting-client.rb', line 119 def run_report_count( = {}) ("Getting a count of records per a set of conditions", :debug) = base_soap_hash .merge!() begin response = @soap_client.call(:run_report_count, :message => ) rescue Savon::SOAPFault => error ("SOAP Fault\nError Message:\n#{error}", :error) else if response.success? xml_doc = REXML::Document.new(response.to_xml) return REXML::XPath.first(xml_doc, "//RunReportCountResult").text.to_i end end end |
#run_report_query(options = {}) ⇒ Object
Parameters: options: Key value pairs to add to the Savon SOAP request For this request, options must include “reportName” => “Some_Report”, and should probably (read: definitely) include “conditions” => “some condition set” Returns: [=> value1, field2 => value2]
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/connect-stoopid/reporting-client.rb', line 145 def run_report_query( = {}) ("Running full query per a set of conditions", :debug) = base_soap_hash .merge!() begin response = @soap_client.call(:run_report_query, :message => ) rescue Savon::SOAPFault => error ("SOAP Fault\nError Message:\n#{error}", :error) else if response.success? xml_doc = REXML::Document.new(response.to_xml) rows = [] REXML::XPath.each(xml_doc, "//ResultRow") do |row| row_key_vals = {} REXML::XPath.each(row, "Value") do |col| row_key_vals[col.attributes["Name"].to_s] = col.text.to_s end rows << row_key_vals end return rows end end end |