casper-client 0.0.6 → 0.0.7
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.
- data/casper-client.gemspec +1 -1
- data/lib/casper-client.rb +17 -4
- data/spec/casper_client_spec.rb +48 -4
- metadata +2 -29
data/casper-client.gemspec
CHANGED
data/lib/casper-client.rb
CHANGED
@@ -7,14 +7,27 @@ module Casper
|
|
7
7
|
class Client
|
8
8
|
|
9
9
|
@@options = {
|
10
|
-
:host => 'http://casper.jrs-labs.com:8080'
|
10
|
+
:host => 'http://casper.jrs-labs.com:8080',
|
11
|
+
:type => 'pdf'
|
11
12
|
}
|
12
13
|
|
14
|
+
def self.pdf options={}
|
15
|
+
options[:type] = 'pdf'
|
16
|
+
self.report options
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.xls options={}
|
20
|
+
options[:type] = 'xls'
|
21
|
+
self.report options
|
22
|
+
end
|
23
|
+
|
13
24
|
def self.report options={}
|
25
|
+
options = @@options.merge!(options)
|
14
26
|
Client.build options do |report|
|
15
27
|
report.template = options[:template]
|
16
28
|
report.xml = options[:xml]
|
17
29
|
report.xpath = options[:xpath]
|
30
|
+
report.type = options[:type]
|
18
31
|
end
|
19
32
|
end
|
20
33
|
|
@@ -25,7 +38,6 @@ module Casper
|
|
25
38
|
private
|
26
39
|
|
27
40
|
def self.build(options={}, &block)
|
28
|
-
options = @@options.merge!(options)
|
29
41
|
report = Report.new
|
30
42
|
report.instance_eval(&block)
|
31
43
|
RestClient.post options[:host], report.to_json, :content_type => :json, :accept => :json
|
@@ -34,14 +46,15 @@ module Casper
|
|
34
46
|
end
|
35
47
|
|
36
48
|
class Report
|
37
|
-
attr_accessor :xml, :template, :xpath
|
49
|
+
attr_accessor :xml, :template, :xpath, :type
|
38
50
|
|
39
51
|
def to_json
|
40
52
|
{:casper =>
|
41
53
|
{
|
42
54
|
:jrxml => Base64.encode64(self.template.read),
|
43
55
|
:data => Base64.encode64((self.xml.kind_of? File) ? self.xml.read : xml),
|
44
|
-
:xpath => self.xpath
|
56
|
+
:xpath => self.xpath,
|
57
|
+
:type => self.type
|
45
58
|
}
|
46
59
|
}.to_json
|
47
60
|
end
|
data/spec/casper_client_spec.rb
CHANGED
@@ -15,7 +15,8 @@ describe Casper::Client do
|
|
15
15
|
{
|
16
16
|
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
17
17
|
:data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
|
18
|
-
:xpath => '//root'
|
18
|
+
:xpath => '//root',
|
19
|
+
:type => 'pdf'
|
19
20
|
}
|
20
21
|
}.to_json, :content_type => :json, :accept => :json
|
21
22
|
)
|
@@ -33,7 +34,8 @@ describe Casper::Client do
|
|
33
34
|
{
|
34
35
|
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
35
36
|
:data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
|
36
|
-
:xpath => '//root'
|
37
|
+
:xpath => '//root',
|
38
|
+
:type => 'pdf'
|
37
39
|
}
|
38
40
|
}.to_json, :content_type => :json, :accept => :json
|
39
41
|
)
|
@@ -52,7 +54,8 @@ describe Casper::Client do
|
|
52
54
|
{
|
53
55
|
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
54
56
|
:data => Base64.encode64('<model/>'),
|
55
|
-
:xpath => '//root'
|
57
|
+
:xpath => '//root',
|
58
|
+
:type => 'pdf'
|
56
59
|
}
|
57
60
|
}.to_json, :content_type => :json, :accept => :json
|
58
61
|
)
|
@@ -73,7 +76,8 @@ describe Casper::Client do
|
|
73
76
|
{
|
74
77
|
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
75
78
|
:data => Base64.encode64('<model/>'),
|
76
|
-
:xpath => '//root'
|
79
|
+
:xpath => '//root',
|
80
|
+
:type => 'pdf'
|
77
81
|
}
|
78
82
|
}.to_json, :content_type => :json, :accept => :json
|
79
83
|
)
|
@@ -85,6 +89,46 @@ describe Casper::Client do
|
|
85
89
|
)
|
86
90
|
end
|
87
91
|
|
92
|
+
it 'should be possible export as xls format' do
|
93
|
+
Casper::Client.options[:host] = 'http://host.config.com'
|
94
|
+
RestClient.should_receive(:post).with(
|
95
|
+
'http://host.config.com',
|
96
|
+
{:casper =>
|
97
|
+
{
|
98
|
+
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
99
|
+
:data => Base64.encode64('<model/>'),
|
100
|
+
:xpath => '//root',
|
101
|
+
:type => 'xls'
|
102
|
+
}
|
103
|
+
}.to_json, :content_type => :json, :accept => :json
|
104
|
+
)
|
105
|
+
report = Casper::Client.xls(
|
106
|
+
:template => open(File.join(File.dirname(__FILE__),'data/report.jrxml')),
|
107
|
+
:xml => '<model/>',
|
108
|
+
:xpath => '//root'
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should be possible export as pdf format by alias method' do
|
113
|
+
Casper::Client.options[:host] = 'http://host.config.com'
|
114
|
+
RestClient.should_receive(:post).with(
|
115
|
+
'http://host.config.com',
|
116
|
+
{:casper =>
|
117
|
+
{
|
118
|
+
:jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
|
119
|
+
:data => Base64.encode64('<model/>'),
|
120
|
+
:xpath => '//root',
|
121
|
+
:type => 'pdf'
|
122
|
+
}
|
123
|
+
}.to_json, :content_type => :json, :accept => :json
|
124
|
+
)
|
125
|
+
report = Casper::Client.pdf(
|
126
|
+
:template => open(File.join(File.dirname(__FILE__),'data/report.jrxml')),
|
127
|
+
:xml => '<model/>',
|
128
|
+
:xpath => '//root'
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
88
132
|
end
|
89
133
|
|
90
134
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: casper-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 19
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
5
|
+
version: 0.0.7
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Daniel Tamiosso
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 27
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 5
|
33
|
-
- 0
|
34
24
|
version: 2.5.0
|
35
25
|
type: :development
|
36
26
|
version_requirements: *id001
|
@@ -42,9 +32,6 @@ dependencies:
|
|
42
32
|
requirements:
|
43
33
|
- - ">="
|
44
34
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
35
|
version: "0"
|
49
36
|
type: :development
|
50
37
|
version_requirements: *id002
|
@@ -56,9 +43,6 @@ dependencies:
|
|
56
43
|
requirements:
|
57
44
|
- - ">="
|
58
45
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
|
-
segments:
|
61
|
-
- 0
|
62
46
|
version: "0"
|
63
47
|
type: :runtime
|
64
48
|
version_requirements: *id003
|
@@ -70,9 +54,6 @@ dependencies:
|
|
70
54
|
requirements:
|
71
55
|
- - ">="
|
72
56
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
|
-
segments:
|
75
|
-
- 0
|
76
57
|
version: "0"
|
77
58
|
type: :runtime
|
78
59
|
version_requirements: *id004
|
@@ -112,25 +93,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
93
|
requirements:
|
113
94
|
- - ">="
|
114
95
|
- !ruby/object:Gem::Version
|
115
|
-
hash: 3
|
116
|
-
segments:
|
117
|
-
- 0
|
118
96
|
version: "0"
|
119
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
98
|
none: false
|
121
99
|
requirements:
|
122
100
|
- - ">="
|
123
101
|
- !ruby/object:Gem::Version
|
124
|
-
hash: 23
|
125
|
-
segments:
|
126
|
-
- 1
|
127
|
-
- 3
|
128
|
-
- 6
|
129
102
|
version: 1.3.6
|
130
103
|
requirements: []
|
131
104
|
|
132
105
|
rubyforge_project: casper-client
|
133
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.5.2
|
134
107
|
signing_key:
|
135
108
|
specification_version: 3
|
136
109
|
summary: just a simple api for casper service
|