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 +4 -4
- data/README.md +2 -0
- data/lib/almapi/almapi.rb +95 -85
- data/lib/almapi/almapi_error.rb +15 -11
- data/lib/almapi/version.rb +1 -1
- data/lib/almapi.rb +1 -2
- metadata +31 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2595f89d0085997b7725770d054dcdbd80f56dc3c57fbd3c28a6655f70def3e
|
4
|
+
data.tar.gz: edb1857f61ab8d66c891c7e201e7cd269f3617e193e6aa184d4c341fe167816f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c7b704e6e58e721c1ab6c6bb531fd60096c928adca37451e79615352d6b10bcce87bf85464a84e4ba6fcefe03fb99645f52c7fd2cc97e7e73921f0ee88941e2
|
7
|
+
data.tar.gz: 619689dd130c5c710c17278e117f596b2d807652de3cf212bc9e81150b2a190ab3449acf462a501ce3a9efc65a62319968e385f6f6dfa19cede7de550ba20e23
|
data/README.md
CHANGED
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
# Reads the URI base for API calls.
|
14
|
+
#
|
15
|
+
# @return [String] the URI base
|
16
|
+
attr_reader :uri_base
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
# Faraday object to handle API calls.
|
19
|
+
#
|
20
|
+
# @return [Object] the Faraday conn object
|
21
|
+
attr_reader :conn
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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
|
-
|
115
|
+
response
|
107
116
|
else
|
108
117
|
# Request has been correctly handled but cannot succeed
|
109
|
-
raise Almapi::AlmapiError
|
118
|
+
raise Almapi::AlmapiError, "AlmapiError : #{response.status} -> #{response.body}"
|
119
|
+
p @conn
|
110
120
|
end
|
111
121
|
end
|
122
|
+
end
|
112
123
|
end
|
113
|
-
|
data/lib/almapi/almapi_error.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
data/lib/almapi/version.rb
CHANGED
data/lib/almapi.rb
CHANGED
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.
|
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-
|
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: '
|
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: '
|
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:
|
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:
|
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: '
|
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: '
|
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:
|
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:
|
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: '
|
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: '
|
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:
|
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:
|
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.
|
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.
|