casper-client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "casper-client"
6
- s.version = "0.0.3"
6
+ s.version = "0.0.4"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Daniel Tamiosso"]
9
9
  s.email = ["email@danieltamiosso.com"]
data/lib/casper-client.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'rest_client'
2
+ require 'json'
3
+ require 'base64'
2
4
 
3
5
  module Casper
4
6
 
@@ -10,13 +12,24 @@ module Casper
10
12
  options = {:host => 'http://casper.jrs-labs.com:8080'}.merge!(options)
11
13
  report = Report.new
12
14
  report.instance_eval(&block)
13
- RestClient.post options[:host], {'casper[jrxml]' => report.template, 'casper[data]' => report.xml, 'casper[xpath]' => report.xpath}
15
+ RestClient.post options[:host], report.to_json, :content_type => :json, :accept => :json
14
16
  end
15
17
 
16
18
  end
17
19
 
18
20
  class Report
19
21
  attr_accessor :xml, :template, :xpath
22
+
23
+ def to_json
24
+ {:casper =>
25
+ {
26
+ :jrxml => Base64.encode64(self.template.read),
27
+ :data => Base64.encode64((self.xml.kind_of? File) ? self.xml.read : xml),
28
+ :xpath => self.xpath
29
+ }
30
+ }.to_json
31
+ end
32
+
20
33
  end
21
34
 
22
35
  end
@@ -1,42 +1,64 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
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
-
4
+
8
5
  describe 'a basic flow of generation of a report' do
9
6
 
10
7
  before(:each) do
11
8
  RestClient.stub!(:post).and_return('report')
12
9
  end
13
10
 
14
- it 'should build the correct request to a report with a xml datasource' do
11
+ it 'should build the correct request to a report with a xml file as datasource' do
15
12
  RestClient.should_receive(:post).with(
16
13
  'http://casper.jrs-labs.com:8080',
17
- {'casper[jrxml]'=> TEMPLATE,
18
- 'casper[data]'=> DATASET,
19
- 'casper[xpath]'=>'//root'
20
- }
14
+ {:casper =>
15
+ {
16
+ :jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
17
+ :data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
18
+ :xpath => '//root'
19
+ }
20
+ }.to_json, :content_type => :json, :accept => :json
21
21
  )
22
22
  report = Casper::Client.build do |report|
23
- report.xml = DATASET
24
- report.template = TEMPLATE
23
+ report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
24
+ report.xml = open(File.join(File.dirname(__FILE__),'data/dataset.xml'))
25
+ report.xpath = '//root'
26
+ end
27
+ end
28
+
29
+ it 'should build the correct request to a report with a xml file as datasource with a optional host' do
30
+ RestClient.should_receive(:post).with(
31
+ 'http://myserver',
32
+ {:casper =>
33
+ {
34
+ :jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
35
+ :data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
36
+ :xpath => '//root'
37
+ }
38
+ }.to_json, :content_type => :json, :accept => :json
39
+ )
40
+ report = Casper::Client.build :host => 'http://myserver' do |report|
41
+ report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
42
+ report.xml = open(File.join(File.dirname(__FILE__),'data/dataset.xml'))
25
43
  report.xpath = '//root'
26
44
  end
27
45
  end
28
46
 
29
- it 'should build the correct request to a report with a xml datasource with a optional host' do
47
+
48
+ it 'should build the correct request to a report with a xml string as datasource' do
30
49
  RestClient.should_receive(:post).with(
31
50
  'http://mycasperserver.com',
32
- {'casper[jrxml]'=> TEMPLATE,
33
- 'casper[data]'=> DATASET,
34
- 'casper[xpath]'=> '//root'
35
- }
51
+ {:casper =>
52
+ {
53
+ :jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
54
+ :data => Base64.encode64('<model/>'),
55
+ :xpath => '//root'
56
+ }
57
+ }.to_json, :content_type => :json, :accept => :json
36
58
  )
37
59
  report = Casper::Client.build :host => 'http://mycasperserver.com' do |report|
38
- report.xml = DATASET
39
- report.template = TEMPLATE
60
+ report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
61
+ report.xml = '<model/>'
40
62
  report.xpath = '//root'
41
63
  end
42
64
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), '..','lib','casper_client')
1
+ require File.join(File.dirname(__FILE__), '..','lib','casper-client')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: casper-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Tamiosso