dor-services-client 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dc4362abaa9eaecac5c6f674648c6d03f9e59cdabcdfa71d5873b109adc4227
4
- data.tar.gz: 5d79616a6ee362b38fd4f1a54ab943f5dc69e219e6b59f30147f4835b3c8a5fb
3
+ metadata.gz: 4cc04584524185c77cc51392ebe2d26cdd52c62811bdefcec67c34823c7f2c77
4
+ data.tar.gz: 66c0e4f1c3bc51f9e5ac0236a4d08fa7e10b4a5dcec95323a791a8c9556f1dce
5
5
  SHA512:
6
- metadata.gz: 9d27e2217db14ee5354aa1e91063b36d52f9fbf48f71df75633010b260c0e501998ffaf102b39165e247604ecdf8cede0408ceddb55d4b8892f266671c8bc067
7
- data.tar.gz: 4fba8bbce26a2cf3cccb98bc55665adaf51eac079d92f4baf8f75b6c23702e0b6eae40ed6cddb61b3fc98eb7fdc7b2b455efe77861d10c70c0035cec0ab35d38
6
+ metadata.gz: 552b9071818b8ea4705176e2bcb52feb695d932c836e5e3ea65698a81e9cfc0e42e228de5ab05a115eb29cb1fa72c14a23593ea226365c25bad89305e4aaf750
7
+ data.tar.gz: 88f1e631dc93a138cd8747fb25c16914011ff89be2d992d44f0660c39cc8989ced643785e4bb49446523ac3dfa57a3e1b41499342366976704a4c5b3ccf65c5a
@@ -0,0 +1,3 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ AllCops:
3
+ TargetRubyVersion: 2.3
@@ -0,0 +1,26 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-12-18 09:21:53 -0800 using RuboCop version 0.60.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Configuration parameters: CountComments, ExcludedMethods.
11
+ # ExcludedMethods: refine
12
+ Metrics/BlockLength:
13
+ Max: 104
14
+
15
+ # Offense count: 1
16
+ Style/Documentation:
17
+ Exclude:
18
+ - 'spec/**/*'
19
+ - 'test/**/*'
20
+ - 'lib/dor/services/client.rb'
21
+
22
+ # Offense count: 10
23
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
24
+ # URISchemes: http, https
25
+ Metrics/LineLength:
26
+ Max: 115
@@ -1,6 +1,19 @@
1
- ---
1
+
2
+ # single test suite, non-parallel build.
3
+
4
+ env:
5
+ global:
6
+ - CC_TEST_REPORTER_ID=47b57fbbf65654b17f33b6ff4a108ce2abed31a86468033f20eb4d4e9e09935a
2
7
  language: ruby
3
8
  cache: bundler
4
9
  rvm:
5
10
  - 2.5.3
6
11
  before_install: gem install bundler -v 1.17.1
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter
15
+ - ./cc-test-reporter before-build
16
+ script:
17
+ - bundle exec rspec
18
+ after_script:
19
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in dor-services-client.gemspec
6
8
  gemspec
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![Gem Version](https://badge.fury.io/rb/dor-services-client.svg)](https://badge.fury.io/rb/dor-services-client)
2
+ [![Build Status](https://travis-ci.com/sul-dlss/dor-services-client.svg?branch=master)](https://travis-ci.com/sul-dlss/dor-services-client)
3
+ [![Code Climate](https://codeclimate.com/github/sul-dlss/dor-services-client/badges/gpa.svg)](https://codeclimate.com/github/sul-dlss/dor-services-client)
4
+ [![Code Climate Test Coverage](https://codeclimate.com/github/sul-dlss/dor-services-client/badges/coverage.svg)](https://codeclimate.com/github/sul-dlss/dor-services-client/coverage)
5
+
1
6
  # Dor::Services::Client
2
7
 
3
8
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dor/services/client`. To experiment with that code, run `bin/console` for an interactive prompt.
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
3
2
 
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new
4
8
  RSpec::Core::RakeTask.new(:spec)
5
9
 
6
- task :default => :spec
10
+ desc 'Run linter and tests'
11
+ task default: %i[rubocop spec]
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "dor/services/client"
4
+ require 'bundler/setup'
5
+ require 'dor/services/client'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "dor/services/client"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,31 +1,33 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "dor/services/client/version"
5
+ require 'dor/services/client/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "dor-services-client"
8
+ spec.name = 'dor-services-client'
8
9
  spec.version = Dor::Services::Client::VERSION
9
- spec.authors = ["Justin Coyne", "Michael Giarlo"]
10
- spec.email = ["jcoyne@justincoyne.com", "leftwing@alumni.rutgers.edu"]
10
+ spec.authors = ['Justin Coyne', 'Michael Giarlo']
11
+ spec.email = ['jcoyne@justincoyne.com', 'leftwing@alumni.rutgers.edu']
11
12
 
12
- spec.summary = %q{A client for dor-services-app}
13
+ spec.summary = 'A client for dor-services-app'
13
14
  spec.homepage = 'https://github.com/sul-dlss/dor-services-client'
14
15
 
15
16
  # Specify which files should be added to the gem when it is released.
16
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
20
  end
20
- spec.bindir = "exe"
21
+ spec.bindir = 'exe'
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
23
24
 
24
- spec.add_dependency "faraday", "~> 0.15"
25
- spec.add_dependency "activesupport", "~> 5.0"
25
+ spec.add_dependency 'activesupport', '~> 5.0'
26
+ spec.add_dependency 'faraday', '~> 0.15'
26
27
 
27
- spec.add_development_dependency "bundler", "~> 1.17"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
30
- spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.61.0'
32
+ spec.add_development_dependency 'webmock'
31
33
  end
@@ -1,7 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dor/services/client/version'
2
4
  require 'singleton'
3
5
  require 'faraday'
4
6
  require 'active_support/core_ext/hash/indifferent_access'
7
+ require 'dor/services/client/files'
8
+ require 'dor/services/client/objects'
9
+ require 'dor/services/client/release_tags'
10
+ require 'dor/services/client/workflow'
11
+ require 'dor/services/client/workspace'
5
12
 
6
13
  module Dor
7
14
  module Services
@@ -10,6 +17,25 @@ module Dor
10
17
 
11
18
  include Singleton
12
19
 
20
+ def objects
21
+ @objects ||= Objects.new(connection: connection)
22
+ end
23
+
24
+ def files
25
+ @files ||= Files.new(connection: connection)
26
+ end
27
+
28
+ def workflow
29
+ @workflow ||= Workflow.new(connection: connection)
30
+ end
31
+
32
+ def workspace
33
+ @workspace ||= Workspace.new(connection: connection)
34
+ end
35
+
36
+ def release_tags
37
+ @release_tags ||= ReleaseTags.new(connection: connection)
38
+ end
13
39
 
14
40
  def self.configure(url:)
15
41
  instance.url = url
@@ -18,60 +44,59 @@ module Dor
18
44
  # Creates a new object in DOR
19
45
  # @return [HashWithIndifferentAccess] the response, which includes a :pid
20
46
  def self.register(params:)
21
- instance.register(params: params)
47
+ instance.objects.register(params: params)
22
48
  end
23
49
 
24
50
  # @param [String] object the identifier for the object
25
51
  # @param [String] filename the name of the file to retrieve
26
52
  # @return [String] the file contents from the workspace
27
53
  def self.retrieve_file(object:, filename:)
28
- instance.retrieve_file(object: object, filename: filename)
54
+ instance.files.retrieve(object: object, filename: filename)
29
55
  end
30
56
 
31
57
  # @param [String] object the identifier for the object
32
58
  # @return [Array<String>] the list of filenames in the workspace
33
59
  def self.list_files(object:)
34
- instance.list_files(object: object)
60
+ instance.files.list(object: object)
35
61
  end
36
62
 
37
- attr_writer :url
38
-
39
- def url
40
- @url || raise(Error, "url has not yet been configured")
63
+ # Initializes a new workflow
64
+ # @param object [String] the pid for the object
65
+ # @param wf_name [String] the name of the workflow
66
+ # @raises [Error] if the request is unsuccessful.
67
+ # @return nil
68
+ def self.initialize_workflow(object:, wf_name:)
69
+ instance.workflow.create(object: object, wf_name: wf_name)
41
70
  end
42
71
 
43
- def register(params:)
44
- resp = connection.post do |req|
45
- req.url 'v1/objects'
46
- req.headers['Content-Type'] = 'application/json'
47
- req.headers['Accept'] = 'application/json' # asking the service to return JSON (else it'll be plain text)
48
- req.body = params.to_json
49
- end
50
- raise "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
51
- JSON.parse(resp.body).with_indifferent_access
72
+ # Initializes a new workspace
73
+ # @param object [String] the pid for the object
74
+ # @param source [String] the path to the object
75
+ # @raises [Error] if the request is unsuccessful.
76
+ # @return nil
77
+ def self.initialize_workspace(object:, source:)
78
+ instance.workspace.create(object: object, source: source)
52
79
  end
53
80
 
54
- def retrieve_file(object:, filename:)
55
- resp = connection.get do |req|
56
- req.url "v1/objects/#{object}/contents/#{filename}"
57
- end
58
- return unless resp.success?
59
-
60
- resp.body
81
+ # Creates a new release tag for the object
82
+ # @param object [String] the pid for the object
83
+ # @param release [Boolean]
84
+ # @param what [String]
85
+ # @param to [String]
86
+ # @param who [String]
87
+ # @return [Boolean] true if successful
88
+ def self.create_release_tag(object:, release:, what:, to:, who:)
89
+ instance.release_tags.create(object: object, release: release, what: what, to: to, who: who)
61
90
  end
62
91
 
63
- def list_files(object:)
64
- resp = connection.get do |req|
65
- req.url "v1/objects/#{object}/contents"
66
- end
67
- return [] unless resp.success?
68
-
69
- json = JSON.parse(resp.body)
70
- json['items'].map { |item| item['name'] }
71
- end
92
+ attr_writer :url
72
93
 
73
94
  private
74
95
 
96
+ def url
97
+ @url || raise(Error, 'url has not yet been configured')
98
+ end
99
+
75
100
  def connection
76
101
  @connection ||= Faraday.new(url)
77
102
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # API calls relating to files
7
+ class Files
8
+ def initialize(connection:)
9
+ @connection = connection
10
+ end
11
+
12
+ def retrieve(object:, filename:)
13
+ resp = connection.get do |req|
14
+ req.url "v1/objects/#{object}/contents/#{filename}"
15
+ end
16
+ return unless resp.success?
17
+
18
+ resp.body
19
+ end
20
+
21
+ def list(object:)
22
+ resp = connection.get do |req|
23
+ req.url "v1/objects/#{object}/contents"
24
+ end
25
+ return [] unless resp.success?
26
+
27
+ json = JSON.parse(resp.body)
28
+ json['items'].map { |item| item['name'] }
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :connection
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # API calls that are about a repository object
7
+ class Objects
8
+ def initialize(connection:)
9
+ @connection = connection
10
+ end
11
+
12
+ attr_reader :connection
13
+
14
+ # Creates a new object in DOR
15
+ # @return [HashWithIndifferentAccess] the response, which includes a :pid
16
+ def register(params:)
17
+ resp = connection.post do |req|
18
+ req.url 'v1/objects'
19
+ req.headers['Content-Type'] = 'application/json'
20
+ # asking the service to return JSON (else it'll be plain text)
21
+ req.headers['Accept'] = 'application/json'
22
+ req.body = params.to_json
23
+ end
24
+ raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
25
+
26
+ JSON.parse(resp.body).with_indifferent_access
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # API calls that are about a repository object
7
+ class ReleaseTags
8
+ def initialize(connection:)
9
+ @connection = connection
10
+ end
11
+
12
+ attr_reader :connection
13
+
14
+ # Creates a new release tag for the object
15
+ # @param object [String] the pid for the object
16
+ # @param release [Boolean]
17
+ # @param what [String]
18
+ # @param to [String]
19
+ # @param who [String]
20
+ # @return [Boolean] true if successful
21
+ # rubocop:disable Metrics/MethodLength
22
+ def create(object:, release:, what:, to:, who:)
23
+ params = {
24
+ to: to,
25
+ who: who,
26
+ what: what,
27
+ release: release
28
+ }
29
+ resp = connection.post do |req|
30
+ req.url "v1/objects/#{object}/release_tags"
31
+ req.headers['Content-Type'] = 'application/json'
32
+ req.body = params.to_json
33
+ end
34
+ raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
35
+
36
+ true
37
+ end
38
+ # rubocop:enable Metrics/MethodLength
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dor
2
4
  module Services
3
5
  class Client
4
- VERSION = "0.1.0"
6
+ VERSION = '0.2.0'
5
7
  end
6
8
  end
7
9
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # API calls that are about workflow
7
+ class Workflow
8
+ def initialize(connection:)
9
+ @connection = connection
10
+ end
11
+
12
+ attr_reader :connection
13
+
14
+ # Begin a new workflow
15
+ # @param object [String] the pid for the object
16
+ # @param wf_name [String] the name of the workflow
17
+ # @raises [Error] if the request is unsuccessful.
18
+ # @return nil
19
+ def create(object:, wf_name:)
20
+ resp = connection.post do |req|
21
+ req.url "v1/objects/#{object}/apo_workflows/#{wf_name}"
22
+ end
23
+ raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # API calls that are about the DOR workspace
7
+ class Workspace
8
+ def initialize(connection:)
9
+ @connection = connection
10
+ end
11
+
12
+ attr_reader :connection
13
+
14
+ # Initializes a new workspace
15
+ # @param object [String] the pid for the object
16
+ # @param source [String] the path to the object
17
+ # @raises [Error] if the request is unsuccessful.
18
+ # @return nil
19
+ def create(object:, source:)
20
+ resp = connection.post do |req|
21
+ req.url "v1/objects/#{object}/initialize_workspace"
22
+ req.params['source'] = source
23
+ end
24
+ raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-services-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -12,33 +12,33 @@ cert_chain: []
12
12
  date: 2018-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: faraday
15
+ name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.15'
20
+ version: '5.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0.15'
27
+ version: '5.0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: activesupport
29
+ name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.0'
34
+ version: '0.15'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '5.0'
41
+ version: '0.15'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.61.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.61.0
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: webmock
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +119,8 @@ extra_rdoc_files: []
105
119
  files:
106
120
  - ".gitignore"
107
121
  - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".rubocop_todo.yml"
108
124
  - ".travis.yml"
109
125
  - Gemfile
110
126
  - README.md
@@ -113,7 +129,12 @@ files:
113
129
  - bin/setup
114
130
  - dor-services-client.gemspec
115
131
  - lib/dor/services/client.rb
132
+ - lib/dor/services/client/files.rb
133
+ - lib/dor/services/client/objects.rb
134
+ - lib/dor/services/client/release_tags.rb
116
135
  - lib/dor/services/client/version.rb
136
+ - lib/dor/services/client/workflow.rb
137
+ - lib/dor/services/client/workspace.rb
117
138
  homepage: https://github.com/sul-dlss/dor-services-client
118
139
  licenses: []
119
140
  metadata: {}