root/myexperiment-rest/trunk/lib/myexperiment-rest.rb @ 160

Revision 160, 2.1 KB (checked in by kostas.karasavvas@…, 3 years ago)

Renamed xml_uri to content_uri and added simple session cookie authentication

Line 
1require 'rubygems'
2require 'rest_client'
3
4require 'myexperiment-rest/constants'
5require 'myexperiment-rest/workflow'
6require 'myexperiment-rest/user'
7require 'myexperiment-rest/authentication'
8
9
10module MyExperimentREST
11
12 
13  # Get information from myExperiment using the REST API. Resources supported currently
14  # are +WORKFLOW_URL+"+ and +USER_URL+.
15  def self.get_myexperiment_data(resource_url, params)
16    case resource_url
17
18    when Urls::WORKFLOW_URL
19      begin
20        # Get workflow resource information -- if version is empty it returns the current version
21        if params[:session_cookie].empty?
22          response = RestClient.get("#{Urls::MYEXPERIMENT_URL}/#{Urls::WORKFLOW_URL}",
23                                           {:params => {'id' => "#{params[:id]}",
24                                                        'version' => "#{params[:version]}",
25                                                        'elements' => 'title,description,content-uri,components,uploader'} } )
26          response     
27        else    # TODO: reduce repetition.. if else only for the cookie key-value pair!!
28          response = RestClient.get("#{Urls::MYEXPERIMENT_URL}/#{Urls::WORKFLOW_URL}", 
29                                           {:params => {'id' => "#{params[:id]}",
30                                                        'version' => "#{params[:version]}",
31                                                        'elements' => 'title,description,content-uri,components,uploader'},
32                                            :cookies => params[:session_cookie] } )
33          response
34        end
35      rescue Exception => e
36        raise "REST call to acquire workflow resource failed!\n" + e
37      end
38
39    when Urls::USER_URL
40      begin
41        # Get user resource information
42        response = RestClient.get("#{Urls::MYEXPERIMENT_URL}/#{Urls::USER_URL}",
43                                         {:params => {'id' => "#{params[:id]}" } } )
44        response
45      rescue Exception => e
46        raise "REST call to acquire user resource failed!\n" + e
47      end
48
49    else
50      raise "This is not a supported resource type!\n"
51    end
52
53  end
54
55
56end
Note: See TracBrowser for help on using the browser.