Skip to content
Browse files

Further Rails prep

  • Loading branch information...
1 parent e65b6ae commit 1c0afee62b5a528b66a7cb0c23bf406ce76cf0cd @wagenet committed Apr 2, 2009
Showing with 122 additions and 100 deletions.
  1. +4 −100 Rakefile
  2. +1 −0 init.rb
  3. +13 −0 rails/init.rb
  4. +104 −0 tasks/healthvault.rake
View
104 Rakefile
@@ -1,111 +1,15 @@
-require 'rubygems'
+require File.join(File.dirname(__FILE__), 'init')
+
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
+load File.join(File.dirname(__FILE__), 'tasks', 'healthvault.rake')
- 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'
-
- 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|
- 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
-
-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
+task :default => ['healthvault:get_things', :rdoc]
spec = Gem::Specification.new do |s|
s.name = 'rubyhealthvault'
View
1 init.rb
@@ -0,0 +1 @@
+require File.expand_path(File.join(File.dirname(__FILE__), 'rails', 'init'))
View
13 rails/init.rb
@@ -0,0 +1,13 @@
+require 'rubygems'
+require 'active_support'
+
+HEALTHVAULT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+$LOAD_PATH << File.join(HEALTHVAULT_ROOT, 'lib')
+$LOAD_PATH << File.join(HEALTHVAULT_ROOT, 'lib', 'generated')
+
+Dependencies = ActiveSupport::Dependencies unless defined?(Dependencies)
+Dependencies.load_paths << File.join(HEALTHVAULT_ROOT, 'lib')
+Dependencies.load_paths << File.join(HEALTHVAULT_ROOT, 'lib', 'generated')
+
+require 'rexml/formatters/pretty_fix'
View
104 tasks/healthvault.rake
@@ -0,0 +1,104 @@
+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 = 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
+
+ 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)
+ }
+ 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

0 comments on commit 1c0afee

Please sign in to comment.
Something went wrong with that request. Please try again.