dor-services-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dor-services-client.gemspec +31 -0
- data/lib/dor/services/client.rb +80 -0
- data/lib/dor/services/client/version.rb +7 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0dc4362abaa9eaecac5c6f674648c6d03f9e59cdabcdfa71d5873b109adc4227
|
4
|
+
data.tar.gz: 5d79616a6ee362b38fd4f1a54ab943f5dc69e219e6b59f30147f4835b3c8a5fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d27e2217db14ee5354aa1e91063b36d52f9fbf48f71df75633010b260c0e501998ffaf102b39165e247604ecdf8cede0408ceddb55d4b8892f266671c8bc067
|
7
|
+
data.tar.gz: 4fba8bbce26a2cf3cccb98bc55665adaf51eac079d92f4baf8f75b6c23702e0b6eae40ed6cddb61b3fc98eb7fdc7b2b455efe77861d10c70c0035cec0ab35d38
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Dor::Services::Client
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dor-services-client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dor-services-client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dor-services-client.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dor/services/client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "dor/services/client/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dor-services-client"
|
8
|
+
spec.version = Dor::Services::Client::VERSION
|
9
|
+
spec.authors = ["Justin Coyne", "Michael Giarlo"]
|
10
|
+
spec.email = ["jcoyne@justincoyne.com", "leftwing@alumni.rutgers.edu"]
|
11
|
+
|
12
|
+
spec.summary = %q{A client for dor-services-app}
|
13
|
+
spec.homepage = 'https://github.com/sul-dlss/dor-services-client'
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# 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
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "faraday", "~> 0.15"
|
25
|
+
spec.add_dependency "activesupport", "~> 5.0"
|
26
|
+
|
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"
|
31
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'dor/services/client/version'
|
2
|
+
require 'singleton'
|
3
|
+
require 'faraday'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
|
6
|
+
module Dor
|
7
|
+
module Services
|
8
|
+
class Client
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
|
14
|
+
def self.configure(url:)
|
15
|
+
instance.url = url
|
16
|
+
end
|
17
|
+
|
18
|
+
# Creates a new object in DOR
|
19
|
+
# @return [HashWithIndifferentAccess] the response, which includes a :pid
|
20
|
+
def self.register(params:)
|
21
|
+
instance.register(params: params)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [String] object the identifier for the object
|
25
|
+
# @param [String] filename the name of the file to retrieve
|
26
|
+
# @return [String] the file contents from the workspace
|
27
|
+
def self.retrieve_file(object:, filename:)
|
28
|
+
instance.retrieve_file(object: object, filename: filename)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [String] object the identifier for the object
|
32
|
+
# @return [Array<String>] the list of filenames in the workspace
|
33
|
+
def self.list_files(object:)
|
34
|
+
instance.list_files(object: object)
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_writer :url
|
38
|
+
|
39
|
+
def url
|
40
|
+
@url || raise(Error, "url has not yet been configured")
|
41
|
+
end
|
42
|
+
|
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
|
52
|
+
end
|
53
|
+
|
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
|
61
|
+
end
|
62
|
+
|
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
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def connection
|
76
|
+
@connection ||= Faraday.new(url)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dor-services-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Coyne
|
8
|
+
- Michael Giarlo
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-12-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.15'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.15'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '5.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '5.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.17'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.17'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: webmock
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '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'
|
98
|
+
description:
|
99
|
+
email:
|
100
|
+
- jcoyne@justincoyne.com
|
101
|
+
- leftwing@alumni.rutgers.edu
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- dor-services-client.gemspec
|
115
|
+
- lib/dor/services/client.rb
|
116
|
+
- lib/dor/services/client/version.rb
|
117
|
+
homepage: https://github.com/sul-dlss/dor-services-client
|
118
|
+
licenses: []
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.7.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A client for dor-services-app
|
140
|
+
test_files: []
|