sadi-rb 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 073f8686ffefb783f5d1833aae09bf542894ccf1
4
- data.tar.gz: 24326b372b6847239761400d6a9eff41088c4015
3
+ metadata.gz: ab2044de34253723c4b946f38ffd1aa6c05ecc4f
4
+ data.tar.gz: 0f6b13b3ee863ab5cf5fe751c4511f7ceacc44f0
5
5
  SHA512:
6
- metadata.gz: 7fe92760c66dd37064c00adcaed32059769062fd1edd6cdee245fa93752e5a4d823401c827ff1b17b6d0b22d308f10bfea13699a643513706475a39888515109
7
- data.tar.gz: cdb8922540ec0c35ff2184843f02d8c4357b681585b1db811fd81c7c14c9dcc43ede0bc9136e178a417a56ef22aac1d8ba9ad026279edc4ba61bb9c619b1becc
6
+ metadata.gz: 4282d1f8e806189166e83517603e57a4718d4a55e7d528c359f1e3b4778c10fdb107fc765a070e3faf336bd89e7790aa8eb5e0502844af1212e8a40a5f2b7d36
7
+ data.tar.gz: ba25e5a446f0229053c126cefbe0cc3b4caba059214f81efc0841d6d941b00566de933c164e4d6212e7390586ef4e29e70d4ca7d5af9367a715a738e0cae68d4
data/Gemfile CHANGED
@@ -18,4 +18,9 @@ end
18
18
 
19
19
  gem 'sinatra'
20
20
  gem 'sinatra-linkeddata'
21
+
21
22
  gem 'equivalent-xml', :require => false
23
+
24
+ platforms :ruby do
25
+ gem 'thin'
26
+ end
data/README.md CHANGED
@@ -1,10 +1,21 @@
1
1
  # sadi-rb
2
2
 
3
+ ### Installation
4
+ `gem install sadi-rb`
5
+
6
+ or clone the repository and run `rake install` for the latest version
7
+
8
+ ### Description
9
+
3
10
  Write [SADI] Services in Ruby, then host them as a Sinatra server
4
11
 
5
- Currently only supports synchronous services, and only a copy of the [demo service] has been implemented
12
+ Currently only supports [synchronous] service have been implemented.
13
+
14
+ ### Usage
6
15
 
7
- To try it, run the specs, or run
16
+ To test the server, use the gem's executable `sadi-rb`. This will start the server on [http://localhost:4567](http://localhost:4567), and load the [demo service].
17
+
18
+ The server can also be run as part of a script using
8
19
 
9
20
  ```ruby
10
21
  require 'sadi-rb'
@@ -12,7 +23,37 @@ require 'sadi-rb'
12
23
  SADI::Server.run!
13
24
  ```
14
25
 
15
- to run an instance of the demo service, at 'localhost:4567/services/hello'
26
+ ### Writing your own services
27
+
28
+ To create an asynchronous service, simply extend the `SADI::SynchronousService` module and implement the interface methods it requires;
29
+
30
+ ```ruby
31
+ require 'sadi-rb'
32
+
33
+ Class MyService
34
+ def service_name
35
+ "my_service_name"
36
+ end
37
+
38
+ def service_description
39
+ # an RDF::Graph of your service's description
40
+ end
41
+
42
+ def service_owl
43
+ # an RDF::Graph of your service's OWL classes
44
+ end
45
+
46
+ def process_object(input_graph, owl_object)
47
+ # Service logic goes here
48
+
49
+ # Should return an RDF::Graph of
50
+ # the output for the resource specified by the URI owl_object,
51
+ # from the RDF::Graph input_graph
52
+ end
53
+ end
54
+ ```
55
+
56
+ Although SADI can theoretically use any vocabulary for its service description, the gem internals currently require that you use the [mygrid ontology] in implementing your `service_description` method
16
57
 
17
58
  ## Contributing to sadi-rb
18
59
 
@@ -30,4 +71,5 @@ Copyright (c) 2013 Will Strinz. See LICENSE.txt for
30
71
  further details.
31
72
 
32
73
  [demo service]: http://sadiframework.org/content/how-sadi-works/synchronous-sadi-services/
33
- [SADI]: http://sadiframework.org
74
+ [SADI]: http://sadiframework.org
75
+ [mygrid ontology]: http://www.mygrid.org.uk/tools/service-management/mygrid-ontology/
data/Rakefile CHANGED
@@ -20,8 +20,9 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.summary = %Q{Build and run SADI services with ruby-rdf and sinatra}
21
21
  gem.description = %Q{Build and run SADI services with ruby-rdf and sinatra}
22
22
  gem.email = "wstrinz@gmail.com"
23
+ # gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
24
  gem.authors = ["Will Strinz"]
24
- gem.version = '0.0.1'
25
+ gem.version = '0.0.2'
25
26
  # dependencies defined in Gemfile
26
27
  end
27
28
  Jeweler::RubygemsDotOrgTasks.new
data/bin/sadi-rb ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/sadi-rb.rb'
3
+
4
+ SADI::Server.run!
@@ -6,6 +6,7 @@ module SADI
6
6
  raise "Unknown input format #{mime_type}" unless format
7
7
  format = format.to_sym
8
8
  end
9
+
9
10
  RDF::Graph.new << RDF::Reader.for(format).new(string)
10
11
  end
11
12
  end
@@ -1,6 +1,10 @@
1
1
  class ExampleService
2
2
  extend SADI::SynchronousService
3
3
  class << self
4
+ def service_name
5
+ "hello"
6
+ end
7
+
4
8
  def service_description
5
9
  str = <<-EOS
6
10
  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@@ -71,7 +75,6 @@ foaf:name a owl:DatatypeProperty;
71
75
  def process_object(in_graph, object)
72
76
  out_graph = RDF::Graph.new
73
77
 
74
- # obj = input_objects(in_graph).first
75
78
  name = RDF::Query.execute(in_graph) do
76
79
  pattern [object, RDF::FOAF.name, :name]
77
80
  end
@@ -5,8 +5,13 @@ module SADI
5
5
  class Server < Sinatra::Base
6
6
  register Sinatra::LinkedData
7
7
 
8
- get '/test' do
9
- "test success"
8
+ configure do
9
+ enable :inline_templates
10
+ end
11
+
12
+ get '/' do
13
+ # "This is a SADI "
14
+ haml :index
10
15
  end
11
16
 
12
17
  get '/services/:service' do
@@ -27,14 +32,47 @@ module SADI
27
32
  repo
28
33
  end
29
34
 
30
-
31
35
  def handle_synchronous(service)
32
- rdf_response ExampleService.process_input(request.body.read,request.content_type)
36
+ svc = SADI.service_for(service)
37
+ raise "no service exists with name '#{service}'" unless svc
38
+ rdf_response svc.process_input(request.body.read,request.content_type)
33
39
  end
34
40
 
35
41
  def get_description(service)
36
- ExampleService.service_description
42
+ svc = SADI.service_for(service)
43
+ raise "no service exists with name '#{service}'" unless svc
44
+ svc.service_description
45
+ end
46
+
47
+ def service_list
48
+ SADI.services.keys.map{|k| "<a href=\"/services/#{k}\"> #{k} </a>"}.join("<br>")
49
+ end
50
+
51
+ def format_list
52
+ RDF::Format.each.to_a.uniq{|f| f.content_type}
53
+ .reject{|f| f.content_type.size == 0}
54
+ .map{|f| "#{f.content_type} (#{f.to_sym})"}
55
+ .join('<br>')
37
56
  end
38
57
  end
39
58
  end
40
- end
59
+ end
60
+
61
+ __END__
62
+
63
+ @@ index
64
+ %h1
65
+ This is a
66
+ %a{href: 'http://sadiframework.org'} SADI
67
+ Server
68
+
69
+ %div
70
+ %strong Available services are: <br>
71
+ = service_list
72
+
73
+ %br
74
+ %br
75
+
76
+ %div
77
+ %strong Valid RDF formats are: <br>
78
+ = "#{format_list}"
@@ -0,0 +1,35 @@
1
+ module SADI
2
+ class << self
3
+
4
+ def service_for(name)
5
+ services[name]
6
+ end
7
+
8
+ def register_service(name, object)
9
+ services[name] = object
10
+ end
11
+
12
+ def services
13
+ @@services ||= {}
14
+ end
15
+
16
+ def reload_services
17
+ @@services = {}
18
+
19
+ SADI::SynchronousService.classes.each do |service|
20
+ if service.respond_to? 'service_name'
21
+ name = service.service_name
22
+ puts "Warning: service #{@@services[name]} already using name '#{name}', overwriting" if @@services[name]
23
+ @@services[name] = service
24
+ elsif service.instance_methods.include? :service_name
25
+ service = service.new
26
+ name = service.service_name
27
+ puts "Warning: service #{@@services[name]} already using name '#{name}', overwriting" if @@services[name]
28
+ @@services[name] = service
29
+ else
30
+ raise "service #{service} does not define a proper interface"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,6 +2,20 @@ module SADI
2
2
  module SynchronousService
3
3
  include SADI::Converter
4
4
 
5
+ def self.included(base)
6
+ @classes ||= []
7
+ @classes << base
8
+ end
9
+
10
+ def self.extended(base)
11
+ @classes ||= []
12
+ @classes << base
13
+ end
14
+
15
+ def self.classes
16
+ @classes
17
+ end
18
+
5
19
  def process_input(input, format)
6
20
  gr = RDF::Graph.new
7
21
  in_graph = parse_string(input,format)
@@ -54,5 +68,9 @@ module SADI
54
68
  def process_object(owl_graph, object)
55
69
  raise "Must implement a #process_input that takes an RDF::Graph or Repository as input and returns a new one"
56
70
  end
71
+
72
+ def service_name
73
+ raise "Must define a service name"
74
+ end
57
75
  end
58
76
  end
data/lib/sadi-rb.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require_relative 'sadi-rb/server.rb'
2
2
  require_relative 'sadi-rb/converter.rb'
3
3
  require_relative 'sadi-rb/synchronous_service.rb'
4
+ require_relative 'sadi-rb/services.rb'
5
+
4
6
  require_relative 'sadi-rb/example_service.rb'
7
+
8
+ SADI.reload_services
data/sadi-rb.gemspec ADDED
@@ -0,0 +1,84 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sadi-rb"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Will Strinz"]
12
+ s.date = "2013-10-15"
13
+ s.description = "Build and run SADI services with ruby-rdf and sinatra"
14
+ s.email = "wstrinz@gmail.com"
15
+ s.executables = ["sadi-rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "bin/sadi-rb",
27
+ "lib/sadi-rb.rb",
28
+ "lib/sadi-rb/converter.rb",
29
+ "lib/sadi-rb/example_service.rb",
30
+ "lib/sadi-rb/server.rb",
31
+ "lib/sadi-rb/services.rb",
32
+ "lib/sadi-rb/synchronous_service.rb",
33
+ "sadi-rb.gemspec",
34
+ "spec/server_spec.rb"
35
+ ]
36
+ s.homepage = "http://github.com/wstrinz/sadi-rb"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "2.0.3"
40
+ s.summary = "Build and run SADI services with ruby-rdf and sinatra"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 4
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
47
+ s.add_runtime_dependency(%q<sinatra-linkeddata>, [">= 0"])
48
+ s.add_runtime_dependency(%q<equivalent-xml>, [">= 0"])
49
+ s.add_runtime_dependency(%q<thin>, [">= 0"])
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
54
+ s.add_development_dependency(%q<rspec>, [">= 0"])
55
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
56
+ s.add_development_dependency(%q<pry>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<sinatra>, [">= 0"])
59
+ s.add_dependency(%q<sinatra-linkeddata>, [">= 0"])
60
+ s.add_dependency(%q<equivalent-xml>, [">= 0"])
61
+ s.add_dependency(%q<thin>, [">= 0"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
66
+ s.add_dependency(%q<rspec>, [">= 0"])
67
+ s.add_dependency(%q<rack-test>, [">= 0"])
68
+ s.add_dependency(%q<pry>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<sinatra>, [">= 0"])
72
+ s.add_dependency(%q<sinatra-linkeddata>, [">= 0"])
73
+ s.add_dependency(%q<equivalent-xml>, [">= 0"])
74
+ s.add_dependency(%q<thin>, [">= 0"])
75
+ s.add_dependency(%q<shoulda>, [">= 0"])
76
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
77
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
78
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
79
+ s.add_dependency(%q<rspec>, [">= 0"])
80
+ s.add_dependency(%q<rack-test>, [">= 0"])
81
+ s.add_dependency(%q<pry>, [">= 0"])
82
+ end
83
+ end
84
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sadi-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Strinz
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: shoulda
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +166,8 @@ dependencies:
152
166
  version: '0'
153
167
  description: Build and run SADI services with ruby-rdf and sinatra
154
168
  email: wstrinz@gmail.com
155
- executables: []
169
+ executables:
170
+ - sadi-rb
156
171
  extensions: []
157
172
  extra_rdoc_files:
158
173
  - LICENSE.txt
@@ -163,11 +178,14 @@ files:
163
178
  - LICENSE.txt
164
179
  - README.md
165
180
  - Rakefile
181
+ - bin/sadi-rb
166
182
  - lib/sadi-rb.rb
167
183
  - lib/sadi-rb/converter.rb
168
184
  - lib/sadi-rb/example_service.rb
169
185
  - lib/sadi-rb/server.rb
186
+ - lib/sadi-rb/services.rb
170
187
  - lib/sadi-rb/synchronous_service.rb
188
+ - sadi-rb.gemspec
171
189
  - spec/server_spec.rb
172
190
  homepage: http://github.com/wstrinz/sadi-rb
173
191
  licenses: