Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reorganized Generation and Added Rails Install

  • Loading branch information...
commit 3f005d228778b13a28d3932f795fef049a450fbe 1 parent 8587288
@wagenet authored
View
3  Rakefile
@@ -1,6 +1,7 @@
require File.join(File.dirname(__FILE__), 'init')
require 'rake'
+require 'rake/clean'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
@@ -8,6 +9,8 @@ require 'spec/rake/spectask'
load File.join(File.dirname(__FILE__), 'tasks', 'healthvault.rake')
+CLOBBER.add("#{HEALTHVAULT_ROOT}/lib/health_vault/hv.log")
+CLOBBER.add(*HealthVault::CodeGeneration::Generator::GENERATED_PATHS)
task :default => ['healthvault:get_things', :rdoc]
View
3  install.rb
@@ -0,0 +1,3 @@
+require File.join(File.dirname(__FILE__), 'init')
+
+HealthVault::CodeGeneration::Generator.get_things
View
125 lib/health_vault/code_generation/generator.rb
@@ -0,0 +1,125 @@
+module HealthVault
+ module CodeGeneration
+ class Generator
+
+ GENERATED_PATHS = [
+ "#{HEALTHVAULT_ROOT}/lib/health_vault/wc_data/thing.rb",
+ "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/requests",
+ "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/responses",
+ "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/things",
+ "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/common",
+ "#{HEALTHVAULT_ROOT}/lib/generated"
+ ]
+
+ BOOTSTRAP_DIR = "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/bootstrap"
+ XSD_DIR = "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd"
+ THINGS_DIR = "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/things"
+
+
+ def self.get_things
+ new.get_things
+ end
+
+
+ def remove_generated
+ # TODO: Log this
+ GENERATED_PATHS.each{|fn| FileUtils.rm_r fn rescue nil }
+ end
+
+ # TODO: Is there a way to tell what's been run?
+
+ def bootstrap
+ remove_generated
+
+ Dir.foreach(BOOTSTRAP_DIR) do |filename|
+ if filename.ends_with?(".xsd")
+ HealthVault::CodeGeneration::XSDParser.new("#{BOOTSTRAP_DIR}/#{filename}").run
+ end
+ end
+ end
+
+ def get_services
+ bootstrap
+
+ request_schemas = []
+ response_schemas = []
+ common_schemas = []
+
+ # get the common and method schemas from the server
+ result = connection.send_request("GetServiceDefinition")
+
+ 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
+
+ def get_things
+ get_services
+
+ puts "getting thing schemas..."
+ result = connection.send_request("GetThingType") {|r| r.info.add_section('xsd') }
+
+ Dir.mkdir(THINGS_DIR) unless File.exists?(THINGS_DIR)
+ result.info.thing_type.each do |type|
+ File.open("#{THINGS_DIR}/#{type.name}.xsd", 'w'){|f| f << type.xsd }
+ end
+
+ #generate thing types
+ x = HealthVault::CodeGeneration::XSDParser.new("")
+ Dir.foreach(THINGS_DIR) do |filename|
+ if filename.ends_with?(".xsd")
+ puts "parsing: #{filename}"
+ p = HealthVault::CodeGeneration::XSDParser.new("#{THINGS_DIR}/#{filename}")
+ x.add_thing("#{THINGS_DIR}/#{filename}")
+ p.run
+ end
+ end
+ x.create_things
+ end
+
+ private
+
+ def connection
+ unless @connection
+ app = HealthVault::Application.default
+ @connection = app.create_connection
+ end
+ @connection
+ end
+
+ def run_parser(wdir, schemas)
+ 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)
+ 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
+
+ end
+ end
+end
View
101 tasks/healthvault.rake
@@ -1,105 +1,10 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'init'))
-require 'rake/clean'
-
-clobber = %w(wc_data/thing.rb xsd/requests xsd/responses xsd/things xsd/common hv.log).
- map{|f| "#{HEALTHVAULT_ROOT}/lib/health_vault/#{f}" }
-clobber << "#{HEALTHVAULT_ROOT}/lib/generated"
-CLOBBER.add(*clobber)
namespace :healthvault do
- desc "Bootstrap HealthVault"
- task :bootstrap => [:clobber] do |t|
- bootstrap_dir = "#{HEALTHVAULT_ROOT}/lib/health_vault/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
-
- desc "Get HealthVault services"
- task :get_services => [:bootstrap] do |t|
- xsd_dir = "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd"
- app = HealthVault::Application.default
- connection = app.create_connection
-
- request_schemas = []
- response_schemas = []
- common_schemas = []
-
- # 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
desc "Get HealthVault Things"
- task :get_things => [:get_services] do |t|
- 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 = "#{HEALTHVAULT_ROOT}/lib/health_vault/xsd/things"
- unless File.exists?(tdir)
- Dir.mkdir(tdir)
- end
- result.info.thing_type.each do |type|
- File.open(tdir + "/#{type.name}.xsd", 'w') do |f|
- f << type.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
-end
-
-def run_parser(wdir, schemas)
- 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)
- http.use_ssl = true
- File.open("#{wdir}/#{name[name.length - 1]}" , 'w') { |f|
- f.write(http.get(uri.path).body)
- }
+ task :get_things do |t|
+ HealthVault::CodeGeneration::Generator.get_things
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
Please sign in to comment.
Something went wrong with that request. Please try again.