Module: ConnectWiseWebReports

Defined in:
lib/connect_wise_web_reports.rb,
lib/connect_wise_web_reports/error.rb,
lib/connect_wise_web_reports/report.rb,
lib/connect_wise_web_reports/version.rb,
lib/connect_wise_web_reports/configuration.rb

Defined Under Namespace

Classes: Configuration, ConnectionError, Report

Constant Summary collapse

DEFAULT_OPTIONS =
{
  conditions: nil,
  fields: [],
  limit: 100,
  order_by: nil,
  skip: nil,
  timeout: 5,

  # authentication
  host: ConnectWiseWebReports.configuration.host,
  company_id: ConnectWiseWebReports.configuration.company_id,
  integrator_id: ConnectWiseWebReports.configuration.integrator_id,
  integrator_password: ConnectWiseWebReports.configuration.integrator_password,
  version: ConnectWiseWebReports.configuration.version,
  proxy_host: ConnectWiseWebReports.configuration.proxy_host,
  proxy_port: ConnectWiseWebReports.configuration.proxy_port,
  proxy_user: ConnectWiseWebReports.configuration.proxy_user,
  proxy_pass: ConnectWiseWebReports.configuration.proxy_pass
}.freeze
VERSION =
'1.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



4
5
6
# File 'lib/connect_wise_web_reports/configuration.rb', line 4

def configuration
  @configuration
end

.loggerObject



32
33
34
35
36
# File 'lib/connect_wise_web_reports/configuration.rb', line 32

def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = self.name
  end
end

Class Method Details

.agent(options) ⇒ Mechanize

Create a new Mechanize agent.

Returns:

  • (Mechanize)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/connect_wise_web_reports.rb', line 33

def self.agent(options)
  Mechanize.new do |agent|
    if options[:proxy_host]
      agent.set_proxy(options[:proxy_host], options[:proxy_port],
                      options[:proxy_user], options[:proxy_pass])
    end

    agent.read_timeout = options[:timeout]
    agent.keep_alive = false
    agent.idle_timeout = 5
  end
end

.configure {|configuration| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/connect_wise_web_reports/configuration.rb', line 11

def self.configure
  yield(configuration)
end

.info(options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/connect_wise_web_reports.rb', line 46

def self.info(options)
  options = DEFAULT_OPTIONS.merge(options)
  url = "https://#{options[:host]}/login/companyinfo/#{options[:company_id]}"
  response = agent(options).get(url)

  return {} if response.content == 'null'

  JSON.parse(response.content)
rescue StandardError => e
  raise ConnectionError.new(e.message)
end