Skip to content

Commit e260224

Browse files
author
Matt Binsfeld
committed
moving client to git
1 parent 568a1e0 commit e260224

29 files changed

+1143
-0
lines changed

AdoDataSource.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# "THE BEER-WARE LICENSE"
2+
# As long as you retain this notice you can do whatever you want with this
3+
# stuff. If you meet an employee from Windward some day, and you think this
4+
# stuff is worth it, you can buy them a beer in return. Windward Studios
5+
6+
7+
require 'rexml/document'
8+
require_relative 'DataSource'
9+
include REXML
10+
11+
class AdoDataSource < DataSource
12+
@className
13+
@connectionString
14+
15+
def initialize(className, connectionString)
16+
@className = className
17+
@connectionString = connectionString
18+
end
19+
20+
def GetXml(name)
21+
element = Element.new "Datasource"
22+
e = element.add_element "Name"
23+
e.add_text name.to_s
24+
e = element.add_element "Type"
25+
e.add_text "sql"
26+
e = element.add_element "ClassName"
27+
e.add_text @className.to_s
28+
e = element.add_element "ConnectionString"
29+
e.add_text @connectionString.to_s
30+
if @Variables != nil && @Variables.length > 0
31+
element.add_element(GetVariablesXml)
32+
end
33+
return element
34+
end
35+
end

Client.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# "THE BEER-WARE LICENSE"
2+
# As long as you retain this notice you can do whatever you want with this
3+
# stuff. If you meet an employee from Windward some day, and you think this
4+
# stuff is worth it, you can buy them a beer in return. Windward Studios
5+
6+
require "net/http"
7+
require "uri"
8+
9+
10+
class Client
11+
def self.post(uri, body)
12+
req = Net::HTTP::Post.new(uri)
13+
req.body = body.to_s
14+
req.content_type = 'text/xml'
15+
return processRequest(req, uri)
16+
end
17+
18+
def self.get(uri)
19+
#req = Net::HTTP::Get.new(uri)
20+
#return processRequest(req, uri)
21+
return Net::HTTP.get_response(uri)
22+
end
23+
24+
def self.delete(uri)
25+
http = Net::HTTP.new(uri.host, uri.port)
26+
req = Net::HTTP::Delete.new(uri.path)
27+
return processRequest(req, uri)
28+
end
29+
30+
def self.processRequest(req, uri)
31+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
32+
http.request(req)
33+
end
34+
return res
35+
end
36+
37+
def sendRequest(request)
38+
#TODO
39+
end
40+
41+
def setRequestBody(request)
42+
#TODO
43+
end
44+
45+
def getResponseBody(response)
46+
#TODO
47+
end
48+
end

DataSource.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# "THE BEER-WARE LICENSE"
2+
# As long as you retain this notice you can do whatever you want with this
3+
# stuff. If you meet an employee from Windward some day, and you think this
4+
# stuff is worth it, you can buy them a beer in return. Windward Studios
5+
6+
require 'rexml/document'
7+
include REXML
8+
9+
class DataSource
10+
attr_accessor :variables
11+
12+
def GetVariablesXml()
13+
element = Element.new "Variables"
14+
@varables.each do |variable|
15+
e = element.add_element "Variable"
16+
el = e.add_element "Name"
17+
el.add_text variable.Name
18+
el = e.add_element "Value"
19+
el.add_text variable.Value
20+
end
21+
puts element.to_s
22+
return element
23+
end
24+
end
25+

Gemfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source "https://rubygems.org"
2+
gem 'ci_reporter', '= 1.9.1'
3+
gem 'test-unit', '= 2.5.5'
4+
#gem 'nokogiri'
5+
gem 'json_pure', '1.8.2'
6+
#gem "net/http"
7+
#gem "uri"
8+
9+

Gemfile.lock

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
builder (3.2.2)
5+
ci_reporter (1.9.1)
6+
builder (>= 2.1.2)
7+
json_pure (1.8.2)
8+
test-unit (2.5.5)
9+
10+
PLATFORMS
11+
x86-mingw32
12+
13+
DEPENDENCIES
14+
ci_reporter (= 1.9.1)
15+
json_pure (= 1.8.2)
16+
test-unit (= 2.5.5)

LICENCE

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"THE BEER-WARE LICENSE"
2+
As long as you retain this notice you can do whatever you want with this
3+
stuff. If you meet an employee from Windward some day, and you think this
4+
stuff is worth it, you can buy them a beer in return. Windward Studios

Report.rb

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# "THE BEER-WARE LICENSE"
2+
# As long as you retain this notice you can do whatever you want with this
3+
# stuff. If you meet an employee from Windward some day, and you think this
4+
# stuff is worth it, you can buy them a beer in return. Windward Studios
5+
6+
require "uri"
7+
require "net/http"
8+
require "rexml/document"
9+
require "base64"
10+
#require 'nokogiri'
11+
require_relative 'Client'
12+
require_relative 'Version'
13+
require 'json/pure'
14+
include REXML
15+
16+
class Report
17+
@baseUri
18+
@template
19+
@report
20+
@guid
21+
22+
attr_accessor :Description
23+
attr_accessor :Title
24+
attr_accessor :Subject
25+
attr_accessor :Keywords
26+
attr_accessor :Locale
27+
attr_accessor :Timeout
28+
29+
attr_accessor :Hyphenate
30+
attr_accessor :TrackImports
31+
attr_accessor :RemoveUnusedFormats
32+
attr_accessor :CopyMetadata
33+
34+
attr_reader :OutputFormat
35+
36+
def initialize(baseUri, template, report = nil)
37+
ctor(baseUri)
38+
@template = template
39+
@report = report
40+
end
41+
def ctor(baseUri)
42+
url = baseUri.to_s
43+
if !url.end_with? "/"
44+
url.concat("/")
45+
end
46+
@baseUri = URI(url)
47+
@Timeout = 0
48+
@Hyphenate = :template
49+
@TrackImports = false
50+
@RemoveUnusedFormats = true
51+
@CopyMetadata = :nodatasource
52+
end
53+
54+
def self.GetVersion(baseUri)
55+
uri = URI.join(baseUri, "v1/version")
56+
response = Client.get(uri)
57+
status = response.message
58+
body = response.body
59+
p_body = JSON.parse(body)
60+
if(status == 'OK')
61+
ev = p_body["EngineVersion"].to_s
62+
sv = p_body["ServiceVersion"].to_s
63+
v = Version.new(sv, ev)
64+
else
65+
return nil
66+
end
67+
return v
68+
end
69+
70+
def ProcessDataSources(dataSources)
71+
xml = CreateXmlDocument()
72+
ApplyDataSources xml, dataSources
73+
ProcessXml xml
74+
end
75+
76+
def Process()
77+
xml = CreateXmlDocument()
78+
ProcessXml xml
79+
end
80+
81+
def ProcessXml(xml)
82+
SetReportOption(xml, "Description", @Description)
83+
SetReportOption(xml, "Title", @Title)
84+
SetReportOption(xml, "Subject", @Subject)
85+
SetReportOption(xml, "Keywords", @Keywords)
86+
SetReportOption(xml, "Description", @Description)
87+
SetReportOption(xml, "Locale", @Locale)
88+
89+
root = xml.root
90+
e = root.add_element "Timeout"
91+
e.add_text @Timeout.to_s
92+
93+
e = root.add_element "Hyphenate"
94+
e.add_text @Hyphenate.to_s
95+
96+
if(@TrackImports)
97+
_track_imports = "true"
98+
else
99+
_track_imports = "false"
100+
end
101+
102+
e = root.add_element "TrackImports"
103+
e.add_text _track_imports
104+
105+
if(@RemoveUnusedFormats)
106+
_remove_form = "true"
107+
else
108+
_remove_form = "false"
109+
end
110+
111+
e = root.add_element "RemoveUnusedFormats"
112+
e.add_text _remove_form
113+
114+
e = root.add_element "CopyMetadata"
115+
e.add_text @CopyMetadata.to_s
116+
117+
if(@report == nil)
118+
e = root.add_element "Async"
119+
e.add_text "true"
120+
end
121+
result = Client.post(URI.join(@baseUri, "v1/reports"), xml)
122+
status = result.message
123+
body = result.body
124+
if(status == 'OK')
125+
if(@report != nil)
126+
ReadReport(body)
127+
else
128+
ReadGuid(body)
129+
end
130+
else
131+
raise body.to_s
132+
end
133+
end
134+
135+
def GetReport
136+
uri = URI.join(@baseUri, "v1/reports")
137+
uri = URI.join(uri, @guid)
138+
139+
result = Client.Get(uri)
140+
status = result.message
141+
body = result.body
142+
if(status == 'OK')
143+
return Base64.decode64(body.root.get_elements("Data")[0].get_text.value)
144+
end
145+
return null
146+
end
147+
148+
def Delete
149+
uri = URI.join(@baseUri, v1/reports)
150+
uri = URI.join(uri, @guid)
151+
result = Client.Delete(uri)
152+
end
153+
154+
def GetStatus
155+
uri = URI.join(@baseUri, "v1/reports/")
156+
uri = URI.join(uri, @guid)
157+
uri = URI.join(uri, "/status")
158+
result = Client.get(uri)
159+
status = result.code
160+
161+
case status
162+
when 200
163+
return :Ready
164+
when 202
165+
return :Working
166+
when 500
167+
return :Error
168+
else
169+
return :NotFound
170+
end
171+
end
172+
173+
def ReadReport result
174+
p_result = JSON.parse(result)
175+
data = Base64.decode64(p_result["Data"])
176+
@report.write(data)
177+
#File.open(@report, 'wb') do |output|
178+
# output.puts data
179+
#end
180+
end
181+
182+
def ReadGuid body
183+
p_body = JSON.parse(body)
184+
@guid = body["Data"][0]
185+
end
186+
187+
def SetReportOption xml, name, option
188+
if(option != nil)
189+
e = xml.root.add_element name
190+
e.add_text option.to_s
191+
end
192+
end
193+
194+
def CreateXmlDocument
195+
bytes = File.binread(@template)
196+
encodedTemplate = Base64.encode64(bytes)
197+
xml = Document.new
198+
e = xml.add_element "Template"
199+
e1 = e.add_element "Data"
200+
e1.add_text encodedTemplate
201+
e1 = e.add_element "OutputFormat"
202+
e1.add_text @OutputFormat.to_s
203+
return xml
204+
end
205+
206+
def ApplyDataSources xml, dataSources
207+
if(dataSources.length > 0)
208+
xmlDatasources = xml.root.add_element "Datasources"
209+
dataSources.each do |key, value|
210+
e = xmlDatasources.add_element(value.GetXml(key).root)
211+
end
212+
end
213+
end
214+
end

ReportCsv.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# "THE BEER-WARE LICENSE"
2+
# As long as you retain this notice you can do whatever you want with this
3+
# stuff. If you meet an employee from Windward some day, and you think this
4+
# stuff is worth it, you can buy them a beer in return. Windward Studios
5+
6+
require_relative 'report'
7+
class ReportCsv < Report
8+
def initialize uri, template, report = nil
9+
@OutputFormat = :csv
10+
super
11+
end

ReportDocx.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require_relative 'report'
2+
class ReportDocx < Report
3+
def initialize uri, template, report = nil
4+
@OutputFormat = :docx
5+
super
6+
end
7+
end

ReportException.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# "THE BEER-WARE LICENSE"
2+
# As long as you retain this notice you can do whatever you want with this
3+
# stuff. If you meet an employee from Windward some day, and you think this
4+
# stuff is worth it, you can buy them a beer in return. Windward Studios
5+
6+
require_relative 'report'
7+
class ReportException < Exception
8+
def initialize(msg=nil)
9+
super(msg)
10+
end
11+
end

0 commit comments

Comments
 (0)