Permalink
Browse files

Renaming Files to fit Rails conventions

  • Loading branch information...
1 parent 91cee51 commit 0044ffe8c01d79904ce87eb03b4d825b16e8ee3f @wagenet committed Apr 2, 2009
View
@@ -0,0 +1,12 @@
+*.log
+.DS_Store
+
+lib/generated/*
+lib/health_vault/wc_data/thing.rb
+
+lib/health_vault/wc_data/thing.rb
+lib/health_vault/xsd/common/
+lib/health_vault/xsd/requests/
+lib/health_vault/xsd/responses/
+lib/health_vault/xsd/things/
+
View
@@ -1,4 +1,4 @@
-RubyHealthVault is copyrighted free software by Danny Coates and Ashkan Farhadtouski.
+RubyHealthVault is copyrighted free software by Danny Coates, Ashkan Farhadtouski and Peter Wagenet.
You can redistribute it and/or modify it under either the terms of the GPL (see
the GPL file), or the conditions below:
@@ -6,9 +6,7 @@
#++
require 'uri'
-require File.dirname(__FILE__) + '/config'
-require File.dirname(__FILE__) + '/connection'
-require File.dirname(__FILE__) + '/utils/crypto_utils'
+require 'utils/crypto_utils' # for CryptoKey
module HealthVault
class Application
@@ -22,7 +20,7 @@ def initialize(id, hv_uri, certificate_location, certificate_password)
end
def key
- return CryptoKey.new(@cert_file, @cert_pass)
+ return Utils::CryptoKey.new(@cert_file, @cert_pass)
end
def self.default
@@ -7,23 +7,20 @@
require 'rexml/document'
require 'erb'
-require File.dirname(__FILE__) + "/../wc_data/complex_type"
-require File.dirname(__FILE__) + "/../config"
-require File.dirname(__FILE__) + "/../utils/string_utils"
module HealthVault
module CodeGeneration
class XSDParser
- include StringUtils
+ include Utils::StringUtils
include REXML
-
+
def initialize(filename)
- cdir = File.dirname(__FILE__)
+ cdir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'templates'))
@filename = filename
- @simple_template = cdir + "/../templates/simple_type_template.erb"
- @complex_template = cdir + "/../templates/complex_type_template.erb"
- @thing_ex_template = cdir + "/../templates/thing_class_extension_template.erb"
- @file_path = cdir + "/../wc_data/generated"
+ @simple_template = cdir + "/simple_type_template.erb"
+ @complex_template = cdir + "/complex_type_template.erb"
+ @thing_ex_template = cdir + "/thing_class_extension_template.erb"
+ @file_path = "#{HEALTHVAULT_ROOT}/lib/generated/health_vault/wc_data"
@logger = Configuration.instance.logger
end
@@ -40,7 +37,7 @@ def add_thing(filename)
type = el.attribute('type').to_s
class_path = "HealthVault::WCData::"
if type.empty?
- class_path += (mods.collect {|s| classify(s)}).join('::') + "::" + classify(cname)
+ class_path += (mods.collect {|s| hv_classify(s)}).join('::') + "::" + hv_classify(cname)
else
namespaces = get_namespaces
class_path = get_class_path(type)
@@ -57,12 +54,12 @@ def create_things
class_hash = @thing_hash
result = ""
File.open(File.dirname(__FILE__) + "/../wc_data/thing.rb", 'w') do |f|
- e = ERB.new(File.read(@thing_ex_template), 0, '<>', 'result')
+ e = erb_with_defaults(File.read(@thing_ex_template))
e.result(binding)
f << result
end
end
-
+
# creates ruby class files for the types defined in the xsd
def run(test = :no)
@test = test
@@ -117,7 +114,7 @@ def get_namespaces
if name.include?('xmlns:')
m = value.match(/urn\:com\.microsoft\.wc\.(.*)/)
unless m.nil?
- mod = (m[1].split('.').collect {|s| classify(s)}).join('::')
+ mod = (m[1].split('.').collect {|s| hv_classify(s)}).join('::')
namespaces[name.split(':')[-1]]= mod
end
end
@@ -128,10 +125,10 @@ def get_namespaces
# create the directory structure from the xsd namespace
def create_directories
unless File.exists?(@file_path)
- Dir.mkdir(@file_path)
- end
+ FileUtils.mkdir_p(@file_path)
+ end
@modules.each do |m|
- @file_path << "/#{underscore(m)}"
+ @file_path << "/#{m.underscore}"
unless File.exists?(@file_path)
Dir.mkdir(@file_path)
end
@@ -142,8 +139,8 @@ def create_directories
def create_simple_type(e, cname = '')
cname = e.attribute('name').to_s if cname.empty?
cname = 'info' if cname.empty?
- file_name = underscore(cname)
- class_name = classify(cname)
+ file_name = to_filename(cname)
+ class_name = hv_classify(cname)
restrictions = Hash.new
e.get_elements('restriction').each do |r|
restrictions = restrictions.merge(parse_restriction(r))
@@ -155,9 +152,10 @@ def create_simple_type(e, cname = '')
def create_complex_type(e, cname = '')
cname = e.attribute('name').to_s if cname.empty?
children = Array.new
- file_name = underscore(cname)
- class_name = classify(cname)
+ file_name = to_filename(cname)
+ class_name = hv_classify(cname)
cdoc = doc(e)
+
e.elements.each do |child|
case child.name
when 'sequence'
@@ -171,6 +169,7 @@ def create_complex_type(e, cname = '')
children += parse_choice(child)
end
end
+
create_class_from_template(@complex_template, file_name, class_name, cname.downcase, cdoc, children)
end
@@ -266,6 +265,8 @@ def parse_choice(e)
choice_id = rand(1 << 29).to_s
e.elements.each do |child|
case child.name
+ when 'sequence'
+ children += parse_sequence(child)
when 'element'
n = parse_element(child, choice_id, min, max)
children << n unless n.nil?
@@ -348,29 +349,36 @@ def get_class_path(type)
comp = type.split(':')
@namespaces.each do |k,v|
if comp[0] == k
- return base + v + "::#{classify(type.gsub(/.*:/, ''))}"
+ return base + v + "::#{hv_classify(type.gsub(/.*:/, ''))}"
end
end
#TODO: parse xsd primatives
- return "String"#base + classify(type.gsub(/wc-.*:/, ''))
+ return "String"#base + hv_classify(type.gsub(/wc-.*:/, ''))
end
# generate the .rb file with the given template
def create_class_from_template(template, file_name, class_name, tag_name, cdoc, children = [])
result = ''
modules = @modules
+
if @test == :yes
- e = ERB.new(File.read(template), 0, '<>', 'result')
+ e = erb_with_defaults(File.read(template))
e.run(binding)
else
- File.open(@file_path + "/#{file_name}.rb", 'w') do |f|
- e = ERB.new(File.read(template), 0, '<>', 'result')
+ # Remove underscores before digits or our files will have the wrong names
+ file = File.join(File.expand_path(@file_path), "#{file_name}.rb")
+ File.open(file, 'w') do |f|
+ e = erb_with_defaults(File.read(template))
e.result(binding)
f << result
end
end
end
+ def erb_with_defaults(data)
+ ERB.new(data, 0, '-', 'result')
+ end
+
end
end
end
@@ -18,11 +18,12 @@ class Configuration
#using HealthVault::Configuration.instance accessor methods
def initialize
@app_id = "05a059c9-c309-46af-9b86-b06d42510550"
- @cert_file = File.dirname(__FILE__) + "/../bin/certs/helloWorld.pem"
+ @cert_file = "#{HEALTHVAULT_ROOT}/bin/certs/helloWorld.pem"
@cert_pass = ""
@shell_url = "https://account.healthvault-ppe.com"
@hv_url = "https://platform.healthvault-ppe.com/platform/wildcat.ashx"
- @logger = Logger.new("hv.log")
+ @logger = Logger.new("#{HEALTHVAULT_ROOT}/hv.log")
end
+
end
-end
+end
@@ -21,19 +21,19 @@ def initialize(application)
end
def authenticate
- @shared_secret = CryptoUtils.create_shared_secret
+ @shared_secret = Utils::CryptoUtils.create_shared_secret
@session_token = nil
request = Request.create("CreateAuthenticatedSessionToken", self)
request.info.auth_info.app_id.data = application.id
request.info.auth_info.credential.appserver = Types::AppServerCred.new
request.info.auth_info.credential.appserver.content.app_id = application.id
request.info.auth_info.credential.appserver.content.shared_secret.hmac_alg.alg_name = "HMACSHA1"
- request.info.auth_info.credential.appserver.content.shared_secret.hmac_alg.data = CryptoUtils.encode64(shared_secret)
+ request.info.auth_info.credential.appserver.content.shared_secret.hmac_alg.data = Utils::CryptoUtils.encode64(shared_secret)
request.info.auth_info.credential.appserver.sig.digest_method = "SHA1"
request.info.auth_info.credential.appserver.sig.sig_method = "RSA-SHA1"
request.info.auth_info.credential.appserver.sig.thumbprint = application.key.fingerprint
request.info.auth_info.credential.appserver.sig.data =
- CryptoUtils.encode64(application.key.sign(
+ Utils::CryptoUtils.encode64(application.key.sign(
request.info.auth_info.credential.appserver.content.element('content').to_s))
response = request.send
@@ -53,7 +53,7 @@ def send(request)
http_endpoint.use_ssl = true
#http_endpoint.verify_mode = OpenSSL::SSL::VERIFY_PEER
content = request.to_s
- Configuration.instance.logger.debug content
+ Configuration.instance.log_xml request.element
http_header = {'Content-Type' => 'text/xml'}
return Response.new(http_endpoint.post(application.uri.path, content, http_header))
end
@@ -8,7 +8,6 @@
require 'rexml/document'
require 'date'
require File.dirname(__FILE__) + '/utils/string_utils'
-require File.dirname(__FILE__) + '/wc_data/init'
# HealtVault doesn't adhere to valid xml standards.
# Attribute values must be in double quotes to be parseable
@@ -19,7 +18,7 @@ module HealthVault
class Request < HealthVault::WCData::ComplexType
include WCData
include REXML
- include StringUtils
+ include Utils::StringUtils
# HealthVault::WCData::Types::HMACFinalized
def auth=(value)
@@ -11,7 +11,7 @@
module HealthVault
class Response
include REXML
- include StringUtils
+ include Utils::StringUtils
include WCData
attr_reader :xml, :info
@@ -25,21 +25,21 @@ def initialize(http_response)
Configuration.instance.logger.error "ERRORCODE: #{code.to_s} MESSAGE: #{msg}"
raise StandardError.new(msg)
end
- Configuration.instance.logger.debug @xml.to_s
+ Configuration.instance.log_xml(@xml)
begin
info_node = XPath.first(@xml, '//wc:info')
response_namespace = info_node.attribute('xmlns:wc').to_s
m = response_namespace.match(/urn\:com\.microsoft\.wc\.(.*)/)
rescue => e
- Configuration.instance.logger.warn @xml
+ Configuration.instance.log_xml(@xml, :warn)
Configuration.instance.logger.warn e
m = nil
end
if m.nil?
@info = nil
else
begin
- mod = (m[1].split('.').collect {|s| classify(s)}).join('::') + "::Info.new"
+ mod = (m[1].split('.').collect {|s| hv_classify(s)}).join('::') + "::Info.new"
# eval may as well be called evil
nfo = eval mod
@info = nfo
@@ -1,43 +1,44 @@
# -*- ruby -*-
#--
-# Copyright 2008 Danny Coates, Ashkan Farhadtouski
+# Copyright 2008 Danny Coates, Ashkan Farhadtouski, Peter Wagenet
# All rights reserved.
# See LICENSE for permissions.
#++
# AUTOGENERATED ComplexType
module HealthVault
module WCData
- <% modules.each do |m| %>module <%= classify(m) %>
- <% end %>
+ <%- modules.each do |m| -%>
+ module <%= hv_classify(m) %>
+ <%- end -%>
class <%= class_name %> < ComplexType
<% children.each do |child| %>
<% if child[:max] == '1' %>
<% if child[:min].to_i > 0 %>#<b>REQUIRED</b><% end %>
<%= child[:doc] %><%= "#<em>value</em> is a #{child[:class]}" %>
- def <%= underscore(child[:name]) %>=(value)
+ def <%= child[:name].underscore.strip %>=(value)
@children['<%= child[:name] %>'][:value] = value
end
<%= "#<b>returns</b>: a #{child[:class]}" %>
- def <%= underscore(child[:name]) %>
+ def <%= child[:name].underscore.strip %>
return @children['<%= child[:name] %>'][:value]
end
<% else %>
<%= "#<em>value</em> is a #{child[:class]}" %>
- def add_<%= underscore(child[:name]) %>(value)
+ def add_<%= child[:name].underscore.strip %>(value)
@children['<%= child[:name] %>'][:value] << value
end
<%= "#<em>value</em> is a ##{child[:class]}" %>
- def remove_<%= underscore(child[:name]) %>(value)
+ def remove_<%= child[:name].underscore.strip %>(value)
@children['<%= child[:name] %>'][:value].delete(value)
end
<% if child[:min].to_i > 0 %>#<b>REQUIRED</b><% end %>
<%= child[:doc] %><%= "#<b>returns</b>: a #{child[:class]} Array" %>
- def <%= underscore(child[:name]) %>
+ def <%= child[:name].underscore.strip %>
return @children['<%= child[:name] %>'][:value]
end
<% end %>
@@ -8,13 +8,15 @@
module HealthVault
module WCData
- <% modules.each do |m| %>module <%= classify(m) + "\n" %><% end %>
+ <%- modules.each do |m| -%>
+ module <%= hv_classify(m) %>
+ <%- end -%>
<%= "##{class_name} is a #{children['base'].to_s}" %>
class <%= class_name %> < SimpleType
<% children.each do |name, target| %>
<% if name == 'enumeration' %>
<% target.each do |enum| %>
- def self.<%= enum.empty? ? 'empty' : underscore(enum.to_s.downcase.strip.gsub(' ', '_')) %>
+ def self.<%= enum.empty? ? 'empty' : enum.to_s.downcase.strip.gsub(' ', '_').underscore %>
return '<%= enum.to_s %>'
end
<% end %>
File renamed without changes.
File renamed without changes.
View
@@ -1,27 +0,0 @@
-# -*- ruby -*-
-#--
-# Copyright 2008 Danny Coates, Ashkan Farhadtouski
-# All rights reserved.
-# See LICENSE for permissions.
-#++
-
-dir = File.dirname(__FILE__) + '/generated'
-require dir + '/../simple_type'
-require dir + '/../complex_type'
-require dir + '/../raw_info_xml'
-
-def recurse_require(dir)
- Dir.foreach(dir) do |filename|
- f = dir + "/#{filename}"
- if File.directory?(f) && f[-1] != 46 #'.'
- recurse_require(f)
- elsif f.include?('.rb') && f != __FILE__
- require f
- end
- end
-end
-recurse_require(dir)
-# '/../thing' won't exist until generated
-if File.exists?(dir + '/../thing.rb')
- require dir + '/../thing'
-end

0 comments on commit 0044ffe

Please sign in to comment.