Class: JasperServer::Client
- Inherits:
-
Object
- Object
- JasperServer::Client
- Defined in:
- lib/jasper_server/client.rb
Overview
The client through which all report requests are sent to the JasperServer.
Instance Method Summary collapse
-
#initialize(url, username, password, timeout = 60) ⇒ Client
constructor
Create a new instance of the client.
-
#request_report(request) ⇒ Object
Request a report from the server based on the ReportRequest object you provide.
Constructor Details
#initialize(url, username, password, timeout = 60) ⇒ Client
Create a new instance of the client.
- url
-
The URL of the JasperServer. This should look something like: “http://<hostname>:<port>/jasperserver/services/repository”
- username
-
The username used to connect to the JasperServer.
- password
-
The password used to connect to the JasperServer.
- timeout
-
Maximum time to wait for a response from the JasperServer (default it 60 seconds).
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jasper_server/client.rb', line 15 def initialize(url, username, password, timeout = 60) unless url =~ /\/services\/repository\/?$/ # add the /services/repository suffix to the URL if the user forgot # to include it url << "/services/repository" puts "WARNING: You may have forgotten to add the '/services/repository' "+ "to your JasperServer URL. Your URL has been automatically changed to #{url.inspect}." end @jasper_url = url @jasper_username = username @jasper_password = password @timeout = timeout end |
Instance Method Details
#request_report(request) ⇒ Object
Request a report from the server based on the ReportRequest object you provide. Returns the report data.
For example if your request specifies PDF
as the output format, PDF binary data will be returned.
client = JasperServer::Client.new("http://example.com/jasperserver/services/repository",
"jasperadmin", "secret!")
request = JasperServer::Request.new("/example/my-report", "PDF", {'fruit' => 'apple'})
pdf_data = client.request_report(request)
File.open('/tmp/report.pdf', 'w') do |f|
f.puts(pdf_data)
end
For debugging purposes, try requesting output in CSV
format, since request_report will then return an easily readable String.
47 48 49 50 51 |
# File 'lib/jasper_server/client.rb', line 47 def request_report(request) soap = JasperServer::Protocols::SOAP.new soap.connect(@jasper_url, @jasper_username, @jasper_password, @timeout) soap.request_report_via_soap(request) end |