/
SOURCES
96 lines (76 loc) · 3.25 KB
/
SOURCES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!--
$HeadURL$
$Id$
Copyright (c) 2009-2010 by Public Library of Science, a non-profit corporation
http://www.plos.org/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
# Sources
## Overview
ALM has a set of default sources that ship with the application, but it's
simple to add your own sources.
### Executive Summary
Here's a minimal example of a new source.
# app/models/sources/new_source.rb
require 'open-uri'
class NewSource < Source
def perform_query(article, options)
citations = JSON.parse open("http://mydoicite/#{CGI.escape article.doi}/citations.json")
citations.each { |citation| citation[:uri] = citation.delete('url') }
end
end
### Detailed Walkthrough
1. add `new_source.rb` to the `app/models/sources` directory
2. create a ruby class for the new source
class NewSource < Source
end
3. implement the `perform_query` method
class NewSource < Source
# perform_query must fetch the article from the external source
# and return an array of one hash for each citation. Each hash
# must include a :uri attribute, which uniquely identifies the
# citation. Other attributes in the hash are stored in the
# details field of the citation record, for later CSV export.
# article - article model instance for the article to cite check
# options - a hash of two values
# :retrieval - the current retrieval model instance for the query
# :timeout - the timeout (in seconds) for the query
def perform_query(article, options)
# do stuff here, for example:
require 'open-uri'
citations = JSON.parse open("http://mydoicite/#{CGI.escape article.doi}/citations.json")
citations.each { |citation| citation[:uri] = citation.delete('url') }
end
end
4. (optional) override `uses_` fields to enable source configuration in the ui
class NewSource < Source
def perform_query
# do stuff (see sample implementation above)
end
# Subclasses should override these to cause fields to appear in UI, and
# enable their validations
def uses_url; true end
def uses_search_url; true end
def uses_username; true end
def uses_password; true end
def uses_live_mode; true end
def uses_salt; true end
def uses_partner_id; true; end
end
5. (optional) override the `public_url_base` and possibly the `public_url` methods
class NewSource < Source
def perform_query; end
def public_url_base
'http://mydoicite/'
end
end
### Other Examples
See the code in `app/models/sources/` for more examples.