-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQUASHED: AUTO-COMMIT-src-client-literature.js,AUTO-COMMIT-src-client-preferences.js,AUTO-COMMIT-src-client-protocols-alex.js,AUTO-COMMIT-src-client-protocols-scholar.js,AUTO-COMMIT-src-components-tools-lively-generic-search.js,AUTO-COMMIT-test-client-literature-alex-example.js,AUTO-COMMIT-test-client-literature-alex-work-example.js,AUTO-COMMIT-test-client-literature-alex-work-example.json,AUTO-COMMIT-test-client-literature-test.js,
- Loading branch information
1 parent
3d6d611
commit 71de294
Showing
7 changed files
with
1,958 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { Scheme } from "src/client/poid.js"; | ||
import PolymorphicIdentifier from "src/client/poid.js"; | ||
import focalStorage from "src/external/focalStorage.js"; | ||
|
||
import {Author, Paper} from "src/client/literature.js" | ||
|
||
import Preferences from 'src/client/preferences.js'; | ||
|
||
|
||
import _ from 'src/external/lodash/lodash.js'; | ||
/*MD | ||
# Alex Scholar API | ||
MD*/`` | ||
|
||
|
||
export default class OpenAlexScheme extends Scheme { | ||
|
||
get scheme() { | ||
return "alex"; | ||
} | ||
|
||
resolve() { | ||
return true; | ||
} | ||
|
||
response(content, contentType = "text/html") { | ||
return new Response(content, { | ||
headers: { | ||
"content-type": contentType | ||
}, | ||
status: 200 | ||
}); | ||
} | ||
|
||
notfound(content, contentType = "text/html") { | ||
return new Response(content, { | ||
headers: { | ||
"content-type": contentType | ||
}, | ||
status: 303 | ||
}); | ||
} | ||
|
||
|
||
get baseURL() { | ||
return "https://api.openalex.org/" | ||
} | ||
|
||
|
||
async GET(options) { | ||
var m = this.url.match(new RegExp(this.scheme + "\:\/\/([^/]*)/(.*)")) | ||
var mode = m[1] | ||
var query = m[2]; | ||
if (query.length < 2) return this.response(`{"error": "query to short"}`); | ||
|
||
if (mode === "browse") { | ||
if (query.match("work/")) { | ||
let id = query.replace(/paper\//,"") | ||
return this.response(`<literature-paper openalexid="${id}"><literature-paper>`); | ||
} else { | ||
return this.response(`query not supported: ` + query); | ||
} | ||
} | ||
|
||
var url = this.baseURL + query | ||
|
||
var headers = new Headers({}) | ||
var content = await fetch(url, { | ||
method: "GET", | ||
headers: headers | ||
}).then(r => r.text()) | ||
|
||
return this.response(content); | ||
} | ||
|
||
async POST(options) { | ||
// #TODO get rid of duplication with GET | ||
var m = this.url.match(new RegExp(this.scheme + "\:\/\/([^/]*)/(.*)")) | ||
var mode = m[1] | ||
var query = m[2]; | ||
if (query.length < 2) return this.response(`{"error": "query to short"}`); | ||
|
||
var url = this.baseURL + query | ||
|
||
|
||
var headers = new Headers({}) | ||
var content = await fetch(url, { | ||
method: "POST", | ||
headers: headers, | ||
body: options.body | ||
}).then(r => r.text()) | ||
|
||
return this.response(content); | ||
} | ||
|
||
|
||
async OPTIONS(options) { | ||
var content = JSON.stringify({}, undefined, 2); | ||
return new Response(content, { | ||
headers: { | ||
"content-type": "application/json" | ||
}, | ||
status: 200 | ||
}); | ||
} | ||
|
||
} | ||
|
||
PolymorphicIdentifier.register(OpenAlexScheme); | ||
|
||
// import Tracing from "src/client/tracing.js" | ||
// Tracing.traceClass(Paper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.