myexperiment-rest 0.2.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ require 'libxml'
2
+
3
+ module MyExperimentREST
4
+
5
+ #
6
+ # Connects to myExperiment REST API and creates a _MyExperimentWorkflow_ object.
7
+ #
8
+ class Workflow
9
+
10
+ # Returns a _MyExperimentWorkflow_ object given a URI of the workflow in the repository as a String.
11
+ def self.from_uri(uri)
12
+
13
+ workflow_id = ''
14
+ workflow_version = ''
15
+
16
+ # Get workflow id - will match both workflow/74 and workflows.xml?id=74
17
+ uri_id = uri.match(/workflow.*[\/?](id=)?(\d+)/)
18
+ if uri_id != nil
19
+ workflow_id = uri_id[2]
20
+ else
21
+ raise "Could not match workflow id."
22
+ end
23
+
24
+ # Get workflow version if it exists
25
+ uri_version = uri.match(/version=(\d+)/)
26
+ if uri_version != nil
27
+ workflow_version = uri_version[1]
28
+ end
29
+
30
+ # Get workflow resource information
31
+ xml = MyExperimentREST.get_myexperiment_data(Urls::WORKFLOW_URL, :id => workflow_id, :version => workflow_version)
32
+
33
+ MyExperimentWorkflow.parse(xml)
34
+ end
35
+
36
+
37
+ # Returns a _MyExperimentWorkflow_ object given a myExperiment id and version for that workflow.
38
+ def self.from_id_and_version(id, version='')
39
+
40
+ # Get workflow resource information
41
+ xml = MyExperimentREST.get_myexperiment_data(Urls::WORKFLOW_URL, :id => id, :version => version)
42
+
43
+ MyExperimentWorkflow.parse(xml)
44
+ end
45
+
46
+
47
+ end # class Workflow
48
+
49
+
50
+
51
+ #
52
+ # Contains all available information about a workflow: _xml_uri_,
53
+ # _title_, _description_,_inputs_, _outputs_ and _uploader_uri_. The _xml_uri_
54
+ # specifies the XML description on myExperiment and not the XML of the workflow
55
+ # itself.
56
+ #
57
+ class MyExperimentWorkflow
58
+
59
+ attr_reader(:xml_uri, :title, :description, :inputs, :outputs, :uploader_uri)
60
+
61
+ def initialize(attributes)
62
+ @xml_uri = attributes[:xml_uri]
63
+ @title = attributes[:title]
64
+ @description = attributes[:description]
65
+ @inputs = attributes[:inputs]
66
+ @outputs = attributes[:outputs]
67
+ @uploader_uri = attributes[:uploader_uri]
68
+ end
69
+
70
+ # Parse workflow information XML and instantiate a _MyExperimentWorkflow_ object
71
+ def self.parse(xml)
72
+
73
+ wkf_inputs = []
74
+ wkf_outputs = []
75
+
76
+ doc = LibXML::XML::Document.string(xml)
77
+
78
+ doc.find("//workflow/components/dataflows/dataflow[@role='top']/sources/source").each do |element|
79
+ wkf_inputs << MyExperimentIOData.from_xml(element)
80
+ end
81
+
82
+ doc.find("//workflow/components/dataflows/dataflow[@role='top']/sinks/sink").each do |element|
83
+ wkf_outputs << MyExperimentIOData.from_xml(element)
84
+ end
85
+
86
+
87
+ new(:xml_uri => doc.find_first("/workflow/content-uri").content,
88
+ :title => doc.find_first("/workflow/title").content,
89
+ :description => doc.find_first("/workflow/description").content,
90
+ :inputs => wkf_inputs,
91
+ :outputs => wkf_outputs,
92
+ :uploader_uri => doc.find_first("/workflow/uploader").attributes['uri'])
93
+
94
+ end
95
+
96
+ end
97
+
98
+
99
+ #
100
+ # Contains all available information about an input or output: name, descriptions
101
+ # and examples. The last two are lists.
102
+ #--
103
+ # Currently both inputs and outputs contain the same information. If that
104
+ # changes we can subclass this one.
105
+ #
106
+ class MyExperimentIOData
107
+ attr_reader(:name, :descriptions, :examples)
108
+
109
+ def initialize(attributes)
110
+ @name = attributes[:name]
111
+ @descriptions = attributes[:descriptions]
112
+ @examples = attributes[:examples]
113
+ end
114
+
115
+ def self.from_xml(xml_node)
116
+ name = ''
117
+ descriptions = []
118
+ examples = []
119
+
120
+ xml_node.each_element do |n|
121
+ if n.name.eql? "name"
122
+ name = n.children[0].to_s
123
+ elsif n.name.eql? "descriptions"
124
+ n.each_element do |d|
125
+ descriptions << d.children[0].to_s
126
+ end if n.children?
127
+ elsif n.name.eql? "examples"
128
+ n.each_element do |e|
129
+ examples << e.children[0].to_s
130
+ end if n.children?
131
+ end
132
+ end
133
+
134
+
135
+ new(
136
+ :name => name,
137
+ :descriptions => descriptions,
138
+ :examples => examples)
139
+
140
+ end
141
+
142
+ end # class MyExperimentIOData
143
+
144
+ end # module
145
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myexperiment-rest
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 8
10
- version: 0.2.8
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Konstantinos Karasavvas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-19 00:00:00 Z
18
+ date: 2011-09-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 5
44
+ hash: 29
45
45
  segments:
46
46
  - 2
47
47
  - 0
48
- - 5
49
- version: 2.0.5
48
+ - 9
49
+ version: 2.0.9
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  description: This is a simple library to access data on myExperiment via its REST API. Currently supports a subset of the workflow information available.
@@ -66,7 +66,9 @@ files:
66
66
  - Rakefile
67
67
  - bin/get_workflow_data.rb
68
68
  - lib/myexperiment-rest.rb
69
- - lib/myexperiment-rest/myexperiment_rest.rb
69
+ - lib/myexperiment-rest/workflow.rb
70
+ - lib/myexperiment-rest/user.rb
71
+ - lib/myexperiment-rest/constants.rb
70
72
  - doc/rdoc/rdoc.css
71
73
  - doc/rdoc/LICENSE.html
72
74
  - doc/rdoc/index.html
@@ -76,7 +78,9 @@ files:
76
78
  - doc/rdoc/js/quicksearch.js
77
79
  - doc/rdoc/MyExperimentREST.html
78
80
  - doc/rdoc/README.html
79
- - doc/rdoc/lib/myexperiment-rest/myexperiment_rest_rb.html
81
+ - doc/rdoc/lib/myexperiment-rest/constants_rb.html
82
+ - doc/rdoc/lib/myexperiment-rest/user_rb.html
83
+ - doc/rdoc/lib/myexperiment-rest/workflow_rb.html
80
84
  - doc/rdoc/lib/myexperiment-rest_rb.html
81
85
  - doc/rdoc/created.rid
82
86
  - doc/rdoc/CHANGES.html
@@ -100,10 +104,12 @@ files:
100
104
  - doc/rdoc/images/page_white_width.png
101
105
  - doc/rdoc/images/package.png
102
106
  - doc/rdoc/images/plugin.png
103
- - doc/rdoc/MyExperimentREST/TavernaUser.html
104
- - doc/rdoc/MyExperimentREST/TavernaIOData.html
105
- - doc/rdoc/MyExperimentREST/Workflows.html
106
- - doc/rdoc/MyExperimentREST/TavernaWorkflow.html
107
+ - doc/rdoc/MyExperimentREST/User.html
108
+ - doc/rdoc/MyExperimentREST/Urls.html
109
+ - doc/rdoc/MyExperimentREST/MyExperimentWorkflow.html
110
+ - doc/rdoc/MyExperimentREST/MyExperimentUser.html
111
+ - doc/rdoc/MyExperimentREST/MyExperimentIOData.html
112
+ - doc/rdoc/MyExperimentREST/Workflow.html
107
113
  homepage:
108
114
  licenses: []
109
115
 
@@ -136,6 +142,6 @@ rubyforge_project:
136
142
  rubygems_version: 1.7.2
137
143
  signing_key:
138
144
  specification_version: 3
139
- summary: This is a simple library to access data on myExperiment via its REST API. Currently supports a subset of the workflow information available.
145
+ summary: This is a simple library to access data on myExperiment via its REST API.
140
146
  test_files: []
141
147
 
@@ -1,190 +0,0 @@
1
- require 'rubygems'
2
- require 'rest_client'
3
- require 'open-uri'
4
- require 'libxml'
5
-
6
- module MyExperimentREST
7
-
8
- #
9
- # Connects to myExperiment REST API and creates a _TavernaWorkflow_ object.
10
- #
11
- class Workflows
12
- include LibXML
13
-
14
- attr_reader(:uri)
15
-
16
- #def initialize
17
- #end
18
-
19
- # Requires the URI of the workflow in the repository as a String.
20
- def read(uri)
21
-
22
- workflow_id = ''
23
- workflow_version = ''
24
-
25
- # Get workflow id
26
- uri_id = uri.match(/workflows\/(\d+)/)
27
- if uri_id != nil
28
- workflow_id = uri_id[1]
29
- else
30
- raise "Could not match workflow id."
31
- end
32
-
33
- # Get workflow version if it exists
34
- uri_version = uri.match(/version=(\d+)/)
35
- if uri_version != nil
36
- workflow_version = uri_version[1]
37
- end
38
-
39
- # Get workflow resource information -- if version is empty it returns the current version
40
- response = RestClient.get('http://www.myexperiment.org/workflow.xml', {:params => {'id' => "#{workflow_id}",
41
- 'version' => "#{workflow_version}",
42
- 'elements' => 'title,description,content-uri,components,uploader'} } )
43
-
44
- populate_workflow(response)
45
- end
46
-
47
-
48
- private
49
-
50
- # Acquire data from XML response and instantiate a _Taverna_Workflow_ object
51
- #--
52
- # TODO: refactor so that each (logical) workflow element is an object with
53
- # its own read from_xml method...
54
- def populate_workflow(response)
55
- doc = XML::Document.string(response)
56
- wkf_xml_uri = doc.find_first("/workflow/content-uri").content
57
- wkf_title = doc.find_first("/workflow/title").content
58
- wkf_descr = doc.find_first("/workflow/description").content
59
- wkf_inputs = get_IOData(doc, "source")
60
- wkf_outputs = get_IOData(doc, "sink")
61
- wkf_user = get_user(doc.find_first("/workflow/uploader").attributes['uri'])
62
-
63
- TavernaWorkflow.new(TavernaWorkflow::MY_EXPERIMENT, wkf_xml_uri, wkf_title, wkf_descr, wkf_inputs, wkf_outputs, wkf_user)
64
-
65
- end
66
-
67
-
68
- #
69
- # Populate _TavernaIOData_ objects for specified type: value +source+'+ is for inputs
70
- # and +sink+ for outputs
71
- #
72
- def get_IOData(doc, type)
73
- io_data = []
74
-
75
- # Get all sources or sinks and create appropriate objects
76
- doc.find("//workflow/components/dataflows/dataflow[@role='top']/#{type}s/#{type}").each do |node|
77
- name = ''
78
- descriptions = []
79
- examples = []
80
-
81
- node.each_element do |n|
82
- if n.name.eql? "name"
83
- name = n.children[0].to_s
84
- elsif n.name.eql? "descriptions"
85
- n.each_element do |d|
86
- descriptions << d.children[0].to_s
87
- end if n.children?
88
- elsif n.name.eql? "examples"
89
- n.each_element do |e|
90
- examples << e.children[0].to_s
91
- end if n.children?
92
- end
93
- end
94
-
95
- io_data << TavernaIOData.new(name, descriptions, examples)
96
- end
97
-
98
- io_data
99
- end
100
-
101
-
102
- #
103
- # Populate _TavernaUser_ object for specified user resource
104
- #
105
- def get_user(user_uri)
106
- doc = XML::Document.file(user_uri)
107
- user = TavernaUser.new(doc.find_first("/user/name").content,
108
- doc.find_first("/user/description").content,
109
- doc.find_first("/user/email").content,
110
- doc.find_first("/user/avatar").attributes['uri'],
111
- doc.find_first("/user/website").content,
112
- doc.find_first("/user/created-at").content)
113
- user
114
- end
115
-
116
-
117
-
118
- end
119
-
120
-
121
-
122
- #
123
- # Contains all available information about a workflow: _input_type_, _xml_uri_,
124
- # _title_, _description_,_inputs_, _outputs_ and _user_. The _xml_uri_ specifies
125
- # the XML description on myExperiment and not the XML of the workflow itself.
126
- # _input_type_ specifies the kind of input. Currently, either "myexperiment"
127
- # (myExperiment's xml uri) or "t2flow" (filename)
128
- #
129
- class TavernaWorkflow
130
-
131
- # possible input types
132
- MY_EXPERIMENT = 'myexperiment'
133
- T2_FLOW = 't2flow'
134
-
135
- attr_reader(:input_type, :xml_uri, :title, :description, :inputs, :outputs, :user)
136
-
137
- def initialize(input_type, xml_uri, title, description, inputs, outputs, user)
138
- @input_type = input_type
139
- @xml_uri = xml_uri
140
- @title = title
141
- @description = description
142
- @inputs = inputs
143
- @outputs = outputs
144
- @user = user
145
- end
146
-
147
- end
148
-
149
-
150
- #
151
- # Contains all available information about an input or output: name, descriptions
152
- # and examples. The last two are lists.
153
- #--
154
- # Currently both inputs and outputs contain the same information. If that
155
- # changes we can subclass this one.
156
- #
157
- class TavernaIOData
158
- attr_reader(:name, :descriptions, :examples)
159
-
160
- def initialize(name, descriptions, examples)
161
- @name = name
162
- @descriptions = descriptions
163
- @examples = examples
164
- end
165
-
166
- end
167
-
168
-
169
- #
170
- # Contains all available information about an input or output: name, descriptions
171
- # and examples. The last two are lists.
172
- #
173
- class TavernaUser
174
- attr_reader(:name, :description, :email, :avatar, :website, :created_at)
175
-
176
- def initialize(name, description, email, avatar, website, created_at)
177
- @name = name
178
- @description = description
179
- @email = email
180
- @avatar = avatar
181
- @website = website
182
- @created_at = created_at
183
- end
184
-
185
- end
186
-
187
-
188
-
189
- end
190
-