diff --git a/lib/scorm_cloud/connection.rb b/lib/scorm_cloud/connection.rb index ade84be..9d320c3 100644 --- a/lib/scorm_cloud/connection.rb +++ b/lib/scorm_cloud/connection.rb @@ -14,7 +14,12 @@ def call(method, params = {}) def call_raw(method, params = {}) url = prepare_url(method, params) execute_call_plain(url) - end + end + + def call_https(method, params = {}) + url = prepare_url(method, params) + execute_call_https(url) + end # Get plain response body and parse the XML doc def execute_call_xml(url) @@ -36,6 +41,24 @@ def execute_call_plain(url) raise "HTTP Error connecting to scorm cloud: #{res.inspect}" end end + + def execute_call_https(url) + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + + case res + when Net::HTTPRedirection + # Return the new URL + res['location'] + when Net::HTTPSuccess + res.body + else + raise "HTTP Error connecting to scorm cloud: #{res.inspect}" + end + end # Get the URL for the call def prepare_url(method, params = {}) @@ -51,7 +74,7 @@ def prepare_url(method, params = {}) join sig = Digest::MD5.hexdigest(raw) - "http://cloud.scorm.com/api?#{html_params}&sig=#{sig}" + "https://cloud.scorm.com/api?#{html_params}&sig=#{sig}" end diff --git a/lib/scorm_cloud/debug_service.rb b/lib/scorm_cloud/debug_service.rb index 4a0e779..8de5cc9 100644 --- a/lib/scorm_cloud/debug_service.rb +++ b/lib/scorm_cloud/debug_service.rb @@ -8,8 +8,8 @@ def ping() "pong" end - def auth_ping() - xml = connection.call("rustici.debug.authPing") + def auth_ping(appid) + xml = connection.call("rustici.debug.authPing", {appid: appid}) raise "Bad Server Response" unless xml.elements["/rsp/pong"] "pong" end diff --git a/lib/scorm_cloud/registration_service.rb b/lib/scorm_cloud/registration_service.rb index 3b518fd..062970f 100644 --- a/lib/scorm_cloud/registration_service.rb +++ b/lib/scorm_cloud/registration_service.rb @@ -1,9 +1,7 @@ module ScormCloud class RegistrationService < BaseService - not_implemented :get_registration_list_results, - :get_launch_history, :get_launch_info, :reset_global_objectives, - :update_learner_info, :test_registration_post_url + not_implemented :get_registration_list_results, :reset_global_objectives, :update_learner_info def create_registration(course_id, reg_id, first_name, last_name, learner_id, options = {}) params = options.merge({ @@ -29,7 +27,7 @@ def get_registration_list(options = {}) def get_registration_result(reg_id, format="course") raise "Illegal format argument: #{format}" unless ["course","activity","full"].include?(format) - connection.call_raw("rustici.registration.getRegistrationResult", { :regid => reg_id, :format => format }) + connection.call_raw("rustici.registration.getRegistrationResult", { :regid => reg_id, :resultsformat => format }) end def launch(reg_id, redirect_url, options = {}) @@ -44,6 +42,26 @@ def reset_registration(reg_id) xml = connection.call("rustici.registration.resetRegistration", {:regid => reg_id }) !xml.elements["/rsp/success"].nil? end + + def test_registration_post_url(postbackurl, urlname, urlpass, options ={}) + params = options.merge({ + :postbackurl => postbackurl, + :urlname => urlname, + :urlpass => urlpass + }) + xml = connection.call("rustici.registration.testRegistrationPostUrl", params) + !xml.elements["/rsp/success"].nil? + end + + def get_launch_info(launch_id) + xml = connection.call("rustici.registration.getLaunchInfo", {:launchid => launch_id }) + !xml.elements["/rsp/success"].nil? + end + + def get_launch_history(reg_id) + xml = connection.call("rustici.registration.getLaunchHistory", {:regid => reg_id }) + !xml.elements["/rsp/success"].nil? + end end diff --git a/readme.textile b/readme.textile index 863e2f4..79136da 100644 --- a/readme.textile +++ b/readme.textile @@ -25,10 +25,9 @@ bc. require 'scorm_cloud', :git => 'git@github.com:aeseducation/scorm-cloud.git' _Place the following in: config/initializers/scorm_cloud.rb_ bc. # Change MyApplication to the name of your application -MyApplication::Application.configure do |config| - config.scorm_cloud.appid = "my_app_id" - config.scorm_cloud.secretkey = "my_secret_key" -end +MyApplication::Application.config.scorm_cloud.appid = "my_app_id" +MyApplication::Application.config.scorm_cloud.secretkey = "my_secret_key" + _Place the following in: /app/controllers.course_controller.rb_ @@ -54,3 +53,13 @@ bq. # app/views/course/index.html.erb     </li> <% end %> </ul> + +_Uploading a course_ + +bc. # app/models/scorm_training.rb, using scorm_zip as a paperclip attachment in our upload form +def upload_to!(scorm_cloud) + path = scorm_cloud.upload.upload_file(scorm_cloud.upload.get_upload_token, self.scorm_zip.path) + scorm_cloud.course.import_course(self.scorm_course_id, path) +end + +