datacite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 14676f8f7b74e44521ef3a1501f17799613051797ec254883798eb4582185dd2
4
+ data.tar.gz: fa0eb2fa6f505fe8b73f7e765f06311bbf39d2232d05bbad85bbe01e48622993
5
+ SHA512:
6
+ metadata.gz: cd36d5249f1abb5ff9d9c1a498799c0897d1ed9d09ad42adacd75c23055a3414537336602d3f17b48c9fa26de6155eb82695b6e3c2110bc0b12d650224c19885
7
+ data.tar.gz: 8688df8c2c3decf2e6b092734397c2f515584b4d0f83d5d6cf62e1f9f69b3d4976d76c196db1665cfda352c0fee5bd56aed8a82a0e8cd27ae2dc77366b436123
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.2
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,90 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - spec/**/*_spec.rb
7
+
8
+ Style/StringLiterals:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ Enabled: true
14
+ EnforcedStyle: double_quotes
15
+
16
+ Layout/LineLength:
17
+ Max: 120
18
+
19
+ Gemspec/DateAssignment: # (new in 1.10)
20
+ Enabled: true
21
+ Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
22
+ Enabled: true
23
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
24
+ Enabled: true
25
+ Lint/AmbiguousAssignment: # (new in 1.7)
26
+ Enabled: true
27
+ Lint/DeprecatedConstants: # (new in 1.8)
28
+ Enabled: true
29
+ Lint/DuplicateBranch: # (new in 1.3)
30
+ Enabled: true
31
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
32
+ Enabled: true
33
+ Lint/EmptyBlock: # (new in 1.1)
34
+ Enabled: true
35
+ Lint/EmptyClass: # (new in 1.3)
36
+ Enabled: true
37
+ Lint/EmptyInPattern: # (new in 1.16)
38
+ Enabled: true
39
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
40
+ Enabled: true
41
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
42
+ Enabled: true
43
+ Lint/NumberedParameterAssignment: # (new in 1.9)
44
+ Enabled: true
45
+ Lint/OrAssignmentToConstant: # (new in 1.9)
46
+ Enabled: true
47
+ Lint/RedundantDirGlobSort: # (new in 1.8)
48
+ Enabled: true
49
+ Lint/SymbolConversion: # (new in 1.9)
50
+ Enabled: true
51
+ Lint/ToEnumArguments: # (new in 1.1)
52
+ Enabled: true
53
+ Lint/TripleQuotes: # (new in 1.9)
54
+ Enabled: true
55
+ Lint/UnexpectedBlockArity: # (new in 1.5)
56
+ Enabled: true
57
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
58
+ Enabled: true
59
+ Naming/InclusiveLanguage: # (new in 1.18)
60
+ Enabled: true
61
+ Style/ArgumentsForwarding: # (new in 1.1)
62
+ Enabled: true
63
+ Style/CollectionCompact: # (new in 1.2)
64
+ Enabled: true
65
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
66
+ Enabled: true
67
+ Style/EndlessMethod: # (new in 1.8)
68
+ Enabled: true
69
+ Style/HashConversion: # (new in 1.10)
70
+ Enabled: true
71
+ Style/HashExcept: # (new in 1.7)
72
+ Enabled: true
73
+ Style/IfWithBooleanLiteralBranches: # (new in 1.9)
74
+ Enabled: true
75
+ Style/InPatternThen: # (new in 1.16)
76
+ Enabled: true
77
+ Style/MultilineInPatternThen: # (new in 1.16)
78
+ Enabled: true
79
+ Style/NegatedIfElseCondition: # (new in 1.2)
80
+ Enabled: true
81
+ Style/NilLambda: # (new in 1.3)
82
+ Enabled: true
83
+ Style/QuotedSymbols: # (new in 1.16)
84
+ Enabled: true
85
+ Style/RedundantArgument: # (new in 1.4)
86
+ Enabled: true
87
+ Style/StringChars: # (new in 1.12)
88
+ Enabled: true
89
+ Style/SwapValues: # (new in 1.1)
90
+ Enabled: true
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in datacite.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
13
+
14
+ gem "rubocop-rake", "~> 0.6.0"
15
+ gem "rubocop-rspec", "~> 2.4"
16
+
17
+ gem "webmock", "~> 3.13"
18
+
19
+ gem "faraday_middleware", "~> 1.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ datacite (0.1.0)
5
+ dry-monads (~> 1.3)
6
+ faraday (~> 1.4)
7
+ zeitwerk (~> 2.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.8.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ ast (2.4.2)
15
+ concurrent-ruby (1.1.9)
16
+ crack (0.4.5)
17
+ rexml
18
+ diff-lcs (1.4.4)
19
+ dry-core (0.6.0)
20
+ concurrent-ruby (~> 1.0)
21
+ dry-equalizer (0.3.0)
22
+ dry-monads (1.3.5)
23
+ concurrent-ruby (~> 1.0)
24
+ dry-core (~> 0.4, >= 0.4.4)
25
+ dry-equalizer
26
+ faraday (1.5.0)
27
+ faraday-em_http (~> 1.0)
28
+ faraday-em_synchrony (~> 1.0)
29
+ faraday-excon (~> 1.1)
30
+ faraday-httpclient (~> 1.0.1)
31
+ faraday-net_http (~> 1.0)
32
+ faraday-net_http_persistent (~> 1.1)
33
+ faraday-patron (~> 1.0)
34
+ multipart-post (>= 1.2, < 3)
35
+ ruby2_keywords (>= 0.0.4)
36
+ faraday-em_http (1.0.0)
37
+ faraday-em_synchrony (1.0.0)
38
+ faraday-excon (1.1.0)
39
+ faraday-httpclient (1.0.1)
40
+ faraday-net_http (1.0.1)
41
+ faraday-net_http_persistent (1.1.0)
42
+ faraday-patron (1.0.0)
43
+ faraday_middleware (1.0.0)
44
+ faraday (~> 1.0)
45
+ hashdiff (1.0.1)
46
+ multipart-post (2.1.1)
47
+ parallel (1.20.1)
48
+ parser (3.0.1.1)
49
+ ast (~> 2.4.1)
50
+ public_suffix (4.0.6)
51
+ rainbow (3.0.0)
52
+ rake (13.0.4)
53
+ regexp_parser (2.1.1)
54
+ rexml (3.2.5)
55
+ rspec (3.10.0)
56
+ rspec-core (~> 3.10.0)
57
+ rspec-expectations (~> 3.10.0)
58
+ rspec-mocks (~> 3.10.0)
59
+ rspec-core (3.10.1)
60
+ rspec-support (~> 3.10.0)
61
+ rspec-expectations (3.10.1)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.10.0)
64
+ rspec-mocks (3.10.2)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.10.0)
67
+ rspec-support (3.10.2)
68
+ rubocop (1.18.3)
69
+ parallel (~> 1.10)
70
+ parser (>= 3.0.0.0)
71
+ rainbow (>= 2.2.2, < 4.0)
72
+ regexp_parser (>= 1.8, < 3.0)
73
+ rexml
74
+ rubocop-ast (>= 1.7.0, < 2.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (>= 1.4.0, < 3.0)
77
+ rubocop-ast (1.7.0)
78
+ parser (>= 3.0.1.1)
79
+ rubocop-rake (0.6.0)
80
+ rubocop (~> 1.0)
81
+ rubocop-rspec (2.4.0)
82
+ rubocop (~> 1.0)
83
+ rubocop-ast (>= 1.1.0)
84
+ ruby-progressbar (1.11.0)
85
+ ruby2_keywords (0.0.4)
86
+ unicode-display_width (2.0.0)
87
+ webmock (3.13.0)
88
+ addressable (>= 2.3.6)
89
+ crack (>= 0.3.2)
90
+ hashdiff (>= 0.4.0, < 2.0.0)
91
+ zeitwerk (2.4.2)
92
+
93
+ PLATFORMS
94
+ x86_64-darwin-19
95
+ x86_64-linux
96
+
97
+ DEPENDENCIES
98
+ datacite!
99
+ faraday_middleware (~> 1.0)
100
+ rake (~> 13.0)
101
+ rspec (~> 3.0)
102
+ rubocop (~> 1.7)
103
+ rubocop-rake (~> 0.6.0)
104
+ rubocop-rspec (~> 2.4)
105
+ webmock (~> 3.13)
106
+
107
+ BUNDLED WITH
108
+ 2.2.21
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Datacite Ruby Client
2
+
3
+ This is a Ruby client for interfacing with the DataCite REST API. https://support.datacite.org/docs/api
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'datacite'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install datacite
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = Datacite::Client.new(username: "foo", password: "bar")
25
+ result = client.autogenerate_doi
26
+ result.either(
27
+ -> response { response.doi },
28
+ -> response { raise("Something went wrong", response.status) }
29
+ )
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sul-dlss/datacite-ruby.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "datacite"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/datacite.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/datacite/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "datacite"
7
+ spec.version = Datacite::VERSION
8
+ spec.authors = ["Justin Coyne"]
9
+ spec.email = ["jcoyne@justincoyne.com"]
10
+
11
+ spec.summary = "A Ruby client library for the DataCite REST API "
12
+ spec.description = "See https://support.datacite.org/docs/api"
13
+ spec.homepage = "https://github.com/sul-dlss/datacite-ruby"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "dry-monads", "~> 1.3"
32
+ spec.add_dependency "faraday", "~> 1.4"
33
+ spec.add_dependency "zeitwerk", "~> 2.4"
34
+ end
data/lib/datacite.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+
5
+ loader = Zeitwerk::Loader.new
6
+ loader.tag = File.basename(__FILE__, ".rb")
7
+ loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
8
+ loader.push_dir(__dir__)
9
+ loader.setup
10
+
11
+ module Datacite
12
+ class Error < StandardError; end
13
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datacite
4
+ # The JSON request to create a DOI
5
+ class AutogenerateDoi
6
+ # @param [Prefix] prefix
7
+ def initialize(prefix:)
8
+ @prefix = prefix
9
+ end
10
+
11
+ # @returns [Hash]
12
+ def to_json(*_args)
13
+ {
14
+ data: {
15
+ type: "dois",
16
+ attributes: {
17
+ prefix: prefix
18
+ }
19
+ }
20
+ }
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :prefix
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "dry/monads"
6
+
7
+ module Datacite
8
+ # The connection to DataCite API
9
+ class Client
10
+ include Dry::Monads[:result]
11
+
12
+ # @param [String] username
13
+ # @param [String] password
14
+ # @param [String] host
15
+ def initialize(username:, password:, host: "api.test.datacite.org")
16
+ @conn = Faraday.new(
17
+ url: "https://#{host}",
18
+ headers: headers
19
+ ) do |conn|
20
+ conn.request :json
21
+ conn.basic_auth(username, password)
22
+ conn.response :json
23
+ end
24
+ end
25
+
26
+ # @returns [Dry::Monads::Result]
27
+ def autogenerate_doi(prefix:)
28
+ request_body = AutogenerateDoi.new(prefix: prefix).to_json
29
+ response = conn.post("/dois", request_body)
30
+ response.success? ? Success(Response.new(response)) : Failure(response)
31
+ end
32
+
33
+ private
34
+
35
+ def headers
36
+ {
37
+ "Content-Type" => "application/vnd.api+json",
38
+ "User-Agent" => "Datacite Ruby client version #{Datacite::VERSION}"
39
+ }
40
+ end
41
+
42
+ attr_reader :conn
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datacite
4
+ # The response object from the datacite API
5
+ class Response
6
+ # @param [Hash] response a json reponse
7
+ def initialize(response)
8
+ @body = response.body
9
+ end
10
+
11
+ attr_reader :body
12
+
13
+ def doi
14
+ body.dig("data", "id")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datacite
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datacite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Coyne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-monads
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: zeitwerk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ description: See https://support.datacite.org/docs/api
56
+ email:
57
+ - jcoyne@justincoyne.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".github/workflows/main.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - datacite.gemspec
73
+ - lib/datacite.rb
74
+ - lib/datacite/autogenerate_doi.rb
75
+ - lib/datacite/client.rb
76
+ - lib/datacite/response.rb
77
+ - lib/datacite/version.rb
78
+ homepage: https://github.com/sul-dlss/datacite-ruby
79
+ licenses: []
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ homepage_uri: https://github.com/sul-dlss/datacite-ruby
83
+ source_code_uri: https://github.com/sul-dlss/datacite-ruby
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.7.0
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.1.4
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A Ruby client library for the DataCite REST API
103
+ test_files: []