-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest-plos.rb
61 lines (51 loc) · 1.93 KB
/
test-plos.rb
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
require "test/unit"
require "multi_json"
require "faraday"
require "faraday_middleware"
class TestPlos < Test::Unit::TestCase
def setup
@doi = "10.1371/journal.pgen.1006546"
@plos = MultiJson.load(File.open('src/plos.json'))
end
def test_plos_keys
assert_equal(
@plos.keys().sort(),
["components", "cookies","crossref_member", "journals", "open_access",
"prefixes", "publisher", "publisher_parent", "regex", "urls", "use_crossref_links"]
)
assert_nil(@plos['urls'])
assert_not_nil(@plos['journals'])
end
def test_plos_xml
conndoi = Faraday.new(:url => 'http://api.crossref.org/works/%s' % @doi) do |f|
f.adapter Faraday.default_adapter
end
issn = MultiJson.load(conndoi.get.body)['message']['ISSN'][0]
conn = Faraday.new(
:url => @plos['journals'].select { |x| x['issn'].include? issn }[0]['urls']['xml'] %
@doi.match(@plos['journals'][0]['components']['doi']['regex']).to_s) do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 3
f.adapter Faraday.default_adapter
end
res = conn.get;
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
assert_equal("application/xml", res.headers['content-type'])
end
def test_plos_pdf
conndoi = Faraday.new(:url => 'http://api.crossref.org/works/%s' % @doi) do |f|
f.adapter Faraday.default_adapter
end
issn = MultiJson.load(conndoi.get.body)['message']['ISSN'][0]
conn = Faraday.new(
:url => @plos['journals'].select { |x| x['issn'].include? issn }[0]['urls']['pdf'] %
@doi.match(@plos['journals'][0]['components']['doi']['regex']).to_s) do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 3
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
assert_equal("application/pdf", res.headers['content-type'])
end
end