almapi 0.1.5 → 0.1.7

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: 0f2c26aa18fade1372b97275580085b9ad05a60a2f7e73dca141e65f6990045d
4
- data.tar.gz: b2e04d2a9f615f33db3c1802dd49894ddaa83397c629b73002080b6642478b48
3
+ metadata.gz: e2595f89d0085997b7725770d054dcdbd80f56dc3c57fbd3c28a6655f70def3e
4
+ data.tar.gz: edb1857f61ab8d66c891c7e201e7cd269f3617e193e6aa184d4c341fe167816f
5
5
  SHA512:
6
- metadata.gz: 285d020a9b515fb8f28c77cc61e921460d60b4ab33d7c19bcdd0a6efb959f57ffbd233276ee6dff4399263e26dffb77a82bcedd2a56849770f2102e649b6ad89
7
- data.tar.gz: e7cdb29ad8984185b9c2b846f88afb09196c336f68ed7d35fab7b60f905a1245ab2308d17a1c4875ecd953bc26f808d278f41bd60732e7e9d9838d7d8b889d76
6
+ metadata.gz: 2c7b704e6e58e721c1ab6c6bb531fd60096c928adca37451e79615352d6b10bcce87bf85464a84e4ba6fcefe03fb99645f52c7fd2cc97e7e73921f0ee88941e2
7
+ data.tar.gz: 619689dd130c5c710c17278e117f596b2d807652de3cf212bc9e81150b2a190ab3449acf462a501ce3a9efc65a62319968e385f6f6dfa19cede7de550ba20e23
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,107 @@
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
+ puts url_api
87
+ begin
88
+ handle_response(@conn.put(url_api, data.to_s, "Content-Type" => "application/xml"))
89
+ rescue StandardError => e
90
+ puts e
91
+ end
92
+ end
74
93
 
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
94
+ # Handles a DELETE request creating the complete URI.
95
+ #
96
+ # @param resource [String] mandatory : the part of the URI specifying the access point.
97
+ # Must not include "?" for it adds "?apikey" automatically.
98
+ # @param data [String] : an XML string containing data to put.
99
+ # @return [Response] : the resulting response. If error occurs, raises an AlmapiError
100
+ def delete(resource, _data)
101
+ url_api = resource.to_s
102
+ handle_response(@conn.delete(url_api))
103
+ end
85
104
 
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
105
+ private
96
106
 
97
- private
98
107
  # [Private] handles the response and decides to raise AlmapiError if necessary
99
108
  #
100
109
  # @param response [Response] mandatory : the response of the API call
@@ -103,11 +112,12 @@ class Almapi::Api
103
112
  case response.status
104
113
  when 200
105
114
  # Success
106
- return response
115
+ response
107
116
  else
108
117
  # Request has been correctly handled but cannot succeed
109
- raise Almapi::AlmapiError.new("AlmapiError : #{response.status} -> #{response.body}")
118
+ raise Almapi::AlmapiError, "AlmapiError : #{response.status} -> #{response.body}"
119
+ p @conn
110
120
  end
111
121
  end
122
+ end
112
123
  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.7"
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.7
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.