Skip to content

Commit c60a4a9

Browse files
committed
Merge branch 'master' of github.com:ElixirUK/TeSS_api_client
2 parents d980944 + 471262f commit c60a4a9

38 files changed

Lines changed: 1447 additions & 835 deletions

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ content_provider = ContentProvider.new(
1919
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/2000px-Smiley.svg.png",
2020
"We're sharing our content with TeSS!"
2121
)
22-
content_provider = Uploader.create_or_update_content_provider(content_provider)
22+
23+
content_provider.create_or_update
2324

2425
material = Material.new(title: 'How to use TeSS API',
2526
url: 'http://mysite.org/tess_api',
@@ -31,7 +32,7 @@ material = Material.new(title: 'How to use TeSS API',
3132
scientific_topic: ['Computational Biology'],
3233
keywords: ['tutorial', 'TeSS', 'sharing'])
3334

34-
Uploader.create_or_update_material(upload_material)
35+
material.create
3536
```
3637

3738
If a website has schema.org content embedded in either RDFa or Microdata formats you can extract it easily. First convert it to RDF, and then use the RdfaExtractor library to parse it.

lib/content_provider.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/material.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/node.rb

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib/rdfa_extractor.rb

Lines changed: 0 additions & 109 deletions
This file was deleted.

lib/resource.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

lib/scraper_config.rb

Lines changed: 0 additions & 46 deletions
This file was deleted.

lib/tess/api/api_resource.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module Tess
2+
module API
3+
module ApiResource
4+
5+
attr_accessor :last_action, :errors
6+
7+
def create
8+
begin
9+
response = Uploader.do_upload(self, true, self.class.data_type, "/#{self.class.resource_path}.json", :post)
10+
self.id = response['id']
11+
self.last_action = :create
12+
rescue RestClient::ExceptionWithResponse => e
13+
self.errors = error_message(e)
14+
end
15+
16+
self
17+
end
18+
19+
def update
20+
begin
21+
Uploader.do_upload(self, true, self.class.data_type, "/#{self.class.resource_path}/#{self.id}.json", :put)
22+
self.last_action = :update
23+
rescue RestClient::ExceptionWithResponse => e
24+
self.errors = error_message(e)
25+
end
26+
27+
self
28+
end
29+
30+
def create_or_update
31+
if exists?
32+
update
33+
else
34+
create
35+
end
36+
end
37+
38+
def find_or_create
39+
create unless exists?
40+
41+
self
42+
end
43+
44+
def exists?
45+
response = Uploader.do_upload(self, false, self.class.data_type, "/#{self.class.resource_path}/check_exists.json", :post)
46+
self.id = response['id']
47+
48+
!response['id'].nil?
49+
end
50+
51+
private
52+
53+
def error_message(exception)
54+
begin
55+
JSON.parse(exception.response)
56+
rescue JSON::ParserError
57+
{ error_message: exception }
58+
end
59+
end
60+
61+
end
62+
end
63+
end

lib/tess/api/content_provider.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Tess
2+
module API
3+
class ContentProvider < Resource
4+
5+
include ApiResource
6+
7+
def self.data_type
8+
:content_provider
9+
end
10+
11+
def self.resource_path
12+
'content_providers'
13+
end
14+
15+
attr_accessor :title, :url, :image_url, :description, :id, :content_provider_type, :node_name, :keywords
16+
17+
PROVIDER_TYPE = {
18+
organisation: 'Organisation',
19+
portal: 'Portal',
20+
project: 'Project'
21+
}
22+
23+
cv_attributes({ content_provider_type: PROVIDER_TYPE, node_name: Tess::API::Node::NODE_NAMES })
24+
25+
def initialize(params = {})
26+
params[:content_provider_type] ||= :organisation
27+
params[:node_name] ||= params.delete(:node)
28+
29+
super
30+
end
31+
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)