casper-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +0 -0
- data/Gemfile +9 -0
- data/README +0 -0
- data/Rakefile +9 -0
- data/casper-client.gemspec +19 -0
- data/lib/casper_client.rb +22 -0
- data/spec/casper_client_spec.rb +46 -0
- data/spec/data/dataset.xml +1157 -0
- data/spec/data/report.jrxml +61 -0
- data/spec/rspec_opts +3 -0
- data/spec/spec_helper.rb +1 -0
- metadata +68 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
File without changes
|
data/Gemfile
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "casper-client"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Daniel Tamiosso"]
|
9
|
+
s.email = ["email@danieltamiosso.com"]
|
10
|
+
s.homepage = "https://github.com/danieltamiosso/casper-client"
|
11
|
+
s.summary = %q{just a simple api for casper service}
|
12
|
+
s.description = %q{just a simple api for casper service (a web server framework for JasperReports)}
|
13
|
+
|
14
|
+
s.rubyforge_project = "casper-client"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
module Casper
|
4
|
+
|
5
|
+
class Client
|
6
|
+
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
def self.build(options={}, &block)
|
10
|
+
options = {:host => 'http://casper.jrs-labs.com:8080'}.merge!(options)
|
11
|
+
report = Report.new
|
12
|
+
report.instance_eval(&block)
|
13
|
+
RestClient.post options[:host], {'casper[jrxml]' => report.template, 'casper[data]' => report.xml, 'casper[xpath]' => report.xpath}
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class Report
|
19
|
+
attr_accessor :xml, :template, :xpath
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe Casper::Client do
|
4
|
+
|
5
|
+
TEMPLATE = open(File.join(File.dirname(__FILE__), 'data', 'report.jrxml'))
|
6
|
+
DATASET = open(File.join(File.dirname(__FILE__), 'data','dataset.xml'))
|
7
|
+
|
8
|
+
describe 'a basic flow of generation of a report' do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
RestClient.stub!(:post).and_return('report')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should build the correct request to a report with a xml datasource' do
|
15
|
+
RestClient.should_receive(:post).with(
|
16
|
+
'http://casper.jrs-labs.com:8080',
|
17
|
+
{'casper[jrxml]'=> TEMPLATE,
|
18
|
+
'casper[data]'=> DATASET,
|
19
|
+
'casper[xpath]'=>'//root'
|
20
|
+
}
|
21
|
+
)
|
22
|
+
@report = Casper::Client.build do |report|
|
23
|
+
report.xml = DATASET
|
24
|
+
report.template = TEMPLATE
|
25
|
+
report.xpath = '//root'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should build the correct request to a report with a xml datasource with a optional host' do
|
30
|
+
RestClient.should_receive(:post).with(
|
31
|
+
'http://mycasperserver.com',
|
32
|
+
{'casper[jrxml]'=> TEMPLATE,
|
33
|
+
'casper[data]'=> DATASET,
|
34
|
+
'casper[xpath]'=> '//root'
|
35
|
+
}
|
36
|
+
)
|
37
|
+
@report = Casper::Client.build :host => 'http://mycasperserver.com' do |report|
|
38
|
+
report.xml = DATASET
|
39
|
+
report.template = TEMPLATE
|
40
|
+
report.xpath = '//root'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|