-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
184 lines (164 loc) · 5.35 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'
require 'lib/code_generation/xsd_parser'
CLOBBER.add('lib/wc_data/generated', 'lib/wc_data/thing.rb', 'lib/xsd/requests',
'lib/xsd/responses', 'lib/xsd/things', 'lib/xsd/common', 'lib/hv.log')
task :default => [:get_things, :rdoc]
task :bootstrap => [:clobber] do |t|
bootstrap_dir = "lib/xsd/bootstrap/"
Dir.foreach(bootstrap_dir) do |filename|
if filename.include?(".xsd")
p = HealthVault::CodeGeneration::XSDParser.new("#{bootstrap_dir}/#{filename}")
p.run
end
end
end
task :get_services => [:bootstrap] do |t|
xsd_dir = 'lib/xsd'
load 'lib/application.rb'
app = HealthVault::Application.default
connection = app.create_connection
request_schemas = Array.new
response_schemas = Array.new
common_schemas = Array.new
# get the common and method schemas from the server
request = HealthVault::Request.create("GetServiceDefinition", connection)
result = request.send
result.info.xml_method.each do |xm|
xm.version.each do |v|
q = v.request_schema_url.to_s
p = v.response_schema_url.to_s
request_schemas << q unless q.empty?
response_schemas << p unless p.empty?
end
end
result.info.common_schema.each do |cs|
common_schemas << cs.to_s unless cs.to_s.empty?
end
run_parser(xsd_dir + "/common", common_schemas)
run_parser(xsd_dir + "/requests", request_schemas)
run_parser(xsd_dir + "/responses", response_schemas)
end
task :get_things => [:get_services] do |t|
load 'lib/wc_data/init.rb'
require "rexml/document"
require "rexml/xpath"
app = HealthVault::Application.default
connection = app.create_connection
#get thing schemas
request = HealthVault::Request.create("GetThingType", connection)
request.info.add_section('xsd')
puts "getting thing schemas..."
result = request.send
tdir = "lib/xsd/things"
unless File.exists?(tdir)
Dir.mkdir(tdir)
end
result.info.thing_type.each do |type|
#figure out what the class should be called based off the wrapper class info in the xsd
# if there isnt anything there fall back the the name of the thing
xsd = type.xsd
xsd_xml = REXML::Document.new xsd
wrapper_class = REXML::XPath.first(xsd_xml,"//wrapper-class-name")
name = wrapper_class ? wrapper_class.text : type.name
puts "Thing Name: #{name} "
path = File.exist?(tdir + "/#{name}.xsd") ? tdir + "/#{name}_2.xsd" : tdir + "/#{name}.xsd"
puts "Saving as #{path}"
File.open(path, 'w') do |f|
f << xsd
end
end
#generate thing types
x = HealthVault::CodeGeneration::XSDParser.new("")
Dir.foreach(tdir) do |filename|
if filename.include?(".xsd")
puts "parsing: #{filename}"
p = HealthVault::CodeGeneration::XSDParser.new(tdir +"/#{filename}")
x.add_thing(tdir + "/#{filename}")
p.run
end
end
x.create_things
end
def run_parser(wdir, schemas)
proxy = get_proxy
unless File.exists?(wdir)
Dir.mkdir(wdir)
end
schemas.each do |s|
name = s.split(/\//)
uri = URI.parse(s)
http = Net::HTTP.new(uri.host, uri.port,proxy.host,proxy.port,proxy.user,proxy.password)
http.use_ssl = true
File.open("#{wdir}/#{name[name.length - 1]}" , 'w') { |f|
f.write(http.get(uri.path).body)
}
end
Dir.foreach(wdir) do |filename|
if filename.include?(".xsd")
puts "parsing: #{filename}"
p = HealthVault::CodeGeneration::XSDParser.new(wdir + "/#{filename}")
p.run
end
end
end
def get_proxy
ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
end
spec = Gem::Specification.new do |s|
s.name = 'ruby-healthvault'
s.version = '0.0.2'
s.has_rdoc = true
s.extra_rdoc_files = ['README', 'LICENSE']
s.summary = 'Connect your Ruby code to the Microsoft HealthVault'
s.description = s.summary
s.homepage = 'http://rubyhealthvault.rubyforge.org/'
s.rubyforge_project = 'rubyhealthvault'
s.authors = ['Danny Coates','Rob Dingwell']
s.email = 'dcoates@podfitness.com'
# s.executables = ['your_executable_here']
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
s.require_path = "lib"
s.bindir = "bin"
end
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
p.need_tar = true
p.need_zip = true
end
Rake::RDocTask.new do |rdoc|
files =['README', 'LICENSE', 'lib/**/*.rb']
rdoc.rdoc_files.add(files)
rdoc.main = "README" # page to start on
rdoc.title = "rubyhealthvault Docs"
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
rdoc.options << '--line-numbers'
end
Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*.rb']
end
Spec::Rake::SpecTask.new('testspec') do |t|
t.spec_files = FileList['spec/**/*.rb']
end
begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
gemspec.name = "ruby-healthvault"
gemspec.summary = 'Connect your Ruby code to the Microsoft HealthVault'
gemspec.description = gemspec.summary
gemspec.email = "bobd@mitre.org"
gemspec.homepage = "http://github.com/rdingwell/ruby-healthvault"
gemspec.authors = ['Danny Coates','Rob Dingwell']
gemspec.executables = []
gemspec.has_rdoc = true
gemspec.require_path = "lib"
gemspec.bindir = "bin"
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end