Permalink
Browse files

documented example.rb and README

made TestServer open ie on windows

git-svn-id: svn://rubyforge.org/var/svn/rubyhealthvault/trunk@9 5e59f7e3-561f-4167-93e6-46889eec4fca
  • Loading branch information...
1 parent ff157b5 commit 153fedb0c774e033021512d8ec1bab0571c3b671 dannycoates committed Jun 7, 2008
Showing with 64 additions and 4 deletions.
  1. +17 −1 README
  2. +34 −1 bin/example.rb
  3. +1 −1 nbproject/private/private.properties
  4. +1 −0 nbproject/project.properties
  5. +1 −0 nbproject/project.xml
  6. +10 −1 spec/support/test_server.rb
View
@@ -1,3 +1,19 @@
== HealthVaultRubyLib
-You should document your project here.
+Please refer to bin/example.rb as a quick introduction.
+
+The RDoc documentation provides basic but helpful api specifications for the
+generated HealthVault classes.
+
+When using as a gem:
+require 'healthvault'
+
+KNOWN ISSUES:
+
+- PFX certificates do not load properly on Windows, they must be a pem
+- TestServer doesn't open a browser on Windows when running with JRuby
+- Validation of SimpleTypes and ComplexTypes is not implemented
+- All XSD base types including numbers (like 'int') are represented as String
+- HealthVault 'versions' of Things and Methods are not supported
+- When parsing a response that is defined to contain 'any' value, the parser
+ will only try to guess if its a Thing, otherwise it will skip
View
@@ -3,29 +3,62 @@
require File.dirname(__FILE__) + "/../spec/support/test_server"
include HealthVault
+#The first thing we should do is set our Configuration.
+#This example uses the defaults from config.rb, so nothing needs to be done
+#To make changes follow this commented example:
+#
+#Configuration.instance.app_id = "05a059c9-c309-46af-9b86-b06d42510550"
+#Configuration.instance.logger = RAILS_DEFAULT_LOGGER
+
+#Then we need an Application.
+#Application.default will use settings from Configuration,
+#or you can use Application.new to use other parameters
app = Application.default
+
+#Once we have an Application, we can create Connections.
+#A connection contains the session_token and shared_secret
+#for maintaining a session with HealthVault. It can also hold
+#the user_auth_token of a HealthVault user, and it can be serialized
+#and saved for later, for instance, in a Rails session
connection = app.create_connection
+#Authenticating a connection creates a shared_secret and session_token
+#with HealthVault using the Application.id and certificate as credentials.
+#Most useful HealthVault methods require an authenticated connection.
connection.authenticate
puts 'authenticated application...'
+#Requests are used to communicate with HealthVault.
+#They are created with Request.create passing in the name of the method,
+#and the connection. Depending on the method, additional info may be required
+#before sending the request.
request = Request.create("GetVocabulary", connection)
request.info.vocabulary_parameters = WCData::Methods::GetVocabulary::VocabularyParameters.new
request.info.vocabulary_parameters.add_vocabulary_key WCData::Vocab::VocabularyKey.new
request.info.vocabulary_parameters.vocabulary_key[0].name = "thing-types"
request.info.vocabulary_parameters.vocabulary_key[0].family = "wc"
request.info.vocabulary_parameters.vocabulary_key[0].version = '1'
request.info.vocabulary_parameters.fixed_culture = 'true'
+#the return value of request.send is a Response object if the request succeeds,
+#otherwise a StandardError is raised.
result = request.send
puts 'got thing-type vocabulary...'
+#The TestServer allows us to authenticate a user through the browser.
+#It should not be used for anything but testing.
t = TestServer.new
t.open_login
t.wait_for_auth
+#We set the user_auth_token of connection. Now we can make requests that require
+#the user to be logged in.
connection.user_auth_token = t.auth_token
+
+#now that the user is logged in, we can get their info
request = Request.create("GetPersonInfo", connection)
result = request.send
-
+#selected_record_id is an important field used by many HealthVault methods.
+#Once we have it, it should be added to our Request.header.record_id on
+#future requests like GetThings, PutThings, etc.
record_id = result.info.person_info.selected_record_id
puts 'got person info for...'
@@ -1 +1 @@
-platform.active=default
+platform.active=Ruby
@@ -4,5 +4,6 @@ platform.active=Ruby
ruby.includejava=false
source.encoding=UTF-8
spec.src.dir=spec
+src.bin.dir=bin
src.dir=lib
test.src.dir=test
@@ -5,6 +5,7 @@
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
<name>HealthVaultRubyLib</name>
<source-roots>
+ <root id="src.bin.dir"/>
<root id="src.dir"/>
</source-roots>
<test-roots>
@@ -1,3 +1,6 @@
+if RUBY_PLATFORM =~ /(:?mswin|mingw)/ #TODO: what about jruby?
+ require 'win32ole'
+end
require 'cgi'
require 'webrick'
require 'thread'
@@ -27,7 +30,13 @@ def wait_for_auth
end
def open_login
- system("open","https://account.healthvault-ppe.com/redirect.aspx?target=AUTH&targetqs=?appid=05a059c9-c309-46af-9b86-b06d42510550%26redirect=http://localhost:7331/testAuth")
+ if RUBY_PLATFORM =~ /(:?mswin|mingw)/
+ ie = WIN32OLE.new('InternetExplorer.Application')
+ ie.visible = true
+ ie.navigate("https://account.healthvault-ppe.com/redirect.aspx?target=AUTH&targetqs=?appid=05a059c9-c309-46af-9b86-b06d42510550%26redirect=http://localhost:7331/testAuth")
+ else
+ system("open","https://account.healthvault-ppe.com/redirect.aspx?target=AUTH&targetqs=?appid=05a059c9-c309-46af-9b86-b06d42510550%26redirect=http://localhost:7331/testAuth")
+ end
end
end

0 comments on commit 153fedb

Please sign in to comment.