folio_client 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 +7 -0
- data/.rspec +3 -0
- data/.rubocop/custom.yml +42 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +30 -0
- data/.standard.yml +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +113 -0
- data/LICENSE +15 -0
- data/README.md +55 -0
- data/Rakefile +12 -0
- data/folio_client.gemspec +44 -0
- data/lib/folio_client/authenticator.rb +26 -0
- data/lib/folio_client/unexpected_response.rb +34 -0
- data/lib/folio_client/version.rb +5 -0
- data/lib/folio_client.rb +67 -0
- metadata +193 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 10e1bbd3e3daa19c4149d5a44e143a76b4a9f6eee076bf9930b93f8ccb0e6dba
|
|
4
|
+
data.tar.gz: 65cc43463f69c41fbebfb4b3cdfab5155b6acb1c86fa77c05834fbd3f4ff681c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 61e6b573661efa4008d7b9171242c0f50a465cccf875dd3c1cb2fd61b9cbf663fe0de8a464d0fe785d4955c09ce0080bb07ad0ce2ca75f74b9252c96367e80cc
|
|
7
|
+
data.tar.gz: 25ed05f11889b0cd4bb2ad72eb7ce03b6e68948ab45733f370b6af026eae5021be6259503ff359749836a776aeed8ef4a77d9eddc299df642a9d5a66bab96f4e
|
data/.rspec
ADDED
data/.rubocop/custom.yml
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.1
|
|
3
|
+
DisplayCopNames: true
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
Exclude:
|
|
6
|
+
- bin/**
|
|
7
|
+
- vendor/bundle/**/*
|
|
8
|
+
|
|
9
|
+
# Per team developer playbook
|
|
10
|
+
RSpec/MultipleMemoizedHelpers:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
RSpec/BeEq: # new in 2.9.0
|
|
14
|
+
Enabled: true
|
|
15
|
+
RSpec/BeNil: # new in 2.9.0
|
|
16
|
+
Enabled: true
|
|
17
|
+
RSpec/ChangeByZero: # new in 2.11
|
|
18
|
+
Enabled: true
|
|
19
|
+
RSpec/ClassCheck: # new in 2.13
|
|
20
|
+
Enabled: true
|
|
21
|
+
RSpec/ExcessiveDocstringSpacing: # new in 2.5
|
|
22
|
+
Enabled: true
|
|
23
|
+
RSpec/IdenticalEqualityAssertion: # new in 2.4
|
|
24
|
+
Enabled: true
|
|
25
|
+
RSpec/NoExpectationExample: # new in 2.13
|
|
26
|
+
Enabled: true
|
|
27
|
+
RSpec/SortMetadata: # new in 2.14
|
|
28
|
+
Enabled: true
|
|
29
|
+
RSpec/SubjectDeclaration: # new in 2.5
|
|
30
|
+
Enabled: true
|
|
31
|
+
RSpec/VerifiedDoubleReference: # new in 2.10.0
|
|
32
|
+
Enabled: true
|
|
33
|
+
RSpec/FactoryBot/ConsistentParenthesesStyle: # new in 2.14
|
|
34
|
+
Enabled: true
|
|
35
|
+
RSpec/FactoryBot/SyntaxMethods: # new in 2.7
|
|
36
|
+
Enabled: true
|
|
37
|
+
RSpec/Rails/AvoidSetupHook: # new in 2.4
|
|
38
|
+
Enabled: true
|
|
39
|
+
RSpec/Rails/HaveHttpStatus: # new in 2.12
|
|
40
|
+
Enabled: true
|
|
41
|
+
RSpec/Rails/InferredSpecType: # new in 2.14
|
|
42
|
+
Enabled: true
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2023-02-10 00:58:06 UTC using RuboCop version 1.44.1.
|
|
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: 20
|
|
10
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
11
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
|
|
12
|
+
# SupportedStyles: space, no_space, compact
|
|
13
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
|
14
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
15
|
+
Exclude:
|
|
16
|
+
- 'lib/folio_client.rb'
|
|
17
|
+
- 'spec/folio_client/authenticator_spec.rb'
|
|
18
|
+
- 'spec/folio_client_spec.rb'
|
|
19
|
+
|
|
20
|
+
# Offense count: 1
|
|
21
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
22
|
+
# Configuration parameters: EnforcedStyle.
|
|
23
|
+
# SupportedStyles: be, be_nil
|
|
24
|
+
RSpec/BeNil:
|
|
25
|
+
Exclude:
|
|
26
|
+
- 'spec/folio_client_spec.rb'
|
|
27
|
+
|
|
28
|
+
# Offense count: 1
|
|
29
|
+
RSpec/MultipleExpectations:
|
|
30
|
+
Max: 3
|
data/.standard.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
parallel: true
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
folio_client (0.1.0)
|
|
5
|
+
activesupport (>= 4.2, < 8)
|
|
6
|
+
faraday
|
|
7
|
+
zeitwerk
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
activesupport (7.0.4.2)
|
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
+
i18n (>= 1.6, < 2)
|
|
15
|
+
minitest (>= 5.1)
|
|
16
|
+
tzinfo (~> 2.0)
|
|
17
|
+
addressable (2.8.1)
|
|
18
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
19
|
+
ast (2.4.2)
|
|
20
|
+
byebug (11.1.3)
|
|
21
|
+
concurrent-ruby (1.2.0)
|
|
22
|
+
crack (0.4.5)
|
|
23
|
+
rexml
|
|
24
|
+
diff-lcs (1.5.0)
|
|
25
|
+
docile (1.4.0)
|
|
26
|
+
faraday (2.7.4)
|
|
27
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
28
|
+
ruby2_keywords (>= 0.0.4)
|
|
29
|
+
faraday-net_http (3.0.2)
|
|
30
|
+
hashdiff (1.0.1)
|
|
31
|
+
i18n (1.12.0)
|
|
32
|
+
concurrent-ruby (~> 1.0)
|
|
33
|
+
json (2.6.3)
|
|
34
|
+
language_server-protocol (3.17.0.3)
|
|
35
|
+
minitest (5.17.0)
|
|
36
|
+
parallel (1.22.1)
|
|
37
|
+
parser (3.2.0.0)
|
|
38
|
+
ast (~> 2.4.1)
|
|
39
|
+
public_suffix (5.0.1)
|
|
40
|
+
rainbow (3.1.1)
|
|
41
|
+
rake (13.0.6)
|
|
42
|
+
regexp_parser (2.7.0)
|
|
43
|
+
rexml (3.2.5)
|
|
44
|
+
rspec (3.12.0)
|
|
45
|
+
rspec-core (~> 3.12.0)
|
|
46
|
+
rspec-expectations (~> 3.12.0)
|
|
47
|
+
rspec-mocks (~> 3.12.0)
|
|
48
|
+
rspec-core (3.12.1)
|
|
49
|
+
rspec-support (~> 3.12.0)
|
|
50
|
+
rspec-expectations (3.12.2)
|
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
52
|
+
rspec-support (~> 3.12.0)
|
|
53
|
+
rspec-mocks (3.12.3)
|
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
55
|
+
rspec-support (~> 3.12.0)
|
|
56
|
+
rspec-support (3.12.0)
|
|
57
|
+
rubocop (1.44.1)
|
|
58
|
+
json (~> 2.3)
|
|
59
|
+
parallel (~> 1.10)
|
|
60
|
+
parser (>= 3.2.0.0)
|
|
61
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
62
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
63
|
+
rexml (>= 3.2.5, < 4.0)
|
|
64
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
|
65
|
+
ruby-progressbar (~> 1.7)
|
|
66
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
67
|
+
rubocop-ast (1.24.1)
|
|
68
|
+
parser (>= 3.1.1.0)
|
|
69
|
+
rubocop-capybara (2.17.0)
|
|
70
|
+
rubocop (~> 1.41)
|
|
71
|
+
rubocop-performance (1.15.2)
|
|
72
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
73
|
+
rubocop-ast (>= 0.4.0)
|
|
74
|
+
rubocop-rspec (2.18.1)
|
|
75
|
+
rubocop (~> 1.33)
|
|
76
|
+
rubocop-capybara (~> 2.17)
|
|
77
|
+
ruby-progressbar (1.11.0)
|
|
78
|
+
ruby2_keywords (0.0.5)
|
|
79
|
+
simplecov (0.22.0)
|
|
80
|
+
docile (~> 1.1)
|
|
81
|
+
simplecov-html (~> 0.11)
|
|
82
|
+
simplecov_json_formatter (~> 0.1)
|
|
83
|
+
simplecov-html (0.12.3)
|
|
84
|
+
simplecov_json_formatter (0.1.4)
|
|
85
|
+
standard (1.23.0)
|
|
86
|
+
language_server-protocol (~> 3.17.0.2)
|
|
87
|
+
rubocop (= 1.44.1)
|
|
88
|
+
rubocop-performance (= 1.15.2)
|
|
89
|
+
tzinfo (2.0.6)
|
|
90
|
+
concurrent-ruby (~> 1.0)
|
|
91
|
+
unicode-display_width (2.4.2)
|
|
92
|
+
webmock (3.18.1)
|
|
93
|
+
addressable (>= 2.8.0)
|
|
94
|
+
crack (>= 0.3.2)
|
|
95
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
96
|
+
zeitwerk (2.6.6)
|
|
97
|
+
|
|
98
|
+
PLATFORMS
|
|
99
|
+
x86_64-darwin-19
|
|
100
|
+
x86_64-linux
|
|
101
|
+
|
|
102
|
+
DEPENDENCIES
|
|
103
|
+
byebug
|
|
104
|
+
folio_client!
|
|
105
|
+
rake (~> 13.0)
|
|
106
|
+
rspec (~> 3.0)
|
|
107
|
+
rubocop-rspec
|
|
108
|
+
simplecov
|
|
109
|
+
standard
|
|
110
|
+
webmock
|
|
111
|
+
|
|
112
|
+
BUNDLED WITH
|
|
113
|
+
2.4.5
|
data/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
Copyright (c) 2023 by The Board of Trustees of the Leland Stanford
|
|
3
|
+
Junior University. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you
|
|
6
|
+
may not use this file except in compliance with the License. You
|
|
7
|
+
may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
14
|
+
implied. See the License for the specific language governing
|
|
15
|
+
permissions and limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/folio_client)
|
|
2
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/sul-dlss/folio_client/tree/main)
|
|
3
|
+
[](https://codeclimate.com/github/sul-dlss/folio_client/maintainability)
|
|
4
|
+
[](https://codeclimate.com/github/sul-dlss/folio_client/test_coverage)
|
|
5
|
+
|
|
6
|
+
# FolioClient
|
|
7
|
+
|
|
8
|
+
FolioClient is a Ruby gem that acts as a client to the RESTful HTTP APIs provided by the Folio ILS API.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
13
|
+
|
|
14
|
+
$ bundle add folio_client
|
|
15
|
+
|
|
16
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
17
|
+
|
|
18
|
+
$ gem install folio_client
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
require 'folio_client'
|
|
24
|
+
|
|
25
|
+
# this will configure the client and request an access token
|
|
26
|
+
client = FolioClient.configure(
|
|
27
|
+
url: 'https://okapi-dev.stanford.edu',
|
|
28
|
+
login_params: { username: 'xxx', password: 'yyy' },
|
|
29
|
+
okapi_headers: { 'X-Okapi-Tenant': 'sul', 'User-Agent': 'FolioApiClient' }
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
response = client.get('/organizations/organizations')
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Note that the settings will live in the consumer of this gem and would typically be used like this:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
require 'folio_client'
|
|
39
|
+
|
|
40
|
+
client = FolioClient.configure(
|
|
41
|
+
url: Settings.okapi.url,
|
|
42
|
+
login_params: Settings.okapi.login_params,
|
|
43
|
+
okapi_headers: Settings.okapi.headers
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
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).
|
|
52
|
+
|
|
53
|
+
## Contributing
|
|
54
|
+
|
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sul-dlss/folio_client.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "folio_client/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "folio_client"
|
|
9
|
+
spec.version = FolioClient::VERSION
|
|
10
|
+
spec.authors = ["Peter Mangiafico"]
|
|
11
|
+
spec.email = ["pmangiafico@stanford.edu"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "Interface for interacting with the Folio ILS API."
|
|
14
|
+
spec.description = "This provides API interaction with the Folio ILS API"
|
|
15
|
+
spec.homepage = "https://github.com/sul-dlss/folio_client"
|
|
16
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
17
|
+
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/sul-dlss/folio_client"
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/sul-dlss/folio_client/releases"
|
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
spec.add_dependency "activesupport", ">= 4.2", "< 8"
|
|
35
|
+
spec.add_dependency "faraday"
|
|
36
|
+
spec.add_dependency "zeitwerk"
|
|
37
|
+
|
|
38
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
40
|
+
spec.add_development_dependency "rubocop-rspec"
|
|
41
|
+
spec.add_development_dependency "simplecov"
|
|
42
|
+
spec.add_development_dependency "standard"
|
|
43
|
+
spec.add_development_dependency "webmock"
|
|
44
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class FolioClient
|
|
4
|
+
# Fetch a token from the Folio API using login_params
|
|
5
|
+
class Authenticator
|
|
6
|
+
def self.token(login_params, connection)
|
|
7
|
+
new(login_params, connection).token
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(login_params, connection)
|
|
11
|
+
@login_params = login_params
|
|
12
|
+
@connection = connection
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Request an access_token
|
|
16
|
+
def token
|
|
17
|
+
response = connection.post("/authn/login", login_params.to_json)
|
|
18
|
+
|
|
19
|
+
UnexpectedResponse.call(response) unless response.success?
|
|
20
|
+
|
|
21
|
+
JSON.parse(response.body)["okapiToken"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :login_params, :connection
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class FolioClient
|
|
4
|
+
# Handles unexpected responses when communicating with Folio
|
|
5
|
+
class UnexpectedResponse
|
|
6
|
+
# Error raised by the Folio Auth API returns a 422 Unauthorized
|
|
7
|
+
class UnauthorizedError < StandardError; end
|
|
8
|
+
|
|
9
|
+
# Error raised when the Folio API returns a 404 NotFound
|
|
10
|
+
class ResourceNotFound < StandardError; end
|
|
11
|
+
|
|
12
|
+
# Error raised when the Folio API returns a 403 Forbidden
|
|
13
|
+
class ForbiddenError < StandardError; end
|
|
14
|
+
|
|
15
|
+
# Error raised when the Folio API returns a 500
|
|
16
|
+
class ServiceUnavailable < StandardError; end
|
|
17
|
+
|
|
18
|
+
# @param [Faraday::Response] response
|
|
19
|
+
def self.call(response)
|
|
20
|
+
case response.status
|
|
21
|
+
when 403
|
|
22
|
+
raise ForbiddenError, "The operation requires privileges which the client does not have: #{response.body}"
|
|
23
|
+
when 404
|
|
24
|
+
raise ResourceNotFound, "Endpoint not found or resource does not exist: #{response.body}"
|
|
25
|
+
when 422
|
|
26
|
+
raise UnauthorizedError, "There was a problem fetching the access token: #{response.body} "
|
|
27
|
+
when 500
|
|
28
|
+
raise ServiceUnavailable, "The remote server returned an internal server error."
|
|
29
|
+
else
|
|
30
|
+
raise StandardError, "Unexpected response: #{response.status} #{response.body}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/folio_client.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/core_ext/module/delegation"
|
|
4
|
+
require "faraday"
|
|
5
|
+
require "singleton"
|
|
6
|
+
require "ostruct"
|
|
7
|
+
require "zeitwerk"
|
|
8
|
+
|
|
9
|
+
# Load the gem's internal dependencies: use Zeitwerk instead of needing to manually require classes
|
|
10
|
+
Zeitwerk::Loader.for_gem.setup
|
|
11
|
+
|
|
12
|
+
# Client for interacting with the Folio API
|
|
13
|
+
class FolioClient
|
|
14
|
+
include Singleton
|
|
15
|
+
|
|
16
|
+
DEFAULT_HEADERS = {
|
|
17
|
+
accept: "application/json, text/plain",
|
|
18
|
+
content_type: "application/json"
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
class << self
|
|
22
|
+
# @param url [String] the folio API URL
|
|
23
|
+
# @param login_params [Hash] the folio client login params (username:, password:)
|
|
24
|
+
# @param okapi_headers [Hash] the okapi specific headers to add (X-Okapi-Tenant:, User-Agent:)
|
|
25
|
+
def configure(url:, login_params:, okapi_headers:)
|
|
26
|
+
instance.config = OpenStruct.new(url:, login_params:, okapi_headers:, token: nil)
|
|
27
|
+
|
|
28
|
+
instance.config.token = Authenticator.token(login_params, connection)
|
|
29
|
+
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
delegate :config, :connection, :get, :post, to: :instance
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attr_accessor :config
|
|
37
|
+
|
|
38
|
+
# Send an authenticated get request
|
|
39
|
+
# @param path [String] the path to the Folio API request
|
|
40
|
+
# @param request [Hash] params to get to the API
|
|
41
|
+
def get(path, params = {})
|
|
42
|
+
response = connection.get(path, params, { "x-okapi-token": config.token })
|
|
43
|
+
|
|
44
|
+
UnexpectedResponse.call(response) unless response.success?
|
|
45
|
+
|
|
46
|
+
JSON.parse(response.body)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Send an authenticated post request
|
|
50
|
+
# @param path [String] the path to the Folio API request
|
|
51
|
+
# @param request [json] request body to post to the API
|
|
52
|
+
def post(path, request = nil)
|
|
53
|
+
response = connection.post(path, request, { "x-okapi-token": config.token })
|
|
54
|
+
|
|
55
|
+
UnexpectedResponse.call(response) unless response.success?
|
|
56
|
+
|
|
57
|
+
JSON.parse(response.body)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# the base connection to the Folio API
|
|
61
|
+
def connection
|
|
62
|
+
@connection ||= Faraday.new(
|
|
63
|
+
url: config.url,
|
|
64
|
+
headers: DEFAULT_HEADERS.merge(config.okapi_headers || {})
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: folio_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Peter Mangiafico
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-02-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.2'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '8'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '4.2'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '8'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: faraday
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: zeitwerk
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rake
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '13.0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '13.0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rspec
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '3.0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3.0'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rubocop-rspec
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: simplecov
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: standard
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
type: :development
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
- !ruby/object:Gem::Dependency
|
|
132
|
+
name: webmock
|
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
description: This provides API interaction with the Folio ILS API
|
|
146
|
+
email:
|
|
147
|
+
- pmangiafico@stanford.edu
|
|
148
|
+
executables: []
|
|
149
|
+
extensions: []
|
|
150
|
+
extra_rdoc_files: []
|
|
151
|
+
files:
|
|
152
|
+
- ".rspec"
|
|
153
|
+
- ".rubocop.yml"
|
|
154
|
+
- ".rubocop/custom.yml"
|
|
155
|
+
- ".rubocop_todo.yml"
|
|
156
|
+
- ".standard.yml"
|
|
157
|
+
- Gemfile
|
|
158
|
+
- Gemfile.lock
|
|
159
|
+
- LICENSE
|
|
160
|
+
- README.md
|
|
161
|
+
- Rakefile
|
|
162
|
+
- folio_client.gemspec
|
|
163
|
+
- lib/folio_client.rb
|
|
164
|
+
- lib/folio_client/authenticator.rb
|
|
165
|
+
- lib/folio_client/unexpected_response.rb
|
|
166
|
+
- lib/folio_client/version.rb
|
|
167
|
+
homepage: https://github.com/sul-dlss/folio_client
|
|
168
|
+
licenses: []
|
|
169
|
+
metadata:
|
|
170
|
+
homepage_uri: https://github.com/sul-dlss/folio_client
|
|
171
|
+
source_code_uri: https://github.com/sul-dlss/folio_client
|
|
172
|
+
changelog_uri: https://github.com/sul-dlss/folio_client/releases
|
|
173
|
+
rubygems_mfa_required: 'true'
|
|
174
|
+
post_install_message:
|
|
175
|
+
rdoc_options: []
|
|
176
|
+
require_paths:
|
|
177
|
+
- lib
|
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
|
+
requirements:
|
|
180
|
+
- - ">="
|
|
181
|
+
- !ruby/object:Gem::Version
|
|
182
|
+
version: 2.6.0
|
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
requirements: []
|
|
189
|
+
rubygems_version: 3.4.5
|
|
190
|
+
signing_key:
|
|
191
|
+
specification_version: 4
|
|
192
|
+
summary: Interface for interacting with the Folio ILS API.
|
|
193
|
+
test_files: []
|