casper-client 0.0.5 → 0.0.6

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.5"
6
+ s.version = "0.0.6"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Daniel Tamiosso"]
9
9
  s.email = ["email@danieltamiosso.com"]
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.add_development_dependency "rspec", ">= 2.5.0"
16
+ s.add_development_dependency "bundler", ">= 0"
16
17
  s.add_dependency "rest-client", ">= 0"
17
- s.add_dependency "bundler", ">= 0"
18
+ s.add_dependency "json", ">= 0"
18
19
 
19
20
  s.rubyforge_project = "casper-client"
20
21
 
data/lib/casper-client.rb CHANGED
@@ -3,17 +3,12 @@ require 'json'
3
3
  require 'base64'
4
4
 
5
5
  module Casper
6
-
6
+
7
7
  class Client
8
-
9
- DEFAULT_HOST = 'http://casper.jrs-labs.com:8080'
10
-
11
- def self.build(options={}, &block)
12
- options = {:host => DEFAULT_HOST}.merge!(options)
13
- report = Report.new
14
- report.instance_eval(&block)
15
- RestClient.post options[:host], report.to_json, :content_type => :json, :accept => :json
16
- end
8
+
9
+ @@options = {
10
+ :host => 'http://casper.jrs-labs.com:8080'
11
+ }
17
12
 
18
13
  def self.report options={}
19
14
  Client.build options do |report|
@@ -22,6 +17,19 @@ module Casper
22
17
  report.xpath = options[:xpath]
23
18
  end
24
19
  end
20
+
21
+ def self.options options={}
22
+ @@options.merge!(options)
23
+ end
24
+
25
+ private
26
+
27
+ def self.build(options={}, &block)
28
+ options = @@options.merge!(options)
29
+ report = Report.new
30
+ report.instance_eval(&block)
31
+ RestClient.post options[:host], report.to_json, :content_type => :json, :accept => :json
32
+ end
25
33
 
26
34
  end
27
35
 
@@ -19,11 +19,11 @@ describe Casper::Client do
19
19
  }
20
20
  }.to_json, :content_type => :json, :accept => :json
21
21
  )
22
- report = Casper::Client.build do |report|
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
22
+ report = Casper::Client.report(
23
+ :template => open(File.join(File.dirname(__FILE__),'data/report.jrxml')),
24
+ :xml => open(File.join(File.dirname(__FILE__),'data/dataset.xml')),
25
+ :xpath => '//root'
26
+ )
27
27
  end
28
28
 
29
29
  it 'should build the correct request to a report with a xml file as datasource with a optional host' do
@@ -37,14 +37,14 @@ describe Casper::Client do
37
37
  }
38
38
  }.to_json, :content_type => :json, :accept => :json
39
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'))
43
- report.xpath = '//root'
44
- end
40
+ report = Casper::Client.report(
41
+ :template => open(File.join(File.dirname(__FILE__),'data/report.jrxml')),
42
+ :xml => open(File.join(File.dirname(__FILE__),'data/dataset.xml')),
43
+ :xpath => '//root',
44
+ :host => 'http://myserver'
45
+ )
45
46
  end
46
47
 
47
-
48
48
  it 'should build the correct request to a report with a xml string as datasource' do
49
49
  RestClient.should_receive(:post).with(
50
50
  'http://mycasperserver.com',
@@ -56,31 +56,35 @@ describe Casper::Client do
56
56
  }
57
57
  }.to_json, :content_type => :json, :accept => :json
58
58
  )
59
- report = Casper::Client.build :host => 'http://mycasperserver.com' do |report|
60
- report.template = open(File.join(File.dirname(__FILE__),'data/report.jrxml'))
61
- report.xml = '<model/>'
62
- report.xpath = '//root'
63
- end
59
+ report = Casper::Client.report(
60
+ :template => open(File.join(File.dirname(__FILE__),'data/report.jrxml')),
61
+ :xml => '<model/>',
62
+ :xpath => '//root',
63
+ :host => 'http://mycasperserver.com'
64
+ )
64
65
  end
65
66
 
66
- it 'should build the correct request to a report without a block as param' do
67
+
68
+ it 'should be possible to configure the client directly from a single point' do
69
+ Casper::Client.options[:host] = 'http://host.config.com'
67
70
  RestClient.should_receive(:post).with(
68
- 'http://casper.jrs-labs.com:8080',
71
+ 'http://host.config.com',
69
72
  {:casper =>
70
73
  {
71
74
  :jrxml => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/report.jrxml')).read),
72
- :data => Base64.encode64(open(File.join(File.dirname(__FILE__),'data/dataset.xml')).read),
75
+ :data => Base64.encode64('<model/>'),
73
76
  :xpath => '//root'
74
77
  }
75
78
  }.to_json, :content_type => :json, :accept => :json
76
79
  )
77
80
  report = Casper::Client.report(
78
81
  :template => open(File.join(File.dirname(__FILE__),'data/report.jrxml')),
79
- :xml => open(File.join(File.dirname(__FILE__),'data/dataset.xml')),
80
- :xpath => '//root'
81
- )
82
+ :xml => '<model/>',
83
+ :xpath => '//root',
84
+ :host => 'http://host.config.com'
85
+ )
82
86
  end
83
-
87
+
84
88
  end
85
89
 
86
90
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casper-client
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease:
5
- version: 0.0.5
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
6
11
  platform: ruby
7
12
  authors:
8
13
  - Daniel Tamiosso
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-05-15 00:00:00 -03:00
18
+ date: 2011-06-10 00:00:00 -03:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,31 +26,56 @@ dependencies:
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 2
32
+ - 5
33
+ - 0
24
34
  version: 2.5.0
25
35
  type: :development
26
36
  version_requirements: *id001
27
37
  - !ruby/object:Gem::Dependency
28
- name: rest-client
38
+ name: bundler
29
39
  prerelease: false
30
40
  requirement: &id002 !ruby/object:Gem::Requirement
31
41
  none: false
32
42
  requirements:
33
43
  - - ">="
34
44
  - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
35
48
  version: "0"
36
- type: :runtime
49
+ type: :development
37
50
  version_requirements: *id002
38
51
  - !ruby/object:Gem::Dependency
39
- name: bundler
52
+ name: rest-client
40
53
  prerelease: false
41
54
  requirement: &id003 !ruby/object:Gem::Requirement
42
55
  none: false
43
56
  requirements:
44
57
  - - ">="
45
58
  - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
46
62
  version: "0"
47
63
  type: :runtime
48
64
  version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: json
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
49
79
  description: just a simple api for casper service (a web server framework for JasperReports)
50
80
  email:
51
81
  - email@danieltamiosso.com
@@ -82,17 +112,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
112
  requirements:
83
113
  - - ">="
84
114
  - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
85
118
  version: "0"
86
119
  required_rubygems_version: !ruby/object:Gem::Requirement
87
120
  none: false
88
121
  requirements:
89
122
  - - ">="
90
123
  - !ruby/object:Gem::Version
124
+ hash: 23
125
+ segments:
126
+ - 1
127
+ - 3
128
+ - 6
91
129
  version: 1.3.6
92
130
  requirements: []
93
131
 
94
132
  rubyforge_project: casper-client
95
- rubygems_version: 1.5.2
133
+ rubygems_version: 1.4.1
96
134
  signing_key:
97
135
  specification_version: 3
98
136
  summary: just a simple api for casper service