casper-client 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'rest-client'
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ end
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ end
@@ -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