alma_api 1.0.0 → 1.0.1

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: cbcf2ac797d9d76c1d536a4eba0d084033fe3993f98f55dd02120114ad9df5eb
4
- data.tar.gz: cf70240bb22810542d8ed2400e98eb656412cb1339eecb1605badd9a7019603c
3
+ metadata.gz: 37b01a05c5d0872a429c9b7b79038690be884cce2ffdaf124218125f5adb73da
4
+ data.tar.gz: 3c986e855de66749077a6c203f0f47adb1076d3c8b755262aadb59c73462c549
5
5
  SHA512:
6
- metadata.gz: 266823640ec75ba8962f163a80737ba9ec1f19cf70f4286ec88de278ea7ee9c4efdf9da5a0dad664ab3f918b82d690d41a9a67ccb4f4b8949db3ceb770accb6e
7
- data.tar.gz: 7fdd946b9040bea59f14ce74ad2457736290b9c31baa31b3b1ed443a5391dc2bff96a66fe0d0e23b208b03597c08eca236c778cb25349a15a60a0af0c31d9586
6
+ metadata.gz: 04e5a266e16154d64e59e4a93cd8c7a46c6b27c85cc6425256f5485655193cabba0ae1be4b5a8cc08f72751495b95aa73f9188d9d6674b99e89cf1ed7678be96
7
+ data.tar.gz: 593b7a0d3ccc3140bca25059cb9ce97c23c2dfbf0e9740b0ce94e0c3cb2f90883e430fa8d4d06f22c3a1377ac0f472a247a797acaaa11eb2ff4dcaaf4c7351f3
data/README.md CHANGED
@@ -1,4 +1,10 @@
1
- # Alma REST API Ruby library ![Tests](https://github.com/ubpb/alma_api/actions/workflows/tests.yml/badge.svg)
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` Add your Alma API key here.
39
- 2. `base_url` 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`.
40
- 3. `default_format` The default format to use for each request. The client supports `json` and `xml`. The default is `json`.
41
- 4. `language` 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).
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
 
@@ -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
- error = parse_error_response_body(e.response[:body])
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 error[:error_code]
80
+ case error_response[:error_code]
77
81
  when *GATEWAY_ERROR_CODES
78
- raise GatewayError.new(error[:error_message], error[:error_code])
82
+ raise GatewayError.new(error_response[:error_message], error_response[:error_code])
79
83
  else
80
- case e.response[:status]
84
+ case error.response[:status]
81
85
  when 400..499
82
- raise LogicalError.new(error[:error_message], error[:error_code])
83
- when 500..599
84
- raise ServerError.new(error[:error_message], error[:error_code])
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
- base_url = value.presence || "https://api-eu.hosted.exlibrisgroup.com/almaws/v1"
22
- @base_url = base_url&.ends_with?("/") ? base_url[0..-2] : base_url
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) || "json"
42
+ @default_format = AlmaApi.validate_format!(value) || DEFAULT_FORMAT
27
43
  end
28
44
 
29
45
  def language=(value)
30
- @language = value.presence || "en"
46
+ @language = value.presence || DEFAULT_LANGUAGE
31
47
  end
32
48
 
33
49
  end
@@ -1,3 +1,3 @@
1
1
  module AlmaApi
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
data/lib/alma_api.rb CHANGED
@@ -45,7 +45,7 @@ module AlmaApi
45
45
  end
46
46
 
47
47
  def validate_format!(format)
48
- case format = format&.to_s
48
+ case format = format.presence&.to_s
49
49
  when "json", "xml" then format
50
50
  when nil then nil
51
51
  else
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.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-10 00:00:00.000000000 Z
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: []