almapi 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f2c26aa18fade1372b97275580085b9ad05a60a2f7e73dca141e65f6990045d
4
- data.tar.gz: b2e04d2a9f615f33db3c1802dd49894ddaa83397c629b73002080b6642478b48
3
+ metadata.gz: 8fae996cc6ba2691735a5acde3ce4a588a3ac5c0ecf840e688b71c57e0e1f6d1
4
+ data.tar.gz: 6375a09a9a8447e74668a7d553285ac3bf495e0aa5859373d6292d1b06f1621f
5
5
  SHA512:
6
- metadata.gz: 285d020a9b515fb8f28c77cc61e921460d60b4ab33d7c19bcdd0a6efb959f57ffbd233276ee6dff4399263e26dffb77a82bcedd2a56849770f2102e649b6ad89
7
- data.tar.gz: e7cdb29ad8984185b9c2b846f88afb09196c336f68ed7d35fab7b60f905a1245ab2308d17a1c4875ecd953bc26f808d278f41bd60732e7e9d9838d7d8b889d76
6
+ metadata.gz: 490cfab30075877e0faf4670b6bb65a12f338dd07d10e55a274f6e09cc75ec9206fec95ddc59c22d9c1f3a8012259aec2bda4c65cd25958b1a87b0823d2be255
7
+ data.tar.gz: b061fcb46452f5b56fc9924a0df40a711f8a1b9da4b1c28367aff234da74f685017e926354639d7458d8212d7714b36680175f7f883ec02ff7c91cc0884b3b4a
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This gem is used to handle Alma'a API call.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/almapi.svg)](https://badge.fury.io/rb/almapi)
6
+
5
7
  ## Installation
6
8
 
7
9
  Install the gem and add to the application's Gemfile by executing:
data/lib/almapi/almapi.rb CHANGED
@@ -3,98 +3,106 @@
3
3
  require 'faraday'
4
4
  require 'faraday/follow_redirects'
5
5
  # Class Almapi handles Alma's API call
6
- class Almapi::Api
7
-
8
- # Reads the key for API calls.
9
- #
10
- # @return [String] the API key
11
- attr_reader :apikey
6
+ module Almapi
7
+ class Api
8
+ # Reads the key for API calls.
9
+ #
10
+ # @return [String] the API key
11
+ attr_reader :apikey
12
12
 
13
- # Reads the URI base for API calls.
14
- #
15
- # @return [String] the URI base
16
- attr_reader :uri_base
13
+ # Reads the URI base for API calls.
14
+ #
15
+ # @return [String] the URI base
16
+ attr_reader :uri_base
17
17
 
18
- # Faraday object to handle API calls.
19
- #
20
- # @return [Object] the Faraday conn object
21
- attr_reader :conn
18
+ # Faraday object to handle API calls.
19
+ #
20
+ # @return [Object] the Faraday conn object
21
+ attr_reader :conn
22
22
 
23
- # Initializes a new Almapi object and instance
24
- # variable @apikey, @uri_base and @conn
25
- # that is a Faraday connexion.
26
- #
27
- # @param apikey : API key to be used in API call
28
- # @param uri_base : base URI for API call
29
- def initialize(apikey, uri_base)
30
- @apikey = apikey
31
- @uri_base = uri_base
32
- @conn =
33
- Faraday.new do |f|
34
- f.response :follow_redirects
35
- end
36
- end
23
+ # Initializes a new Almapi object and instance
24
+ # variable @apikey, @uri_base and @conn
25
+ # that is a Faraday connexion.
26
+ #
27
+ # @param apikey : API key to be used in API call
28
+ # @param uri_base : base URI for API call
29
+ def initialize(apikey, uri_base)
30
+ @apikey = apikey
31
+ @uri_base = uri_base
32
+ headers = {
33
+ "Authorization" => "apikey #{@apikey}",
34
+ "Content-Type" => "application/xml",
35
+ }
36
+ @conn =
37
+ Faraday.new(@uri_base, headers: headers) do |f|
38
+ f.response :follow_redirects
39
+ end
40
+ end
41
+
42
+ # Handles a GET request creating the complete URI.
43
+ # It handles the general case, the case of barcode use for items and
44
+ # the case of analytics.
45
+ # If analytics, handles the resumption_token and limit is set to 1000
46
+ # which is the maximum.
47
+ #
48
+ # @param resource [String] mandatory : the part of the URI specifying the access point.
49
+ # <b>EXCEPT for analytics and barcode</b>, it must not include "?" for it adds "?apikey" automatically.
50
+ # If analytics, resource must include the report name.
51
+ # If barcode, resource must include the barcode value.
52
+ # @param resumption_token [String] : resumption token for an analytics call.
53
+ # @return [Response] : the resulting response
54
+ def get(resource, resumption_token = "")
55
+ url_api =
56
+ if resource.include?("analytics") # API call to Analytics entry point
57
+ "#{@uri_base}{resource}&limit=1000&#{resumption_token}"
58
+ # elsif resource.include?("barcode") # API call to items entry point with barcode
59
+ # "#{@uri_base}#{resource}"
60
+ else
61
+ "#{@uri_base}#{resource}" # All other cases
62
+ end
37
63
 
38
- # Handles a GET request creating the complete URI.
39
- # It handles the general case, the case of barcode use for items and
40
- # the case of analytics.
41
- # If analytics, handles the resumption_token and limit is set to 1000
42
- # which is the maximum.
43
- #
44
- # @param resource [String] mandatory : the part of the URI specifying the access point.
45
- # <b>EXCEPT for analytics and barcode</b>, it must not include "?" for it adds "?apikey" automatically.
46
- # If analytics, resource must include the report name.
47
- # If barcode, resource must include the barcode value.
48
- # @param resumption_token [String] : resumption token for an analytics call.
49
- # @return [Response] : the resulting response
50
- def get(resource, resumption_token = "")
51
- url_api =
52
- if resource.include?("analytics") # API call to Analytics entry point
53
- "#{@uri_base}{resource}&limit=1000&apikey=#{@apikey}&#{resumption_token}"
54
- elsif resource.include?("barcode") # API call to items entry point with barcode
55
- "#{@uri_base}#{resource}&apikey=#{@apikey}"
56
- else
57
- "#{@uri_base}#{resource}?apikey=#{@apikey}" # All other cases
58
- end
59
-
60
64
  handle_response(@conn.get(url_api))
65
+ end
61
66
 
62
- end
67
+ # Handles a POST request creating the complete URI.
68
+ #
69
+ # @param resource [String] mandatory : the part of the URI specifying the access point.
70
+ # Must not include "?" for it adds "?apikey" automatically.
71
+ # @param data [String] : an XML string containing data to post.
72
+ # @return [Response] : the resulting response
73
+ def post(resource, data)
74
+ url_api = resource.to_s
75
+ handle_response(@conn.post(url_api, data.to_s))
76
+ end
63
77
 
64
- # Handles a POST request creating the complete URI.
65
- #
66
- # @param resource [String] mandatory : the part of the URI specifying the access point.
67
- # Must not include "?" for it adds "?apikey" automatically.
68
- # @param data [String] : an XML string containing data to post.
69
- # @return [Response] : the resulting response
70
- def post(resource, data)
71
- url_api = "#{resource}?apikey=#{@apikey}"
72
- handle_response(@conn.post(url_api, data.to_s, "Content-Type" => 'application/xml'))
73
- end
78
+ # Handles a PUT request creating the complete URI.
79
+ #
80
+ # @param resource [String] mandatory : the part of the URI specifying the access point.
81
+ # Must not include "?" for it adds "?apikey" automatically.
82
+ # @param data [String] : an XML string containing data to put.
83
+ # @return [Response] : the resulting response. If error occurs, raises an AlmapiError
84
+ def put(resource, data)
85
+ url_api = resource.to_s
86
+ begin
87
+ handle_response(@conn.put(url_api, data.to_s))
88
+ rescue StandardError => e
89
+ puts e
90
+ end
91
+ end
74
92
 
75
- # Handles a PUT request creating the complete URI.
76
- #
77
- # @param resource [String] mandatory : the part of the URI specifying the access point.
78
- # Must not include "?" for it adds "?apikey" automatically.
79
- # @param data [String] : an XML string containing data to put.
80
- # @return [Response] : the resulting response. If error occurs, raises an AlmapiError
81
- def put(resource, data)
82
- url_api = "#{resource}?apikey=#{@apikey}"
83
- handle_response(@conn.put(url_api, data.to_s, "Content-Type" => 'application/xml'))
84
- end
93
+ # Handles a DELETE request creating the complete URI.
94
+ #
95
+ # @param resource [String] mandatory : the part of the URI specifying the access point.
96
+ # Must not include "?" for it adds "?apikey" automatically.
97
+ # @param data [String] : an XML string containing data to put.
98
+ # @return [Response] : the resulting response. If error occurs, raises an AlmapiError
99
+ def delete(resource, _data)
100
+ url_api = resource.to_s
101
+ handle_response(@conn.delete(url_api))
102
+ end
85
103
 
86
- # Handles a DELETE request creating the complete URI.
87
- #
88
- # @param resource [String] mandatory : the part of the URI specifying the access point.
89
- # Must not include "?" for it adds "?apikey" automatically.
90
- # @param data [String] : an XML string containing data to put.
91
- # @return [Response] : the resulting response. If error occurs, raises an AlmapiError
92
- def put(resource, data)
93
- url_api = "#{resource}?apikey=#{@apikey}"
94
- handle_response(@conn.put(url_api, data.to_s, "Content-Type" => 'application/xml'))
95
- end
104
+ private
96
105
 
97
- private
98
106
  # [Private] handles the response and decides to raise AlmapiError if necessary
99
107
  #
100
108
  # @param response [Response] mandatory : the response of the API call
@@ -103,11 +111,11 @@ class Almapi::Api
103
111
  case response.status
104
112
  when 200
105
113
  # Success
106
- return response
114
+ response
107
115
  else
108
116
  # Request has been correctly handled but cannot succeed
109
- raise Almapi::AlmapiError.new("AlmapiError : #{response.status} -> #{response.body}")
117
+ raise Almapi::AlmapiError, "AlmapiError : #{response.status} -> #{response.body}"
110
118
  end
111
119
  end
120
+ end
112
121
  end
113
-
@@ -1,11 +1,15 @@
1
- # Class AlmapiError handles Alma's API call errors
2
- class Almapi::AlmapiError < StandardError
3
- # Initializes a new AlmapiError object
4
- #
5
- # @param msg [String] : error message
6
- # @param exception_type [String] : exception type.
7
- def initialize(msg="This is an AlmpiError", exception_type="AlmpiError")
8
- @exception_type = exception_type
9
- super(msg) # Calling initialize in StandardError
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ # Class AlmapiError handles Alma's API call errors
4
+ module Almapi
5
+ class AlmapiError < StandardError
6
+ # Initializes a new AlmapiError object
7
+ #
8
+ # @param msg [String] : error message
9
+ # @param exception_type [String] : exception type.
10
+ def initialize(msg = "This is an AlmpiError", exception_type = "AlmpiError")
11
+ @exception_type = exception_type
12
+ super(msg) # Calling initialize in StandardError
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Almapi
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/almapi.rb CHANGED
@@ -7,5 +7,4 @@ require "almapi/almapi"
7
7
  # Module Almapi handles Alma's API call and errors
8
8
  # @author jszenb
9
9
  module Almapi
10
-
11
- end
10
+ end
metadata CHANGED
@@ -1,99 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jszenb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-04 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.4'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.63'
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: '0'
36
+ version: 1.63.2
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.63'
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: 1.63.2
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rubocop-performance
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - ">="
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
53
+ version: '1.21'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ">="
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: '1.21'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: yard
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ">="
65
+ - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0'
67
+ version: 0.9.36
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - ">="
72
+ - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0'
74
+ version: 0.9.36
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: faraday
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - ">="
79
+ - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: '2.9'
76
82
  type: :runtime
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - ">="
86
+ - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '0'
88
+ version: '2.9'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: faraday-follow_redirects
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - ">="
93
+ - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '0'
95
+ version: 0.3.0
90
96
  type: :runtime
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - ">="
100
+ - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '0'
102
+ version: 0.3.0
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: zeitwerk
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
153
  - !ruby/object:Gem::Version
148
154
  version: '0'
149
155
  requirements: []
150
- rubygems_version: 3.4.10
156
+ rubygems_version: 3.5.9
151
157
  signing_key:
152
158
  specification_version: 4
153
159
  summary: Gestion des appels à l'API web Alma.