zenodo 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zenodo.rb +4 -1
- data/lib/zenodo/client.rb +3 -3
- data/lib/zenodo/dsl/deposition_actions.rb +16 -13
- data/lib/zenodo/dsl/deposition_files.rb +47 -39
- data/lib/zenodo/dsl/depositions.rb +22 -18
- data/lib/zenodo/errors/client_error.rb +6 -1
- data/lib/zenodo/utils/url_helper.rb +8 -4
- data/lib/zenodo/version.rb +1 -1
- data/zenodo.gemspec +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89fa4a10e36778e6d9f6c874a4268126f0bd0499
|
4
|
+
data.tar.gz: b59b1061ab1faebb8c8697a093f1989d4f48d175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e1819983359266f8d722eaede929bf42b8fc2db999bf23a6d53395475ad52daa683e0463babb6fd21d110d9f61b56ff29a95810be14c15e8a27dc8cb020b989
|
7
|
+
data.tar.gz: 9599cc6a849cd1003953a957582c45fdc60a24f0849c789191668ff13d55515da23260f13262e5db1d05ba4c545d67b2e4fc59077d822e983f00e83a60fac2a2
|
data/lib/zenodo.rb
CHANGED
@@ -10,13 +10,16 @@ module Zenodo
|
|
10
10
|
class << self
|
11
11
|
# @return [String]
|
12
12
|
attr_accessor :api_key
|
13
|
+
attr_accessor :url
|
13
14
|
attr_accessor :logger
|
14
15
|
end
|
15
16
|
|
17
|
+
self.url = 'https://zenodo.org/api/'
|
18
|
+
|
16
19
|
module_function
|
17
20
|
|
18
21
|
# @return [Zenodo::Client]
|
19
22
|
def client
|
20
|
-
@client ||= Client.new(Zenodo.api_key)
|
23
|
+
@client ||= Client.new(Zenodo.api_key, Zenodo.url)
|
21
24
|
end
|
22
25
|
end
|
data/lib/zenodo/client.rb
CHANGED
@@ -12,13 +12,13 @@ module Zenodo
|
|
12
12
|
include Errors
|
13
13
|
include Utils
|
14
14
|
|
15
|
-
URL = 'https://zenodo.org/api/'
|
16
15
|
REQUESTS = [:get, :post, :put, :delete]
|
17
16
|
HEADERS = {'Accept' => 'application/json', 'Content-Type' => 'application/json'}
|
18
17
|
|
19
18
|
# @param [String] api_key
|
20
|
-
def initialize(api_key = Zenodo.api_key)
|
19
|
+
def initialize(api_key = Zenodo.api_key, url = Zenodo.url)
|
21
20
|
@api_key = api_key
|
21
|
+
@url = url
|
22
22
|
|
23
23
|
# Setup HTTP request connection to Zenodo.
|
24
24
|
@connection ||= Faraday.new do |builder|
|
@@ -40,7 +40,7 @@ module Zenodo
|
|
40
40
|
def request(method, path, query = {}, headers = HEADERS)
|
41
41
|
raise ArgumentError, "Unsupported method #{method.inspect}. Only :get, :post, :put, :delete are allowed" unless REQUESTS.include?(method)
|
42
42
|
|
43
|
-
token_url = UrlHelper.build_url(path: "#{
|
43
|
+
token_url = UrlHelper.build_url(path: "#{@url}#{path}", params: {access_token: @api_key})
|
44
44
|
payload = nil
|
45
45
|
if query.present?
|
46
46
|
accept = headers.present? ? headers['Accept'] : nil
|
@@ -5,32 +5,35 @@ module Zenodo
|
|
5
5
|
# Publish POST deposit/depositions/:id/actions/publish
|
6
6
|
# Publishes a deposition.
|
7
7
|
# Note publishing will fail if no files are associated with the deposition.
|
8
|
-
# @param [
|
9
|
-
# @
|
8
|
+
# @param [Hash] options The options to publish a deposition with.
|
9
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
10
|
+
# @raise [ArgumentError] If the given :id is blank.
|
10
11
|
# @return [Zenodo::Resources::deposition, nil].
|
11
|
-
def publish_deposition(
|
12
|
-
|
12
|
+
def publish_deposition(options={})
|
13
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
13
14
|
Resources::Deposition.parse(request(:post, "deposit/depositions/#{id}/actions/publish", nil, nil))
|
14
15
|
end
|
15
16
|
|
16
17
|
# Edit POST deposit/depositions/:id/actions/edit
|
17
18
|
# Unlock already submitted deposition for editing.
|
18
|
-
# @param [
|
19
|
-
# @
|
19
|
+
# @param [Hash] options The options to edit a deposition with.
|
20
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
21
|
+
# @raise [ArgumentError] If the given :id is blank.
|
20
22
|
# @return [Zenodo::Resources::deposition, nil].
|
21
|
-
def edit_deposition(
|
22
|
-
|
23
|
+
def edit_deposition(options={})
|
24
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
23
25
|
Resources::Deposition.parse(request(:post, "deposit/depositions/#{id}/actions/edit", nil, nil))
|
24
26
|
end
|
25
27
|
|
26
28
|
# Discard POST deposit/depositions/:id/actions/discard
|
27
29
|
# Discard changes in the current editing session.
|
28
|
-
# @param [
|
29
|
-
# @
|
30
|
+
# @param [Hash] options The options to discard a deposition with.
|
31
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
32
|
+
# @raise [ArgumentError] If the given :id is blank.
|
30
33
|
# @return [Zenodo::Resources::deposition, nil].
|
31
|
-
def discard_deposition(
|
32
|
-
|
34
|
+
def discard_deposition(options={})
|
35
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
33
36
|
Resources::Deposition.parse(request(:post, "deposit/depositions/#{id}/actions/discard", nil, nil))
|
34
37
|
end
|
35
38
|
end
|
36
|
-
end
|
39
|
+
end
|
@@ -4,26 +4,30 @@ module Zenodo
|
|
4
4
|
module DSL::DepositionFiles
|
5
5
|
# List GET deposit/depositions/:id/files
|
6
6
|
# List all deposition files for a given deposition.
|
7
|
-
# @param [
|
8
|
-
# @
|
7
|
+
# @param [Hash] options The options to get a deposition with.
|
8
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
9
|
+
# @raise [ArgumentError] If the given :id is blank.
|
9
10
|
# @return [Array, nil].
|
10
|
-
def get_deposition_files(
|
11
|
-
|
11
|
+
def get_deposition_files(options={})
|
12
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
12
13
|
Resources::DepositionFile.parse(request(:get, "deposit/depositions/#{id}/files", nil))
|
13
14
|
end
|
14
15
|
|
15
16
|
# Create (upload) POST deposit/depositions/:id/files
|
16
17
|
# Upload a new file.
|
17
18
|
# Note the upload will fail if the filename already exists.
|
18
|
-
# @param [
|
19
|
-
# @
|
20
|
-
# @
|
21
|
-
# @
|
22
|
-
# @
|
19
|
+
# @param [Hash] options The options to create a deposition file with.
|
20
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
21
|
+
# @option options [String, IO] file_or_io The file or already open IO to upload.
|
22
|
+
# @option options [String] filename The name of the file (optional except when an IO).
|
23
|
+
# @option options [String] content_type The content type of the file (optional except when an IO).
|
24
|
+
# @raise [ArgumentError] If the :id or :file_or_io arguments are blank.
|
23
25
|
# @return [Zenodo::Resources::DepositionFile].
|
24
|
-
def create_deposition_file(
|
25
|
-
|
26
|
-
|
26
|
+
def create_deposition_file(options={})
|
27
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
28
|
+
file_or_io = options[:file_or_io] || raise(ArgumentError, "Must supply :file_or_io")
|
29
|
+
filename = options[:filename]
|
30
|
+
content_type = options[:content_type]
|
27
31
|
|
28
32
|
content_type = MIME::Types.type_for(file_or_io).first.content_type if content_type.blank?
|
29
33
|
io = Faraday::UploadIO.new(file_or_io, content_type, filename)
|
@@ -36,54 +40,58 @@ module Zenodo
|
|
36
40
|
|
37
41
|
# Sort PUT deposit/depositions/:id/files
|
38
42
|
# Sort the files for a deposition. By default, the first file is shown in the file preview.
|
39
|
-
# @param [
|
40
|
-
# @
|
41
|
-
# @
|
43
|
+
# @param [Hash] options The options to sort a deposition's files with.
|
44
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
45
|
+
# @option options [Array] :deposition_files The deposition files to sort.
|
46
|
+
# @raise [ArgumentError] If :id or :deposition_files arguments are blank.
|
42
47
|
# @return [Array, nil].
|
43
|
-
def sort_deposition_files(
|
44
|
-
|
45
|
-
|
48
|
+
def sort_deposition_files(options={})
|
49
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
50
|
+
deposition_files = options[:deposition_files] || raise(ArgumentError, "Must supply :deposition_files")
|
46
51
|
Resources::DepositionFile.parse(request(:put, "deposit/depositions/#{id}/files", deposition_files))
|
47
52
|
end
|
48
53
|
|
49
54
|
# Retrieve GET deposit/depositions/:id/files/:file_id
|
50
55
|
# Retrieve a single deposition file.
|
51
|
-
# @param [
|
52
|
-
# @
|
53
|
-
# @
|
56
|
+
# @param [Hash] options The options to get a deposition's file with.
|
57
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
58
|
+
# @option options [String] :file_id A deposition file ID.
|
59
|
+
# @raise [ArgumentError] If :id or :file_id arguments are blank.
|
54
60
|
# @return [Zenodo::Resources::DepositionFile].
|
55
|
-
def get_deposition_file(
|
56
|
-
|
57
|
-
|
61
|
+
def get_deposition_file(options={})
|
62
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
63
|
+
file_id = options[:file_id] || raise(ArgumentError, "Must supply :file_id")
|
58
64
|
Resources::DepositionFile.parse(request(:get, "deposit/depositions/#{id}/files/#{file_id}", nil))
|
59
65
|
end
|
60
66
|
|
61
67
|
# Update PUT deposit/depositions/:id/files/:file_id
|
62
68
|
# Update a deposition file resource. Currently the only use is renaming an already uploaded file.
|
63
69
|
# If you one to replace the actual file, please delete the file and upload a new file.
|
64
|
-
# @param [
|
65
|
-
# @
|
66
|
-
# @
|
67
|
-
# @
|
70
|
+
# @param [Hash] options The options to update a deposition's file with.
|
71
|
+
# @options option [String, Fixnum] :id A deposition's ID.
|
72
|
+
# @options option [String] :file_id A deposition file ID.
|
73
|
+
# @options option [Hash] :deposition_file The deposition file to update.
|
74
|
+
# @raise [ArgumentError] If the :id, :file_id, or :deposition_file arguments are blank.
|
68
75
|
# @return [Zenodo::Resources::DepositionFile].
|
69
|
-
def update_deposition_file(
|
70
|
-
|
71
|
-
|
72
|
-
|
76
|
+
def update_deposition_file(options={})
|
77
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
78
|
+
file_id = options[:file_id] || raise(ArgumentError, "Must supply :file_id")
|
79
|
+
deposition_file = options[:deposition_file] || raise(ArgumentError, "Must supply :deposition_file")
|
73
80
|
Resources::DepositionFile.parse(request(:put, "deposit/depositions/#{id}/files/#{file_id}", deposition_file))
|
74
81
|
end
|
75
82
|
|
76
83
|
# Delete DELETE deposit/depositions/:id/files/:file_id
|
77
84
|
# Delete an existing deposition file resource.
|
78
85
|
# Note, only deposition files for unpublished depositions may be deleted.
|
79
|
-
# @param [
|
80
|
-
# @
|
81
|
-
# @
|
86
|
+
# @param [Hash] options The options to delete a deposition's file with.
|
87
|
+
# @options option [String, Fixnum] :id A deposition's ID.
|
88
|
+
# @options option [String] :file_id A deposition file ID.
|
89
|
+
# @raise [ArgumentError] If the :id or :file_id arguments are blank.
|
82
90
|
# @return [Faraday::Response].
|
83
|
-
def delete_deposition_file(
|
84
|
-
|
85
|
-
|
91
|
+
def delete_deposition_file(options={})
|
92
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
93
|
+
file_id = options[:file_id] || raise(ArgumentError, "Must supply :file_id")
|
86
94
|
request(:delete, "deposit/depositions/#{id}/files/#{file_id}", nil, nil)
|
87
95
|
end
|
88
96
|
end
|
89
|
-
end
|
97
|
+
end
|
@@ -11,43 +11,47 @@ module Zenodo
|
|
11
11
|
|
12
12
|
# GET /Deposit/Deposition/{id}
|
13
13
|
# Get a deposition.
|
14
|
-
# @param [
|
15
|
-
# @
|
14
|
+
# @param [Hash] options The options to get a deposition with.
|
15
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
16
|
+
# @raise [ArgumentError] If the :id is blank
|
16
17
|
# @return [Zenodo::Resources::deposition, nil].
|
17
|
-
def get_deposition(
|
18
|
-
|
18
|
+
def get_deposition(options={})
|
19
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
19
20
|
Resources::Deposition.parse(request(:get, "deposit/depositions/#{id}"))
|
20
21
|
end
|
21
22
|
|
22
23
|
# POST /Deposit/Depositions
|
23
24
|
# Creates a deposition.
|
24
|
-
# @param [Hash]
|
25
|
-
# @
|
25
|
+
# @param [Hash] options The options to create a deposition with.
|
26
|
+
# @option options [Hash] :deposition The deposition to create.
|
27
|
+
# @raise [ArgumentError] If the :deposition arguments are blank.
|
26
28
|
# @return [Zenodo::Resources::deposition, nil].
|
27
|
-
def create_deposition(
|
28
|
-
|
29
|
+
def create_deposition(options={})
|
30
|
+
deposition = options[:deposition] || raise(ArgumentError, "Must supply :deposition")
|
29
31
|
Resources::Deposition.parse(request(:post, "deposit/depositions/", deposition))
|
30
32
|
end
|
31
33
|
|
32
34
|
# PUT /Deposit/Depositions
|
33
35
|
# Updates a deposition.
|
34
|
-
# @param [
|
35
|
-
# @
|
36
|
-
# @
|
36
|
+
# @param [Hash] options The options to update a deposition with.
|
37
|
+
# @option options [String, Fixnum] :id A deposition's ID.
|
38
|
+
# @option options [Hash] :deposition The deposition to update.
|
39
|
+
# @raise [ArgumentError] If the :id or :deposition arguments are blank.
|
37
40
|
# @return [Zenodo::Resources::deposition, nil].
|
38
|
-
def update_deposition(
|
39
|
-
|
40
|
-
|
41
|
+
def update_deposition(options={})
|
42
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
43
|
+
deposition = options[:deposition] || raise(ArgumentError, "Must supply :deposition")
|
41
44
|
Resources::Deposition.parse(request(:put, "deposit/depositions/#{id}", deposition))
|
42
45
|
end
|
43
46
|
|
44
47
|
# DELETE /Deposit/Depositions/{id}
|
45
48
|
# Deletes a deposition.
|
46
|
-
# @param [
|
47
|
-
# @
|
49
|
+
# @param [Hash] options The options to delete a deposition with.
|
50
|
+
# @option optoins [String, Fixnum] :id A deposition's ID.
|
51
|
+
# @raise [ArgumentError] If the :id argument is blank.
|
48
52
|
# @return [Faraday::Response].
|
49
|
-
def delete_deposition(
|
50
|
-
|
53
|
+
def delete_deposition(options={})
|
54
|
+
id = options[:id] || raise(ArgumentError, "Must supply :id")
|
51
55
|
request(:delete, "deposit/depositions/#{id}")
|
52
56
|
end
|
53
57
|
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module Zenodo
|
2
2
|
module Errors
|
3
3
|
class ClientError < StandardError
|
4
|
-
def initialize(
|
4
|
+
def initialize(options={})
|
5
|
+
method = options[:method] || raise(ArgumentError, "Must supply :method")
|
6
|
+
url = options[:url] || raise(ArgumentError, "Must supply :url")
|
7
|
+
response = options[:response] || raise(ArgumentError, "Must supply :response")
|
8
|
+
headers = options[:headers]
|
9
|
+
|
5
10
|
super <<-STR.gsub(/^\s*/, '')
|
6
11
|
HTTP #{method} #{url}
|
7
12
|
Request Headers: #{headers}
|
@@ -2,10 +2,14 @@ module Zenodo
|
|
2
2
|
module Utils
|
3
3
|
class UrlHelper
|
4
4
|
# Build a URL with a querystring containing optional params if supplied.
|
5
|
-
# @param [
|
6
|
-
# @
|
5
|
+
# @param [Hash] options The options to build a URL with.
|
6
|
+
# @options option [String] :path The name of the resource path as per the URL e.g. contacts.
|
7
|
+
# @options option [Hash] :params A hash of params we're turning into a querystring.
|
8
|
+
# @raise [ArgumentError] If the :path or :params arguments are blank.
|
7
9
|
# @return [UrlHelper] The URL of the resource with required params.
|
8
|
-
def self.build_url(
|
10
|
+
def self.build_url(options={})
|
11
|
+
path = options[:path] || raise(ArgumentError, "Must supply :path")
|
12
|
+
params = options[:params] || raise(ArgumentError, "Must supply :params")
|
9
13
|
params.delete_if {|k,v| v.blank?}
|
10
14
|
params = params.to_query
|
11
15
|
query = path
|
@@ -14,4 +18,4 @@ module Zenodo
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
data/lib/zenodo/version.rb
CHANGED
data/zenodo.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'zenodo/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "zenodo"
|
8
8
|
spec.version = Zenodo::VERSION
|
9
|
-
spec.authors = ["David Iorns"]
|
10
|
-
spec.email = ["david.iorns@gmail.com"]
|
9
|
+
spec.authors = ["David Iorns", "Zach Dennis"]
|
10
|
+
spec.email = ["david.iorns@gmail.com", "zach.dennis@gmail.com"]
|
11
11
|
spec.summary = 'A Ruby wrapper for the Zenodo API. https://zenodo.org/dev'
|
12
12
|
spec.description = "A Ruby wrapper for the Zenodo API. https://zenodo.org/dev.
|
13
13
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenodo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Iorns
|
8
|
+
- Zach Dennis
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: faraday
|
@@ -130,6 +131,7 @@ description: |-
|
|
130
131
|
that are not part of the existing institutional or subject-based repositories of the research communities.
|
131
132
|
email:
|
132
133
|
- david.iorns@gmail.com
|
134
|
+
- zach.dennis@gmail.com
|
133
135
|
executables: []
|
134
136
|
extensions: []
|
135
137
|
extra_rdoc_files: []
|