alma_api 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -9
- 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: be075de2651cd726b827c48274a0a71338e21064cb33433597c9e09cafabdf41
|
4
|
+
data.tar.gz: 972119e4a07785159951b1a29f98636608d46c8ce2b8179465191ff3af3804d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc56000113b9aebc0987713e9ebc74a2e52144989fe66dedf6f9b2f8aa128bef2af402e07211a07abcb6bd20f35d480f2fe7beaaed0a4b1626661772a9826834
|
7
|
+
data.tar.gz: 42d7d770833351af4aea0f0bd26bf4920f46fc66ccbf081c079c2f1cb0707a660d27163cf2d3cbd0792e4570e7b7ab5e09163da78acf7f888a81f9608be821fe
|
data/README.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
# Alma REST API Ruby library
|
1
|
+
# Alma REST API Ruby library
|
2
|
+
|
3
|
+
![Tests](https://github.com/ubpb/alma_api/actions/workflows/tests.yml/badge.svg)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/fa479e542383d985dd13/test_coverage)](https://codeclimate.com/github/ubpb/alma_api/test_coverage)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/fa479e542383d985dd13/maintainability)](https://codeclimate.com/github/ubpb/alma_api/maintainability)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/alma_api.svg)](https://badge.fury.io/rb/alma_api)
|
7
|
+
[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](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
|
|
@@ -52,10 +73,10 @@ As a shortcut, you can call `AlmaApi.configure` to get the client instance. Note
|
|
52
73
|
|
53
74
|
```ruby
|
54
75
|
client = AlmaApi.configure do |config|
|
55
|
-
api_key
|
56
|
-
base_url
|
57
|
-
default_format
|
58
|
-
language
|
76
|
+
config.api_key = "..."
|
77
|
+
config.base_url = "..."
|
78
|
+
config.default_format = "..."
|
79
|
+
config.language = "..."
|
59
80
|
end
|
60
81
|
```
|
61
82
|
### Using the client
|
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.2
|
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:
|
11
|
+
date: 2024-01-15 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: []
|