connect_wise_web_reports 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/connect_wise_web_reports.gemspec +28 -0
- data/lib/connect_wise_web_reports/configuration.rb +29 -0
- data/lib/connect_wise_web_reports/report.rb +111 -0
- data/lib/connect_wise_web_reports/version.rb +3 -0
- data/lib/connect_wise_web_reports.rb +57 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3383a03f7bf2501883d705393e127fd7cf59f913
|
4
|
+
data.tar.gz: dd234173f71a7e460c381dd0c3929e290bdfb88d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43a75144611fb67d4dd06fccc829e3fa4bd3211cbd970d409b659340dba85afb69a3cf99a26d92de31094e97e2fe072928953fddbdd8a16d1c4ad9e47eec0b81
|
7
|
+
data.tar.gz: dbb9048e169ef304bc468a1262ed8c7ecdc48dc08f52b8907d349d2454b05a6c3662db7b9c7a9bfe65547008a56fe5299b76538aedbb2af2218730f60767078d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# ConnectWiseWebReports
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/connect_wise_web_reports`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'connect_wise_web_reports'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install connect_wise_web_reports
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/connect_wise_web_reports. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
# connect_wise_web_reports
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "connect_wise_web_reports"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'connect_wise_web_reports/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'connect_wise_web_reports'
|
8
|
+
spec.version = ConnectWiseWebReports::VERSION
|
9
|
+
spec.authors = ['Kevin Pheasey']
|
10
|
+
spec.email = ['kevin@kpheasey.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Connect Wise Web Reports API Wrapper}
|
13
|
+
spec.description = %q{Full support Connect Wise Web Reports API, including custom queries, pagination, api info, and more. }
|
14
|
+
spec.homepage = 'https://github.com/kpheasey/connect_wise_web_reports'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'mechanize', '~> 2.7', '>= 2.7.0'
|
26
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.0'
|
27
|
+
spec.add_dependency 'plissken', '~> 0.2.0'
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ConnectWiseWebReports
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :host, :company_id, :integrator_id, :integrator_password, :version,
|
17
|
+
:proxy_host, :proxy_port, :proxy_user, :proxy_pass
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@version = 'v4_6_release'
|
21
|
+
end
|
22
|
+
|
23
|
+
def set(options = {})
|
24
|
+
options.each { |k, v| self.send("#{k.to_s}=", v) }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module ConnectWiseWebReports
|
2
|
+
|
3
|
+
class Report
|
4
|
+
|
5
|
+
attr_accessor :options, :name, :records
|
6
|
+
|
7
|
+
def initialize(name, options = {})
|
8
|
+
@name = name
|
9
|
+
@options = ConnectWiseWebReports::DEFAULT_OPTIONS.merge(options)
|
10
|
+
@records = fetch
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Array(Hash)]
|
14
|
+
def fetch
|
15
|
+
response = ConnectWiseWebReports.agent(options).get(url)
|
16
|
+
doc = Nokogiri::XML(response.content)
|
17
|
+
|
18
|
+
# raise errors if we got them
|
19
|
+
unless doc.xpath('//error/message').empty?
|
20
|
+
raise doc.xpath('//error/message').first.children.first.text
|
21
|
+
end
|
22
|
+
|
23
|
+
self.parse_records doc.xpath('//results/row')
|
24
|
+
|
25
|
+
return self.records
|
26
|
+
end
|
27
|
+
|
28
|
+
# Generate the Web Report request url.
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
def url
|
32
|
+
url = "https://#{self.options[:host]}/#{self.options[:version]}/webreport/"
|
33
|
+
|
34
|
+
# Report
|
35
|
+
url += "?r=#{self.name}"
|
36
|
+
|
37
|
+
# API credentials
|
38
|
+
url += "&c=#{self.options[:company_id].to_s}"
|
39
|
+
url += "&u=#{self.options[:integrator_id].to_s}"
|
40
|
+
url += "&p=#{self.options[:integrator_password].to_s}"
|
41
|
+
|
42
|
+
#order
|
43
|
+
url += "&o=#{self.options[:order_by].to_s}" unless self.options[:order_by].nil?
|
44
|
+
|
45
|
+
# pagination
|
46
|
+
url += "&l=#{self.options[:limit].to_s}" unless self.options[:limit].nil?
|
47
|
+
url += "&s=#{self.options[:skip].to_s}" unless self.options[:skip].nil?
|
48
|
+
|
49
|
+
# timeout
|
50
|
+
url += "&t=#{self.options[:timeout].to_s}" unless self.options[:timeout].nil?
|
51
|
+
|
52
|
+
# fields
|
53
|
+
url += "&f=#{self.options[:fields].join('&f=')}" unless self.options[:fields].nil? || self.options[:fields].empty?
|
54
|
+
|
55
|
+
# conditions
|
56
|
+
url += "&q=#{self.options[:conditions]}" unless self.options[:conditions].blank?
|
57
|
+
|
58
|
+
return URI.escape(url)
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_records(rows)
|
62
|
+
self.records = []
|
63
|
+
|
64
|
+
rows.each do |row|
|
65
|
+
record = Hash.from_xml(row.to_s)['row'].to_snake_keys.with_indifferent_access
|
66
|
+
record.delete 'result_number'
|
67
|
+
self.records << record
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
### Pagination ###
|
73
|
+
|
74
|
+
def page
|
75
|
+
if self.options[:limit].nil?
|
76
|
+
return 1
|
77
|
+
else
|
78
|
+
self.options[:skip] = 0 if self.options[:skip].nil?
|
79
|
+
return (self.options[:skip] / self.options[:limit]) + 1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def next_page?
|
84
|
+
if self.options[:limit].nil? || self.options[:limit].zero? || self.records.count < self.options[:limit]
|
85
|
+
return false
|
86
|
+
else
|
87
|
+
return true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def next_page
|
92
|
+
self.options[:skip] = 0 if self.options[:skip].nil?
|
93
|
+
self.options[:skip] += self.options[:limit]
|
94
|
+
|
95
|
+
return self.fetch
|
96
|
+
end
|
97
|
+
|
98
|
+
def previous_page?
|
99
|
+
self.page > 1
|
100
|
+
end
|
101
|
+
|
102
|
+
def previous_page
|
103
|
+
self.options[:skip] -= self.options[:limit]
|
104
|
+
self.options[:skip] = [0, self.options[:skip]].max # ensure we don't skip negative
|
105
|
+
|
106
|
+
return self.fetch
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'plissken'
|
4
|
+
|
5
|
+
require 'connect_wise_web_reports/version'
|
6
|
+
require 'connect_wise_web_reports/configuration'
|
7
|
+
require 'connect_wise_web_reports/report'
|
8
|
+
|
9
|
+
module ConnectWiseWebReports
|
10
|
+
|
11
|
+
DEFAULT_OPTIONS = {
|
12
|
+
conditions: nil,
|
13
|
+
fields: [],
|
14
|
+
limit: 100,
|
15
|
+
order_by: nil,
|
16
|
+
skip: nil,
|
17
|
+
timeout: 5,
|
18
|
+
|
19
|
+
# authentication
|
20
|
+
host: ConnectWiseWebReports.configuration.host,
|
21
|
+
company_id: ConnectWiseWebReports.configuration.company_id,
|
22
|
+
integrator_id: ConnectWiseWebReports.configuration.integrator_id,
|
23
|
+
integrator_password: ConnectWiseWebReports.configuration.integrator_password,
|
24
|
+
version: ConnectWiseWebReports.configuration.version,
|
25
|
+
proxy_host: ConnectWiseWebReports.configuration.proxy_host,
|
26
|
+
proxy_port: ConnectWiseWebReports.configuration.proxy_port,
|
27
|
+
proxy_user: ConnectWiseWebReports.configuration.proxy_user,
|
28
|
+
proxy_pass: ConnectWiseWebReports.configuration.proxy_pass
|
29
|
+
}
|
30
|
+
|
31
|
+
# Create a new Mechanize agent.
|
32
|
+
#
|
33
|
+
# @return [Mechanize]
|
34
|
+
def self.agent(options)
|
35
|
+
Mechanize.new do |agent|
|
36
|
+
agent.set_proxy(
|
37
|
+
options[:proxy_host],
|
38
|
+
options[:proxy_port],
|
39
|
+
options[:proxy_user],
|
40
|
+
options[:proxy_pass]
|
41
|
+
) unless options[:proxy_host].nil?
|
42
|
+
|
43
|
+
agent.read_timeout = options[:timeout]
|
44
|
+
agent.keep_alive = false
|
45
|
+
agent.idle_timeout = 5
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.info(options)
|
50
|
+
options = DEFAULT_OPTIONS.merge(options)
|
51
|
+
url = "https://#{options[:host]}/login/companyinfo/#{options[:company_id]}"
|
52
|
+
response = agent(options).get(url)
|
53
|
+
|
54
|
+
return JSON.parse(response.content)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: connect_wise_web_reports
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Pheasey
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mechanize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.7.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.7'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.7.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: nokogiri
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.6'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.6.0
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.6'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.6.0
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: plissken
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.2.0
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.2.0
|
95
|
+
description: 'Full support Connect Wise Web Reports API, including custom queries,
|
96
|
+
pagination, api info, and more. '
|
97
|
+
email:
|
98
|
+
- kevin@kpheasey.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- ".gitignore"
|
104
|
+
- ".travis.yml"
|
105
|
+
- CODE_OF_CONDUCT.md
|
106
|
+
- Gemfile
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- bin/console
|
110
|
+
- bin/setup
|
111
|
+
- connect_wise_web_reports.gemspec
|
112
|
+
- lib/connect_wise_web_reports.rb
|
113
|
+
- lib/connect_wise_web_reports/configuration.rb
|
114
|
+
- lib/connect_wise_web_reports/report.rb
|
115
|
+
- lib/connect_wise_web_reports/version.rb
|
116
|
+
homepage: https://github.com/kpheasey/connect_wise_web_reports
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.5.0
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Connect Wise Web Reports API Wrapper
|
140
|
+
test_files: []
|