almapi 0.1.5 → 0.1.6
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 +93 -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: 8fae996cc6ba2691735a5acde3ce4a588a3ac5c0ecf840e688b71c57e0e1f6d1
|
4
|
+
data.tar.gz: 6375a09a9a8447e74668a7d553285ac3bf495e0aa5859373d6292d1b06f1621f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 490cfab30075877e0faf4670b6bb65a12f338dd07d10e55a274f6e09cc75ec9206fec95ddc59c22d9c1f3a8012259aec2bda4c65cd25958b1a87b0823d2be255
|
7
|
+
data.tar.gz: b061fcb46452f5b56fc9924a0df40a711f8a1b9da4b1c28367aff234da74f685017e926354639d7458d8212d7714b36680175f7f883ec02ff7c91cc0884b3b4a
|
data/README.md
CHANGED
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
|
-
|
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
|
+
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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
|
-
|
114
|
+
response
|
107
115
|
else
|
108
116
|
# Request has been correctly handled but cannot succeed
|
109
|
-
raise Almapi::AlmapiError
|
117
|
+
raise Almapi::AlmapiError, "AlmapiError : #{response.status} -> #{response.body}"
|
110
118
|
end
|
111
119
|
end
|
120
|
+
end
|
112
121
|
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.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-
|
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.
|