orcid_client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +10 -0
- data/.gitignore +42 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +115 -0
- data/LICENSE.md +21 -0
- data/README.md +45 -0
- data/Rakefile +5 -0
- data/lib/orcid_client.rb +3 -0
- data/lib/orcid_client/api.rb +75 -0
- data/lib/orcid_client/author.rb +56 -0
- data/lib/orcid_client/base.rb +21 -0
- data/lib/orcid_client/date.rb +61 -0
- data/lib/orcid_client/metadata.rb +128 -0
- data/lib/orcid_client/notification.rb +125 -0
- data/lib/orcid_client/version.rb +3 -0
- data/lib/orcid_client/work.rb +200 -0
- data/lib/orcid_client/work_type.rb +68 -0
- data/orcid_client.gemspec +37 -0
- data/resources/common_2.0_rc3/common-2.0_rc3.xsd +1624 -0
- data/resources/common_2.0_rc3/samples/common-2.0_rc3.xml +8 -0
- data/resources/notification_2.0_rc3/notification-custom-2.0_rc3.xsd +32 -0
- data/resources/notification_2.0_rc3/notification-permission-2.0_rc3.xsd +128 -0
- data/resources/notification_2.0_rc3/samples/notification-custom-2.0_rc3.xml +45 -0
- data/resources/notification_2.0_rc3/samples/notification-permission-2.0_rc3.xml +58 -0
- data/resources/record_2.0_rc3/activities-2.0_rc3.xsd +187 -0
- data/resources/record_2.0_rc3/address-2.0_rc3.xsd +73 -0
- data/resources/record_2.0_rc3/bulk-2.0_rc3.xsd +57 -0
- data/resources/record_2.0_rc3/deprecated-2.0_rc3.xsd +80 -0
- data/resources/record_2.0_rc3/education-2.0_rc3.xsd +96 -0
- data/resources/record_2.0_rc3/email-2.0_rc3.xsd +74 -0
- data/resources/record_2.0_rc3/employment-2.0_rc3.xsd +96 -0
- data/resources/record_2.0_rc3/error-2.0_rc3.xsd +84 -0
- data/resources/record_2.0_rc3/funding-2.0_rc3.xsd +257 -0
- data/resources/record_2.0_rc3/history-2.0_rc3.xsd +203 -0
- data/resources/record_2.0_rc3/internal-2.0_rc3.xsd +199 -0
- data/resources/record_2.0_rc3/keyword-2.0_rc3.xsd +72 -0
- data/resources/record_2.0_rc3/other-name-2.0_rc3.xsd +88 -0
- data/resources/record_2.0_rc3/peer-review-2.0_rc3.xsd +246 -0
- data/resources/record_2.0_rc3/person-2.0_rc3.xsd +98 -0
- data/resources/record_2.0_rc3/person-external-identifier-2.0_rc3.xsd +63 -0
- data/resources/record_2.0_rc3/personal-details-2.0_rc3.xsd +186 -0
- data/resources/record_2.0_rc3/preferences-2.0_rc3.xsd +50 -0
- data/resources/record_2.0_rc3/record-2.0_rc3.xsd +105 -0
- data/resources/record_2.0_rc3/researcher-url-2.0_rc3.xsd +90 -0
- data/resources/record_2.0_rc3/samples/activities-2.0_rc3.xml +236 -0
- data/resources/record_2.0_rc3/samples/address-2.0_rc3.xml +16 -0
- data/resources/record_2.0_rc3/samples/addresses-2.0_rc3.xml +32 -0
- data/resources/record_2.0_rc3/samples/biography-2.0_rc3.xml +10 -0
- data/resources/record_2.0_rc3/samples/bulk-work-2.0_rc3.json +56 -0
- data/resources/record_2.0_rc3/samples/bulk-work-2.0_rc3.xml +62 -0
- data/resources/record_2.0_rc3/samples/credit-name-2.0_rc3.xml +5 -0
- data/resources/record_2.0_rc3/samples/deprecated-2.0_rc3.xml +13 -0
- data/resources/record_2.0_rc3/samples/education-2.0_rc3.xml +30 -0
- data/resources/record_2.0_rc3/samples/education-full-2.0_rc3.xml +40 -0
- data/resources/record_2.0_rc3/samples/email-2.0_rc3.xml +16 -0
- data/resources/record_2.0_rc3/samples/emails-2.0_rc3.xml +31 -0
- data/resources/record_2.0_rc3/samples/employment-2.0_rc3.xml +30 -0
- data/resources/record_2.0_rc3/samples/employment-full-2.0_rc3.xml +40 -0
- data/resources/record_2.0_rc3/samples/error-2.0_rc3.xml +8 -0
- data/resources/record_2.0_rc3/samples/external-identifier-2.0_rc3.xml +20 -0
- data/resources/record_2.0_rc3/samples/external-identifiers-2.0_rc3.xml +36 -0
- data/resources/record_2.0_rc3/samples/funding-2.0_rc3.xml +65 -0
- data/resources/record_2.0_rc3/samples/funding-full-2.0_rc3.xml +75 -0
- data/resources/record_2.0_rc3/samples/history-2.0_rc3.xml +22 -0
- data/resources/record_2.0_rc3/samples/keyword-2.0_rc3.xml +18 -0
- data/resources/record_2.0_rc3/samples/keywords-2.0_rc3.xml +34 -0
- data/resources/record_2.0_rc3/samples/name-2.0_rc3.xml +12 -0
- data/resources/record_2.0_rc3/samples/other-name-2.0_rc3.xml +16 -0
- data/resources/record_2.0_rc3/samples/other-names-2.0_rc3.xml +31 -0
- data/resources/record_2.0_rc3/samples/peer-review-2.0_rc3.xml +49 -0
- data/resources/record_2.0_rc3/samples/peer-review-full-2.0_rc3.xml +59 -0
- data/resources/record_2.0_rc3/samples/person-2.0_rc3.xml +122 -0
- data/resources/record_2.0_rc3/samples/personal-details-2.0_rc3.xml +47 -0
- data/resources/record_2.0_rc3/samples/preferences-2.0_rc3.xml +4 -0
- data/resources/record_2.0_rc3/samples/record-2.0_rc3.xml +420 -0
- data/resources/record_2.0_rc3/samples/researcher-url-2.0_rc3.xml +19 -0
- data/resources/record_2.0_rc3/samples/researcher-urls-2.0_rc3.xml +21 -0
- data/resources/record_2.0_rc3/samples/search-2.0_rc3.xml +368 -0
- data/resources/record_2.0_rc3/samples/work-2.0_rc3.xml +49 -0
- data/resources/record_2.0_rc3/samples/work-full-2.0_rc3.xml +59 -0
- data/resources/record_2.0_rc3/search-2.0_rc3.xsd +82 -0
- data/resources/record_2.0_rc3/work-2.0_rc3.xsd +445 -0
- data/spec/api_spec.rb +59 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient/get/should_get_works.yml +646 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient/notifications/post/should_create_notification.yml +104 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient/works/delete/should_delete_work.yml +38 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient/works/get/should_get_works.yml +646 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient/works/post/should_create_work.yml +116 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient/works/put/should_update_work.yml +155 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Notification/data.yml +44 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Notification/schema/validates_data.yml +44 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Notification/schema/validates_item_type_work.yml +41 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/citation.yml +50 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/contributors/literal.yml +47 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/contributors/multiple_titles.yml +47 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/contributors/valid.yml +50 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/contributors/with_ORCID_IDs.yml +157 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/data.yml +50 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/publication_date.yml +50 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/schema/validates_ORCID_IDs_for_contributors.yml +157 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/schema/validates_data.yml +50 -0
- data/spec/fixtures/vcr_cassettes/OrcidClient_Work/schema/validates_work_type_data-set.yml +47 -0
- data/spec/fixtures/work.xml +33 -0
- data/spec/notification_spec.rb +42 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/work_spec.rb +100 -0
- metadata +392 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54f06cf497dfe171a49f47fde54c1e48ea99d23e
|
4
|
+
data.tar.gz: 080aa75e6d0fe7f21caf5bba3989089a942f7028
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff5f961def7bff03bcee0d545eba8239866ed41a3f35ea7ca575764b611f859cc0d237588bf30c12333c57b6da9039a25a8f000d8bd9c91a9aecd6fa48b86ffe
|
7
|
+
data.tar.gz: 0e92bcefad358d649f24df1807f36c9bb4b210ad9a259c321f683b3ce3dc70b6635d17de6d2f328d04e817f7d84a956cb3a3c99f4e025db8d7b246d597b58ff8
|
data/.env.example
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
coverage/
|
38
|
+
|
39
|
+
.env
|
40
|
+
.env.*
|
41
|
+
!.env.example
|
42
|
+
!.env.travis
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3.1
|
4
|
+
install:
|
5
|
+
- travis_retry bundle install
|
6
|
+
script: bundle exec rspec
|
7
|
+
notifications:
|
8
|
+
slack: "$SLACK_TOKEN"
|
9
|
+
email: false
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: KZGdqCgmlAGQveK/b/bRSvUIO9wTlCUFngbmKLDHS9tf2gczBYNY3qnzD6GPJ7T12YFudWLH3W8D9CbRN6WyauwseKm+dRYVaeEg+tURobVD8FZgJBEaTnFr1EJNvb8x+iKxYjhV2XgCJHD6t7xbz+ONRVc71CrOi3qtVSRJKML2QocaUlgW+b6a7kMDT5/HtjOHipGf5MCXej+tlK1FESMYG5oNB/ogfbeDR928BCH7Kr4qtvndeF1QHwe5u4mD8UaVBPZNhm2ldEmxiI5+50B/BIjvX5afo0MPiWIJg+A3GlMpdQk4ETAxoT4WPyHYB4pjc2EwnEx9P7k1Zi/64oj+aAAwFlRw0Tof7GQ+zsFLtRSBGtKrWcmRU80iid0ATt+ZFBBNxZ8VDLRstm83wk5TShMPo2qil3eqvNzcvbbE4AwWdTDoky8Ipzto90RSFO1F2+8iLLC1+FLjKEwYakqdNhUz9ur2eVWWJFf2PHFpMDVDH907sRjFs2JaM81KJF4xuryPOlcvEFU/wlv42lSZ3oQPYH4TgV9PDYdcsFhmJkIIMb+RqAYn7PQYzwHUpEhklg0KaOns9hGi1V/iBE2X3Gy01QNITMtfSfIRGfHiFXEoHrXy7K9cZ0Zq2U7iaGsrQRAiv3zzz0FJ+uYH9nLXAC9U9UOUkqdGDNfbrl0=
|
14
|
+
gem: orcid_client
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: datacite/orcid_client
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
orcid_client (0.1)
|
5
|
+
activesupport (~> 4.2, >= 4.2.5)
|
6
|
+
builder (~> 3.2, >= 3.2.2)
|
7
|
+
dotenv (~> 2.1, >= 2.1.1)
|
8
|
+
maremma (~> 2.5)
|
9
|
+
namae (~> 0.10.1)
|
10
|
+
nokogiri (~> 1.6.8)
|
11
|
+
sanitize (~> 4.0, >= 4.0.1)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activesupport (4.2.7.1)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
addressable (2.5.0)
|
23
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
24
|
+
builder (3.2.2)
|
25
|
+
codeclimate-test-reporter (1.0.3)
|
26
|
+
simplecov
|
27
|
+
crack (0.4.3)
|
28
|
+
safe_yaml (~> 1.0.0)
|
29
|
+
crass (1.0.2)
|
30
|
+
diff-lcs (1.2.5)
|
31
|
+
docile (1.1.5)
|
32
|
+
dotenv (2.1.1)
|
33
|
+
excon (0.45.4)
|
34
|
+
faraday (0.9.2)
|
35
|
+
multipart-post (>= 1.2, < 3)
|
36
|
+
faraday-encoding (0.0.4)
|
37
|
+
faraday
|
38
|
+
faraday_middleware (0.10.1)
|
39
|
+
faraday (>= 0.7.4, < 1.0)
|
40
|
+
hashdiff (0.3.0)
|
41
|
+
i18n (0.7.0)
|
42
|
+
json (1.8.3)
|
43
|
+
maremma (2.5.3)
|
44
|
+
activesupport (~> 4.2, >= 4.2.5)
|
45
|
+
builder (~> 3.2, >= 3.2.2)
|
46
|
+
excon (~> 0.45.0)
|
47
|
+
faraday (~> 0.9.2)
|
48
|
+
faraday-encoding (~> 0.0.1)
|
49
|
+
faraday_middleware (~> 0.10.0)
|
50
|
+
multi_json (~> 1.11.2)
|
51
|
+
nokogiri (~> 1.6.7)
|
52
|
+
oj (~> 2.13.1)
|
53
|
+
mini_portile2 (2.1.0)
|
54
|
+
minitest (5.9.1)
|
55
|
+
multi_json (1.11.3)
|
56
|
+
multipart-post (2.0.0)
|
57
|
+
namae (0.10.2)
|
58
|
+
nokogiri (1.6.8.1)
|
59
|
+
mini_portile2 (~> 2.1.0)
|
60
|
+
nokogumbo (1.4.10)
|
61
|
+
nokogiri
|
62
|
+
oj (2.13.1)
|
63
|
+
public_suffix (2.0.4)
|
64
|
+
rack (2.0.1)
|
65
|
+
rack-test (0.6.3)
|
66
|
+
rack (>= 1.0)
|
67
|
+
rake (11.3.0)
|
68
|
+
rspec (3.5.0)
|
69
|
+
rspec-core (~> 3.5.0)
|
70
|
+
rspec-expectations (~> 3.5.0)
|
71
|
+
rspec-mocks (~> 3.5.0)
|
72
|
+
rspec-core (3.5.4)
|
73
|
+
rspec-support (~> 3.5.0)
|
74
|
+
rspec-expectations (3.5.0)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.5.0)
|
77
|
+
rspec-mocks (3.5.0)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.5.0)
|
80
|
+
rspec-support (3.5.0)
|
81
|
+
safe_yaml (1.0.4)
|
82
|
+
sanitize (4.4.0)
|
83
|
+
crass (~> 1.0.2)
|
84
|
+
nokogiri (>= 1.4.4)
|
85
|
+
nokogumbo (~> 1.4.1)
|
86
|
+
simplecov (0.12.0)
|
87
|
+
docile (~> 1.1.0)
|
88
|
+
json (>= 1.8, < 3)
|
89
|
+
simplecov-html (~> 0.10.0)
|
90
|
+
simplecov-html (0.10.0)
|
91
|
+
thread_safe (0.3.5)
|
92
|
+
tzinfo (1.2.2)
|
93
|
+
thread_safe (~> 0.1)
|
94
|
+
vcr (3.0.3)
|
95
|
+
webmock (1.24.6)
|
96
|
+
addressable (>= 2.3.6)
|
97
|
+
crack (>= 0.3.2)
|
98
|
+
hashdiff
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
bundler (~> 1.0)
|
105
|
+
codeclimate-test-reporter (~> 1.0.0)
|
106
|
+
orcid_client!
|
107
|
+
rack-test (~> 0)
|
108
|
+
rake
|
109
|
+
rspec (~> 3.4)
|
110
|
+
simplecov
|
111
|
+
vcr
|
112
|
+
webmock (~> 1.22, >= 1.22.3)
|
113
|
+
|
114
|
+
BUNDLED WITH
|
115
|
+
1.12.5
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 DataCite
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Ruby client for ORCID API
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/orcid_client.svg)](https://badge.fury.io/rb/orcid_client)
|
4
|
+
[![Build Status](https://travis-ci.org/datacite/orcid_client.svg?branch=master)](https://travis-ci.org/datacite/orcid_client)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/datacite/orcid_client/badges/coverage.svg)](https://codeclimate.com/github/datacite/orcid_client/coverage)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/datacite/orcid_client/badges/gpa.svg)](https://codeclimate.com/github/datacite/orcid_client)
|
7
|
+
|
8
|
+
Ruby gem for integrating Ruby applications with the ORCID API.
|
9
|
+
|
10
|
+
## Features
|
11
|
+
|
12
|
+
The following functionality is supported:
|
13
|
+
|
14
|
+
* get all works from an ORCID record, including those set to limited access
|
15
|
+
* create work in an ORCID record
|
16
|
+
* create notification for an ORCID record (needs special permissions)
|
17
|
+
|
18
|
+
## Requirements
|
19
|
+
|
20
|
+
* [ORCID membership](https://orcid.org/about/membership), needed to create, update or delete content via the ORCID API
|
21
|
+
* valid access tokens for ORCID user accounts, collected and safely stored in your application using for example the [omniauth-orcid](https://github.com/datacite/omniauth-orcid) gem.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
The usual way with Bundler: add the following to your `Gemfile` to install the current version of the gem:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'orcid_client'
|
29
|
+
```
|
30
|
+
|
31
|
+
Then run `bundle install` to install into your environment.
|
32
|
+
|
33
|
+
You can also install the gem system-wide in the usual way:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
gem install orcid_client
|
37
|
+
```
|
38
|
+
|
39
|
+
## Use
|
40
|
+
|
41
|
+
TBD.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
[MIT](license.md)
|
data/Rakefile
ADDED
data/lib/orcid_client.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
module OrcidClient
|
4
|
+
module Api
|
5
|
+
API_VERSION = "2.0_rc3"
|
6
|
+
|
7
|
+
def get_works(options={})
|
8
|
+
return { "errors" => [{ "title" => "Access token missing" }] } unless access_token.present?
|
9
|
+
|
10
|
+
orcid_api_url = options[:sandbox] ? 'https://api.sandbox.orcid.org' : 'https://api.orcid.org'
|
11
|
+
|
12
|
+
url = "#{orcid_api_url}/v#{API_VERSION}/#{orcid}/works"
|
13
|
+
Maremma.get(url, accept: 'json', bearer: access_token)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_work(options={})
|
17
|
+
return { "errors" => [{ "title" => "Access token missing" }] } unless access_token.present?
|
18
|
+
|
19
|
+
orcid_api_url = options[:sandbox] ? 'https://api.sandbox.orcid.org' : 'https://api.orcid.org'
|
20
|
+
|
21
|
+
url = "#{orcid_api_url}/v#{API_VERSION}/#{orcid}/work"
|
22
|
+
response = Maremma.post(url, content_type: 'application/vnd.orcid+xml', data: data, bearer: access_token)
|
23
|
+
put_code = response.fetch("headers", {}).fetch("Location", "").split("/").last
|
24
|
+
response.merge("put_code" => put_code)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_work(options={})
|
28
|
+
return { "errors" => [{ "title" => "Access token missing" }] } unless access_token.present?
|
29
|
+
return { "errors" => [{ "title" => "Put code missing" }] } unless put_code.present?
|
30
|
+
|
31
|
+
orcid_api_url = options[:sandbox] ? 'https://api.sandbox.orcid.org' : 'https://api.orcid.org'
|
32
|
+
|
33
|
+
url = "#{orcid_api_url}/v#{API_VERSION}/#{orcid}/work/#{put_code}"
|
34
|
+
response = Maremma.put(url, content_type: 'application/vnd.orcid+xml', data: data, bearer: access_token)
|
35
|
+
put_code = response.fetch("headers", {}).fetch("Location", "").split("/").last
|
36
|
+
response.merge("put_code" => put_code)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_work(options={})
|
40
|
+
return { "errors" => [{ "title" => "Access token missing" }] } unless access_token.present?
|
41
|
+
return { "errors" => [{ "title" => "Put code missing" }] } unless put_code.present?
|
42
|
+
|
43
|
+
orcid_api_url = options[:sandbox] ? 'https://api.sandbox.orcid.org' : 'https://api.orcid.org'
|
44
|
+
|
45
|
+
url = "#{orcid_api_url}/v#{API_VERSION}/#{orcid}/work/#{put_code}"
|
46
|
+
response = Maremma.delete(url, content_type: 'application/vnd.orcid+xml', bearer: access_token)
|
47
|
+
put_code = response.fetch("headers", {}).fetch("Location", "").split("/").last
|
48
|
+
response.merge("put_code" => put_code)
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_notification_access_token(client_id:, client_secret:, **options)
|
52
|
+
orcid_api_url = options[:sandbox] ? 'https://api.sandbox.orcid.org' : 'https://api.orcid.org'
|
53
|
+
|
54
|
+
params = { 'client_id' => client_id,
|
55
|
+
'client_secret' => client_secret,
|
56
|
+
'scope' => '/premium-notification',
|
57
|
+
'grant_type' => 'client_credentials' }
|
58
|
+
|
59
|
+
url = "#{orcid_api_url}/oauth/token"
|
60
|
+
data = URI.encode_www_form(params)
|
61
|
+
Maremma.post(url, content_type: 'application/x-www-form-urlencoded', data: data, accept: 'application/json')
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_notification(options={})
|
65
|
+
return { "errors" => [{ "title" => "Notification access token missing" }] } unless notification_access_token.present?
|
66
|
+
|
67
|
+
orcid_api_url = options[:sandbox] ? 'https://api.sandbox.orcid.org' : 'https://api.orcid.org'
|
68
|
+
|
69
|
+
url = "#{orcid_api_url}/v#{API_VERSION}/#{orcid}/notification-permission"
|
70
|
+
response = Maremma.post(url, content_type: 'application/vnd.orcid+xml', data: data, bearer: notification_access_token)
|
71
|
+
put_code = response.fetch("headers", {}).fetch("Location", "").split("/").last
|
72
|
+
response.merge("put_code" => put_code)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'namae'
|
2
|
+
|
3
|
+
module OrcidClient
|
4
|
+
module Author
|
5
|
+
# parse author string into CSL format
|
6
|
+
def get_one_author(author)
|
7
|
+
return "" if author.blank?
|
8
|
+
|
9
|
+
names = Namae.parse(author)
|
10
|
+
if names.present?
|
11
|
+
name = names.first
|
12
|
+
|
13
|
+
{ "family" => name.family,
|
14
|
+
"given" => name.given }.compact
|
15
|
+
else
|
16
|
+
{ "literal" => author }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# parse array of author strings into CSL format
|
21
|
+
def get_authors(authors)
|
22
|
+
Array(authors).map { |author| get_one_author(author) }
|
23
|
+
end
|
24
|
+
|
25
|
+
# parse array of author hashes into CSL format
|
26
|
+
def get_hashed_authors(authors)
|
27
|
+
Array(authors).map { |author| get_one_hashed_author(author) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_one_hashed_author(author)
|
31
|
+
raw_name = author.fetch("creatorName", nil)
|
32
|
+
|
33
|
+
author_hsh = get_one_author(raw_name)
|
34
|
+
author_hsh["ORCID"] = get_name_identifier(author)
|
35
|
+
author_hsh.compact
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_name_identifier(author)
|
39
|
+
name_identifier = author.fetch("nameIdentifier", nil)
|
40
|
+
name_identifier_scheme = author.fetch("nameIdentifierScheme", "orcid").downcase
|
41
|
+
if name_identifier.present? && name_identifier_scheme == "orcid"
|
42
|
+
"http://orcid.org/#{name_identifier}"
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_credit_name(author)
|
49
|
+
[author['given'], author['family']].compact.join(' ').presence || author['literal']
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_full_name(author)
|
53
|
+
[author['family'], author['given']].compact.join(', ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OrcidClient
|
2
|
+
module Base
|
3
|
+
# load ENV variables from .env file if it exists
|
4
|
+
env_file = File.expand_path("../../../.env", __FILE__)
|
5
|
+
if File.exist?(env_file)
|
6
|
+
require 'dotenv'
|
7
|
+
Dotenv.load! env_file
|
8
|
+
end
|
9
|
+
|
10
|
+
# load ENV variables from container environment if json file exists
|
11
|
+
# see https://github.com/phusion/baseimage-docker#envvar_dumps
|
12
|
+
env_json_file = "/etc/container_environment.json"
|
13
|
+
if File.exist?(env_json_file)
|
14
|
+
env_vars = JSON.parse(File.read(env_json_file))
|
15
|
+
env_vars.each { |k, v| ENV[k] = v }
|
16
|
+
end
|
17
|
+
|
18
|
+
# default values for some ENV variables
|
19
|
+
ENV['ORCID_API_URL'] ||= "https://api.sandbox.orcid.org"
|
20
|
+
end
|
21
|
+
end
|