connect-stoopid 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/connect-stoopid.rb +7 -0
- data/lib/connect-stoopid/reporting-client.rb +201 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
M2Q3NzU4MDVlMWY2ZjQ5MjU2ZjIwNjAzMzVlNDVhMjYwOTY4YzU0NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjAyMjIyMTRlOWIzZmMxNDE4MjIzNTQxNmUzOGEwZDAwM2VmMGY2MA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDU1NzcwYjM4NTU3ZTExMjU5NDI4OWIxZTk1YmU4ODUxYTRmMmNkYzc0NDEx
|
10
|
+
OTBmMjBiMDhkNDZhZjkwMzY5MWZmYWY0ZWU4ZDQwNDg4ZjQ2Nzg3MjBhM2Vj
|
11
|
+
YjY0YzgwOGRjZDQ3ZWI2NGZkY2RmODA2OWRiODI0YWE5NjdiYzA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzdmMWY3YzYyNTNkOGYwZGNjYTMxNjJkMjNkY2YwNWFjNWRiZWRmNGY3ZDdh
|
14
|
+
YzFmZTYxMmQ5MzA3YjhhYWU4NWMyMDhlMDBlN2ZiMThmOTMyYjMwYTliZTgy
|
15
|
+
ZDhkYTJiZThjN2NiNzhhMTEzMWVlYTBlYmYyZjZmZjRhMDM5NzQ=
|
@@ -0,0 +1,201 @@
|
|
1
|
+
=begin
|
2
|
+
ConnectStoopid::ReportingClient
|
3
|
+
Provides an interface to the ConnectWise Reporting API
|
4
|
+
=end
|
5
|
+
|
6
|
+
module ConnectStoopid
|
7
|
+
class ReportingClient
|
8
|
+
|
9
|
+
##
|
10
|
+
# Parameters:
|
11
|
+
# psa_address -- The hostname of your ConnectWise PSA, ie. con.companyconnect.net
|
12
|
+
# company -- Company id used when logging into ConnectWise
|
13
|
+
# username -- ConnectWise Integration username
|
14
|
+
# password -- ConnectWise Integration password
|
15
|
+
# options -- Override the default ReportingClient options
|
16
|
+
##
|
17
|
+
def initialize(psa_address, company, username, password, options = {})
|
18
|
+
@wsdl = "https://#{psa_address}/v4_6_release/apis/1.5/ReportingApi.asmx?wsdl"
|
19
|
+
@company = company
|
20
|
+
@username = username
|
21
|
+
@password = password
|
22
|
+
|
23
|
+
@client_options = {
|
24
|
+
:client_logging => true,
|
25
|
+
:client_logging_level => :error,
|
26
|
+
:soap_version => 2,
|
27
|
+
:soap_logging => false,
|
28
|
+
:soap_logging_level => :fatal
|
29
|
+
}
|
30
|
+
@client_options.merge!(options)
|
31
|
+
|
32
|
+
@soap_client = Savon.client({
|
33
|
+
:wsdl => @wsdl,
|
34
|
+
:soap_version => @client_options[:soap_version],
|
35
|
+
:log => @client_options[:soap_logging],
|
36
|
+
:log_level => @client_options[:soap_logging_level]
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Parameters:
|
42
|
+
# options: Key value pairs to add to the Savon SOAP request
|
43
|
+
# For this request, options must include "includeFields" => "true" (or "false")
|
44
|
+
# Defaults to "includeFields" => "false"
|
45
|
+
# Returns:
|
46
|
+
# If the "includeFields" option is set to "false", returns an array of strings containing all report names in alphabetical order
|
47
|
+
# If set to "true", returns an array of hashes of format {:report_name => "Activity", :fields => ["field1", "field2", ...]}
|
48
|
+
##
|
49
|
+
def get_all_report_types(options = {"includeFields" => "false"})
|
50
|
+
log_client_message("Getting list of report types", :debug)
|
51
|
+
|
52
|
+
request_options = base_soap_hash
|
53
|
+
request_options.merge!(options)
|
54
|
+
|
55
|
+
begin
|
56
|
+
response = @soap_client.call(:get_reports, :message => request_options)
|
57
|
+
rescue Savon::SOAPFault => error
|
58
|
+
log_client_message("SOAP Fault\nError Message:\n#{error}", :error)
|
59
|
+
else
|
60
|
+
if response.success?
|
61
|
+
report_types = []
|
62
|
+
xml_doc = REXML::Document.new(response.to_xml)
|
63
|
+
if options["includeFields"] == "false"
|
64
|
+
REXML::XPath.each(xml_doc, "//Report") do |report|
|
65
|
+
report_types << report.attributes["Name"].to_s
|
66
|
+
end
|
67
|
+
return report_types.sort
|
68
|
+
elsif options["includeFields"] == "true"
|
69
|
+
REXML::XPath.each(xml_doc, "//Report") do |report|
|
70
|
+
report_fields = []
|
71
|
+
REXML::XPath.each(report, "Field") do |field|
|
72
|
+
report_fields << field.attributes["Name"].to_s
|
73
|
+
end
|
74
|
+
report_types << {:report_name => report.attributes["Name"], :fields => report_fields}
|
75
|
+
end
|
76
|
+
return report_types.sort_by! {|x| x[:report_name]}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Parameters:
|
84
|
+
# options: Key value pairs to add to the Savon SOAP request
|
85
|
+
# For this request, options must include "reportName" => "Some_Report"
|
86
|
+
# Returns:
|
87
|
+
# [String]
|
88
|
+
##
|
89
|
+
def get_all_report_fields(options = {})
|
90
|
+
log_client_message("Getting list of available fields for a given report type", :debug)
|
91
|
+
|
92
|
+
request_options = base_soap_hash
|
93
|
+
request_options.merge!(options)
|
94
|
+
|
95
|
+
begin
|
96
|
+
response = @soap_client.call(:get_report_fields, :message => request_options)
|
97
|
+
rescue Savon::SOAPFault => error
|
98
|
+
log_client_message("SOAP Fault\nError Message:\n#{error}", :error)
|
99
|
+
else
|
100
|
+
if response.success?
|
101
|
+
report_fields = []
|
102
|
+
xml_doc = REXML::Document.new(response.to_xml)
|
103
|
+
REXML::XPath.each(xml_doc, "//FieldInfo") do |field|
|
104
|
+
report_fields << field.attributes["Name"].to_s
|
105
|
+
end
|
106
|
+
return report_fields.sort
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Parameters:
|
113
|
+
# options: Key value pairs to add to the Savon SOAP request
|
114
|
+
# For this request, options must include "reportName" => "Some_Report",
|
115
|
+
# and should probably include "conditions" => "some condition set"
|
116
|
+
# Returns:
|
117
|
+
# Integer
|
118
|
+
##
|
119
|
+
def run_report_count(options = {})
|
120
|
+
log_client_message("Getting a count of records per a set of conditions", :debug)
|
121
|
+
|
122
|
+
request_options = base_soap_hash
|
123
|
+
request_options.merge!(options)
|
124
|
+
|
125
|
+
begin
|
126
|
+
response = @soap_client.call(:run_report_count, :message => request_options)
|
127
|
+
rescue Savon::SOAPFault => error
|
128
|
+
log_client_message("SOAP Fault\nError Message:\n#{error}", :error)
|
129
|
+
else
|
130
|
+
if response.success?
|
131
|
+
xml_doc = REXML::Document.new(response.to_xml)
|
132
|
+
return REXML::XPath.first(xml_doc, "//RunReportCountResult").text.to_i
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Parameters:
|
139
|
+
# options: Key value pairs to add to the Savon SOAP request
|
140
|
+
# For this request, options must include "reportName" => "Some_Report",
|
141
|
+
# and should probably (read: definitely) include "conditions" => "some condition set"
|
142
|
+
# Returns:
|
143
|
+
# [{field1 => value1, field2 => value2}]
|
144
|
+
##
|
145
|
+
def run_report_query(options = {})
|
146
|
+
log_client_message("Running full query per a set of conditions", :debug)
|
147
|
+
|
148
|
+
request_options = base_soap_hash
|
149
|
+
request_options.merge!(options)
|
150
|
+
|
151
|
+
begin
|
152
|
+
response = @soap_client.call(:run_report_query, :message => request_options)
|
153
|
+
rescue Savon::SOAPFault => error
|
154
|
+
log_client_message("SOAP Fault\nError Message:\n#{error}", :error)
|
155
|
+
else
|
156
|
+
if response.success?
|
157
|
+
xml_doc = REXML::Document.new(response.to_xml)
|
158
|
+
rows = []
|
159
|
+
REXML::XPath.each(xml_doc, "//ResultRow") do |row|
|
160
|
+
row_key_vals = {}
|
161
|
+
REXML::XPath.each(row, "Value") do |col|
|
162
|
+
row_key_vals[col.attributes["Name"].to_s] = col.text.to_s
|
163
|
+
end
|
164
|
+
rows << row_key_vals
|
165
|
+
end
|
166
|
+
return rows
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
LOG_LEVELS = {
|
173
|
+
:debug => 1,
|
174
|
+
:standard => 2,
|
175
|
+
:error => 3
|
176
|
+
}
|
177
|
+
|
178
|
+
def logging
|
179
|
+
return @client_options[:client_logging]
|
180
|
+
end
|
181
|
+
|
182
|
+
def log_client_message(message, level = :error)
|
183
|
+
if logging
|
184
|
+
if LOG_LEVELS[level] >= LOG_LEVELS[@client_options[:client_logging_level]]
|
185
|
+
puts "#{self.class.to_s.split("::").last} Logger -- #{message}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def base_soap_hash
|
191
|
+
request_options = {
|
192
|
+
"credentials" => {
|
193
|
+
"CompanyId" => @company,
|
194
|
+
"IntegratorLoginId" => @username,
|
195
|
+
"IntegratorPassword" => @password
|
196
|
+
}
|
197
|
+
}
|
198
|
+
return request_options
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: connect-stoopid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Stump
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.0
|
27
|
+
description: Simple Ruby client handling access to the ConnectWise SOAP APIs
|
28
|
+
email: websupport@bytesofknowledge.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ./lib/connect-stoopid.rb
|
34
|
+
- ./lib/connect-stoopid/reporting-client.rb
|
35
|
+
homepage: https://github.com/bytesofknowledge/connect-stoopid
|
36
|
+
licenses:
|
37
|
+
- GPL-2
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.0.6
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Run queries against the ConnectWise Reporting SOAP API
|
59
|
+
test_files: []
|