-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
87 lines (87 loc) · 9.11 KB
/
Copy pathindex.html
File metadata and controls
87 lines (87 loc) · 9.11 KB
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
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>crossrefapi</title>
<link rel="stylesheet" href="https://caltechlibrary.github.io/css/site.css">
<link rel="stylesheet" href="https://media.library.caltech.edu/cl-webcomponents/css/code-blocks.css">
<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/copyToClipboard.js"></script>
<script type="module" src="https://media.library.caltech.edu/cl-webcomponents/footer-global.js"></script>
</head>
<body>
<header>
<a href="https://library.caltech.edu"><img src="https://media.library.caltech.edu/assets/caltechlibrary-logo.png" alt="Caltech Library logo"></a>
</header>
<a href="#main-content" class="visually-hidden">skip to main content</a>
<nav>
<ul>
<li><a href="/">All Library Apps</a></li>
<li><a href="index.html">Home</a></li>
<li><a href="LICENSE">LICENSE</a></li>
<li><a href="INSTALL.html">INSTALL</a></li>
<li><a href="user_manual.html">User Manual</a></li>
<li><a href="about.html">About</a></li>
<!-- <li><a href="search.html">Search</a></li> -->
<li><a href="https://github.com/caltechlibrary/crossrefapi">Code Repository</a></li>
</ul>
</nav>
<section id="main-content">
<h1 id="crossrefapi">crossrefapi</h1>
<p>This is a go package for working with the Crossref API. It is
inspired by the an excellent CrossRefAPI Python package listed in the
Crossref API docs. This package is meant to follow the “polite”
guidelines for interacting with the public API at api.crossref.org.</p>
<h2 id="go-package-example">Go package example</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> appName <span class="op">:=</span> path<span class="op">.</span>Base<span class="op">(</span>os<span class="op">.</span>Args<span class="op">[</span><span class="dv">0</span><span class="op">])</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> client<span class="op">,</span> err <span class="op">:=</span> crossrefapi<span class="op">.</span>NewCrossRefClient<span class="op">(</span>appName<span class="op">,</span> <span class="st">"jane.doe@library.example.edu"</span><span class="op">)</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> works<span class="op">,</span> err <span class="op">:=</span> client<span class="op">.</span>Works<span class="op">(</span><span class="st">"10.1037/0003-066x.59.1.29"</span><span class="op">)</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="co">// continue processing your "works" result...</span></span></code></pre></div>
<p>You can compare two copies of a “works” response and see what has
changed.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> appName <span class="op">:=</span> path<span class="op">.</span>Base<span class="op">(</span>os<span class="op">.</span>Args<span class="op">[</span><span class="dv">0</span><span class="op">])</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> client<span class="op">,</span> err <span class="op">:=</span> crossrefapi<span class="op">.</span>NewCrossRefClient<span class="op">(</span>appName<span class="op">,</span> <span class="st">"jane.doe@library.example.edu"</span><span class="op">)</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> newWorks<span class="op">,</span> err <span class="op">:=</span> client<span class="op">.</span>Works<span class="op">(</span><span class="st">"10.1037/0003-066x.59.1.29"</span><span class="op">)</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="co">// Fetch our previously saved works document.</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> src<span class="op">,</span> err <span class="op">:=</span> os<span class="op">.</span>ReadFile<span class="op">(</span><span class="st">"0003-066x.59.1.29.json"</span><span class="op">)</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a> oldWorks <span class="op">:=</span> <span class="bu">new</span><span class="op">(</span>crossrefapi<span class="op">.</span>Works<span class="op">)</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">:=</span> json<span class="op">.</span>Unmarshal<span class="op">(</span>src<span class="op">,</span> <span class="op">&</span>oldWorks<span class="op">);</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a> src<span class="op">,</span> err <span class="op">=</span> oldWorks<span class="op">.</span>DiffAsJSON<span class="op">(</span>newWorks<span class="op">)</span></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> err <span class="op">!=</span> <span class="ot">nil</span> <span class="op">{</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a> <span class="co">// handle error...</span></span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a> fmt<span class="op">.</span>Println<span class="op">(</span><span class="st">"Diff for 10.1037/0003-066x.59.1.29"</span><span class="op">)</span></span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a> fmt<span class="op">.</span>Printf<span class="op">(</span><span class="st">"</span><span class="ch">\n</span><span class="st">%s</span><span class="ch">\n</span><span class="st">"</span><span class="op">,</span> src<span class="op">)</span></span></code></pre></div>
<h2 id="command-line-example">Command line example</h2>
<pre><code> crossrefapi -mailto="jane.doe@library.example.edu" works "10.1037/0003-066x.59.1.29"</code></pre>
<h2 id="reference">Reference</h2>
<ul>
<li><a href="https://api.crossref.org/">Crossref API Docs</a></li>
<li><a
href="https://www.crossref.org/documentation/schema-library/">Crossref
Schemas</a></li>
<li><a
href="https://github.com/fabiobatalha/crossrefapi">CrossRefAPI</a> -
Python implementation</li>
</ul>
</section>
<footer-global></footer-global>
</body>
</html>