alma_api 1.0.0 → 1.0.1
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 +4 -4
- data/README.md +26 -5
- data/lib/alma_api/client.rb +11 -11
- data/lib/alma_api/configuration.rb +20 -4
- data/lib/alma_api/version.rb +1 -1
- data/lib/alma_api.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37b01a05c5d0872a429c9b7b79038690be884cce2ffdaf124218125f5adb73da
|
4
|
+
data.tar.gz: 3c986e855de66749077a6c203f0f47adb1076d3c8b755262aadb59c73462c549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04e5a266e16154d64e59e4a93cd8c7a46c6b27c85cc6425256f5485655193cabba0ae1be4b5a8cc08f72751495b95aa73f9188d9d6674b99e89cf1ed7678be96
|
7
|
+
data.tar.gz: 593b7a0d3ccc3140bca25059cb9ce97c23c2dfbf0e9740b0ce94e0c3cb2f90883e430fa8d4d06f22c3a1377ac0f472a247a797acaaa11eb2ff4dcaaf4c7351f3
|
data/README.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
# Alma REST API Ruby library
|
1
|
+
# Alma REST API Ruby library
|
2
|
+
|
3
|
+

|
4
|
+
[](https://codeclimate.com/github/ubpb/alma_api/test_coverage)
|
5
|
+
[](https://codeclimate.com/github/ubpb/alma_api/maintainability)
|
6
|
+
[](https://badge.fury.io/rb/alma_api)
|
7
|
+
[](LICENSE)
|
2
8
|
|
3
9
|
This is a simple Ruby library that acts as a wrapper for the
|
4
10
|
[Ex Libris Alma REST APIs](https://developers.exlibrisgroup.com/alma/apis/).
|
@@ -35,10 +41,25 @@ configuration = AlmaApi::Configuration.new(
|
|
35
41
|
)
|
36
42
|
```
|
37
43
|
|
38
|
-
1. `api_key`
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
1. `api_key`
|
45
|
+
Add your Alma API key here.
|
46
|
+
2. `base_url`
|
47
|
+
Add the base URL to be used for each request. Ex Libris provides different API gateways for different geographical locations. See [the documentation here](https://developers.exlibrisgroup.com/alma/apis/#calling) for more information. This parameter is optional and defaults to the Alma API Gateway for Europe: `https://api-eu.hosted.exlibrisgroup.com/almaws/v1`.
|
48
|
+
|
49
|
+
You can use a `Symbol` as a shortcut to set the `base_url` for one of the preconfigured gateways `:na` (North America), `:eu` (Europe), `:ap` (Asia-Pacific), `:ca` (Canada), `:cn` (China).
|
50
|
+
|
51
|
+
For example, to set the `base_url` for the canadian gateway, use
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
configuration = AlmaApi::Configuration.new(
|
55
|
+
base_url: :ca,
|
56
|
+
...
|
57
|
+
)
|
58
|
+
```
|
59
|
+
3. `default_format`
|
60
|
+
The default format to use for each request. The client supports `json` and `xml`. The default is `json`.
|
61
|
+
4. `language`
|
62
|
+
The language used by Alma for error messages and textual information. The default is English (`en`). To change this, set this parameter to any 2-letter language code that is supported and enabled in Alma (see the mapping table "Institution Languages" in Alma).
|
42
63
|
|
43
64
|
### Creating a client
|
44
65
|
|
data/lib/alma_api/client.rb
CHANGED
@@ -71,21 +71,21 @@ module AlmaApi
|
|
71
71
|
set_remaining_api_calls(response)
|
72
72
|
parse_response_body(response.body)
|
73
73
|
rescue Faraday::Error => e
|
74
|
-
|
74
|
+
handle_faraday_error(e)
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle_faraday_error(error)
|
78
|
+
error_response = parse_error_response_body(error.response[:body])
|
75
79
|
|
76
|
-
case
|
80
|
+
case error_response[:error_code]
|
77
81
|
when *GATEWAY_ERROR_CODES
|
78
|
-
raise GatewayError.new(
|
82
|
+
raise GatewayError.new(error_response[:error_message], error_response[:error_code])
|
79
83
|
else
|
80
|
-
case
|
84
|
+
case error.response[:status]
|
81
85
|
when 400..499
|
82
|
-
raise LogicalError.new(
|
83
|
-
|
84
|
-
raise ServerError.new(
|
85
|
-
else # this should not happen
|
86
|
-
# :nocov:
|
87
|
-
raise ServerError.new(error[:error_message], error[:error_code])
|
88
|
-
# :nocov:
|
86
|
+
raise LogicalError.new(error_response[:error_message], error_response[:error_code])
|
87
|
+
else
|
88
|
+
raise ServerError.new(error_response[:error_message], error_response[:error_code])
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -1,6 +1,17 @@
|
|
1
1
|
module AlmaApi
|
2
2
|
class Configuration
|
3
3
|
|
4
|
+
GATEWAYS = {
|
5
|
+
na: "https://api-na.hosted.exlibrisgroup.com/almaws/v1", # North America
|
6
|
+
eu: "https://api-eu.hosted.exlibrisgroup.com/almaws/v1", # Europe
|
7
|
+
ap: "https://api-ap.hosted.exlibrisgroup.com/almaws/v1", # Asia-Pacific
|
8
|
+
ca: "https://api-ca.hosted.exlibrisgroup.com/almaws/v1", # Canada
|
9
|
+
cn: "https://api-cn.hosted.exlibrisgroup.cn/almaws/v1" # China
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
DEFAULT_FORMAT = "json".freeze
|
13
|
+
DEFAULT_LANGUAGE = "en".freeze
|
14
|
+
|
4
15
|
attr_reader :api_key,
|
5
16
|
:base_url,
|
6
17
|
:default_format,
|
@@ -18,16 +29,21 @@ module AlmaApi
|
|
18
29
|
end
|
19
30
|
|
20
31
|
def base_url=(value)
|
21
|
-
|
22
|
-
|
32
|
+
if value.is_a?(Symbol)
|
33
|
+
raise ArgumentError, "Invalid gateway: #{value}" unless GATEWAYS.keys.include?(value.to_sym)
|
34
|
+
|
35
|
+
@base_url = GATEWAYS[value]
|
36
|
+
else
|
37
|
+
@base_url = value.presence || GATEWAYS[:eu]
|
38
|
+
end
|
23
39
|
end
|
24
40
|
|
25
41
|
def default_format=(value)
|
26
|
-
@default_format = AlmaApi.validate_format!(value) ||
|
42
|
+
@default_format = AlmaApi.validate_format!(value) || DEFAULT_FORMAT
|
27
43
|
end
|
28
44
|
|
29
45
|
def language=(value)
|
30
|
-
@language = value.presence ||
|
46
|
+
@language = value.presence || DEFAULT_LANGUAGE
|
31
47
|
end
|
32
48
|
|
33
49
|
end
|
data/lib/alma_api/version.rb
CHANGED
data/lib/alma_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alma_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René Sprotte
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,8 +86,8 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '3.11'
|
89
|
-
description:
|
90
|
-
email:
|
89
|
+
description:
|
90
|
+
email:
|
91
91
|
executables: []
|
92
92
|
extensions: []
|
93
93
|
extra_rdoc_files: []
|
@@ -103,7 +103,7 @@ homepage: http://github.com/ubpb/alma_api
|
|
103
103
|
licenses:
|
104
104
|
- MIT
|
105
105
|
metadata: {}
|
106
|
-
post_install_message:
|
106
|
+
post_install_message:
|
107
107
|
rdoc_options: []
|
108
108
|
require_paths:
|
109
109
|
- lib
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubygems_version: 3.4.10
|
122
|
-
signing_key:
|
122
|
+
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: A Ruby client library for the Ex Libris Alma REST APIs
|
125
125
|
test_files: []
|