almapi 0.1.4 → 0.1.5

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: c13af6e25b9fe65106cdaedb7bed17ff657f74930a637c44acae69dd122a5bda
4
- data.tar.gz: 99542e131e8918f9e1deeae293bd49607f1da6528330de98f694faecc8a76214
3
+ metadata.gz: 0f2c26aa18fade1372b97275580085b9ad05a60a2f7e73dca141e65f6990045d
4
+ data.tar.gz: b2e04d2a9f615f33db3c1802dd49894ddaa83397c629b73002080b6642478b48
5
5
  SHA512:
6
- metadata.gz: 9b0f3e74341c24efbffd556998dbe2ac1e9018c63d5eeab33fc8c82ef068125561e94ff5417ae7cd417dff45b2236fb3de2bd21e9b6c95eabb8ce64021f5d1a2
7
- data.tar.gz: 764becdc44a2abc5b98eeebda08c22e8d5f552c5cb47307354a662f3fb79b8d74f9051111001a618ed7da5228243fa07178bd34601c6d98e468e79d9e551a5f6
6
+ metadata.gz: 285d020a9b515fb8f28c77cc61e921460d60b4ab33d7c19bcdd0a6efb959f57ffbd233276ee6dff4399263e26dffb77a82bcedd2a56849770f2102e649b6ad89
7
+ data.tar.gz: e7cdb29ad8984185b9c2b846f88afb09196c336f68ed7d35fab7b60f905a1245ab2308d17a1c4875ecd953bc26f808d278f41bd60732e7e9d9838d7d8b889d76
data/CHANGELOG.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.4] - 2024-04-04
3
+ ## [0.1.5] - 2024-04-04
4
4
 
5
5
  - Still trying to require_relative error (learning to create gem so may take a few versions :) .
6
6
 
7
- ## [0.1.1] to [0.1.3]- 2024-04-04
7
+ ## [0.1.1] to [0.1.4]- 2024-04-04
8
8
 
9
9
  - Correct require_relative error.
10
10
 
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "almapi"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday/follow_redirects'
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
12
+
13
+ # Reads the URI base for API calls.
14
+ #
15
+ # @return [String] the URI base
16
+ attr_reader :uri_base
17
+
18
+ # Faraday object to handle API calls.
19
+ #
20
+ # @return [Object] the Faraday conn object
21
+ attr_reader :conn
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
37
+
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
+ handle_response(@conn.get(url_api))
61
+
62
+ end
63
+
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
74
+
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
85
+
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
96
+
97
+ private
98
+ # [Private] handles the response and decides to raise AlmapiError if necessary
99
+ #
100
+ # @param response [Response] mandatory : the response of the API call
101
+ # @return [Response || AlmapiError] : the resulting response if the API call succeeded, else AlmapiError
102
+ def handle_response(response)
103
+ case response.status
104
+ when 200
105
+ # Success
106
+ return response
107
+ else
108
+ # Request has been correctly handled but cannot succeed
109
+ raise Almapi::AlmapiError.new("AlmapiError : #{response.status} -> #{response.body}")
110
+ end
111
+ end
112
+ end
113
+
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Almapi
4
+ VERSION = "0.1.5"
5
+ end
data/lib/almapi.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "almapi/version"
4
+ require "almapi/almapi_error"
5
+ require "almapi/almapi"
6
+
7
+ # Module Almapi handles Alma's API call and errors
8
+ # @author jszenb
9
+ module Almapi
10
+
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jszenb
@@ -115,17 +115,15 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".rspec"
119
- - ".rubocop-http---relaxed-ruby-style-rubocop-yml"
120
- - ".rubocop.yml"
121
118
  - CHANGELOG.md
122
119
  - CODE_OF_CONDUCT.md
123
- - Gemfile
124
- - Gemfile.lock
125
- - LICENSE.txt
126
120
  - README.md
127
- - Rakefile
128
- - sig/almapi.rbs
121
+ - bin/console
122
+ - bin/setup
123
+ - lib/almapi.rb
124
+ - lib/almapi/almapi.rb
125
+ - lib/almapi/almapi_error.rb
126
+ - lib/almapi/version.rb
129
127
  homepage: https://rubygems.org/gems/almapi.
130
128
  licenses:
131
129
  - MIT
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,153 +0,0 @@
1
- # Relaxed.Ruby.Style
2
- ## Version 2.5
3
-
4
- Style/Alias:
5
- Enabled: false
6
- StyleGuide: https://relaxed.ruby.style/#stylealias
7
-
8
- Style/AsciiComments:
9
- Enabled: false
10
- StyleGuide: https://relaxed.ruby.style/#styleasciicomments
11
-
12
- Style/BeginBlock:
13
- Enabled: false
14
- StyleGuide: https://relaxed.ruby.style/#stylebeginblock
15
-
16
- Style/BlockDelimiters:
17
- Enabled: false
18
- StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
19
-
20
- Style/CommentAnnotation:
21
- Enabled: false
22
- StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
23
-
24
- Style/Documentation:
25
- Enabled: false
26
- StyleGuide: https://relaxed.ruby.style/#styledocumentation
27
-
28
- Layout/DotPosition:
29
- Enabled: false
30
- StyleGuide: https://relaxed.ruby.style/#layoutdotposition
31
-
32
- Style/DoubleNegation:
33
- Enabled: false
34
- StyleGuide: https://relaxed.ruby.style/#styledoublenegation
35
-
36
- Style/EndBlock:
37
- Enabled: false
38
- StyleGuide: https://relaxed.ruby.style/#styleendblock
39
-
40
- Style/FormatString:
41
- Enabled: false
42
- StyleGuide: https://relaxed.ruby.style/#styleformatstring
43
-
44
- Style/IfUnlessModifier:
45
- Enabled: false
46
- StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
47
-
48
- Style/Lambda:
49
- Enabled: false
50
- StyleGuide: https://relaxed.ruby.style/#stylelambda
51
-
52
- Style/ModuleFunction:
53
- Enabled: false
54
- StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
55
-
56
- Style/MultilineBlockChain:
57
- Enabled: false
58
- StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
59
-
60
- Style/NegatedIf:
61
- Enabled: false
62
- StyleGuide: https://relaxed.ruby.style/#stylenegatedif
63
-
64
- Style/NegatedWhile:
65
- Enabled: false
66
- StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
67
-
68
- Style/NumericPredicate:
69
- Enabled: false
70
- StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate
71
-
72
- Style/ParallelAssignment:
73
- Enabled: false
74
- StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
75
-
76
- Style/PercentLiteralDelimiters:
77
- Enabled: false
78
- StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
79
-
80
- Style/PerlBackrefs:
81
- Enabled: false
82
- StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
83
-
84
- Style/Semicolon:
85
- Enabled: false
86
- StyleGuide: https://relaxed.ruby.style/#stylesemicolon
87
-
88
- Style/SignalException:
89
- Enabled: false
90
- StyleGuide: https://relaxed.ruby.style/#stylesignalexception
91
-
92
- Style/SingleLineBlockParams:
93
- Enabled: false
94
- StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
95
-
96
- Style/SingleLineMethods:
97
- Enabled: false
98
- StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
99
-
100
- Layout/SpaceBeforeBlockBraces:
101
- Enabled: false
102
- StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
103
-
104
- Layout/SpaceInsideParens:
105
- Enabled: false
106
- StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
107
-
108
- Style/SpecialGlobalVars:
109
- Enabled: false
110
- StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
111
-
112
- Style/StringLiterals:
113
- Enabled: false
114
- StyleGuide: https://relaxed.ruby.style/#stylestringliterals
115
-
116
- Style/TrailingCommaInArguments:
117
- Enabled: false
118
- StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
119
-
120
- Style/TrailingCommaInArrayLiteral:
121
- Enabled: false
122
- StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
123
-
124
- Style/TrailingCommaInHashLiteral:
125
- Enabled: false
126
- StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
127
-
128
- Style/SymbolArray:
129
- Enabled: false
130
- StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
131
-
132
- Style/WhileUntilModifier:
133
- Enabled: false
134
- StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
135
-
136
- Style/WordArray:
137
- Enabled: false
138
- StyleGuide: https://relaxed.ruby.style/#stylewordarray
139
-
140
- Lint/AmbiguousRegexpLiteral:
141
- Enabled: false
142
- StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
143
-
144
- Lint/AssignmentInCondition:
145
- Enabled: false
146
- StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
147
-
148
- Layout/LineLength:
149
- Enabled: false
150
-
151
- Metrics:
152
- Enabled: false
153
-
data/.rubocop.yml DELETED
@@ -1,75 +0,0 @@
1
- # Utiliser une version (peu) édulcorée des règles de base de rubocop
2
- inherit_from:
3
- - http://relaxed.ruby.style/rubocop.yml
4
-
5
- # Ajoute des règles de performance aux règles de base de Rubocop
6
- require:
7
- - rubocop-performance
8
-
9
- AllCops:
10
- # Chaque version de rubocop ajoute de nouvelles règles.
11
- # Ceci les active par défaut.
12
- NewCops: enable
13
- DisplayStyleGuide: true
14
- DisplayCopNames: true
15
- Exclude:
16
- - "bin/*"
17
- - "vendor/**/*"
18
-
19
- # Certains fichiers sont de gigantesques block.
20
- # Ne pas les compter.
21
- Metrics/BlockLength:
22
- Exclude:
23
- - "spec/**/*.rb"
24
- - "Guardfile"
25
- - "vendor/bundle"
26
- - "*.gemspec"
27
-
28
- # Les règles qui vont suivre sont des règles de style
29
- # permettant de split les lignes.
30
- Layout/DotPosition:
31
- Enabled: true
32
- EnforcedStyle: trailing
33
-
34
- Style/TrailingCommaInArrayLiteral:
35
- Enabled: true
36
- EnforcedStyleForMultiline: comma
37
-
38
- Style/TrailingCommaInHashLiteral:
39
- Enabled: true
40
- EnforcedStyleForMultiline: comma
41
-
42
- Layout/MultilineArrayLineBreaks:
43
- Enabled: true
44
-
45
- Layout/MultilineHashKeyLineBreaks:
46
- Enabled: true
47
-
48
- Layout/MultilineMethodArgumentLineBreaks:
49
- Enabled: true
50
-
51
- Layout/FirstArrayElementLineBreak:
52
- Enabled: true
53
-
54
- Layout/FirstHashElementLineBreak:
55
- Enabled: true
56
-
57
- Layout/FirstMethodArgumentLineBreak:
58
- Enabled: true
59
-
60
- Layout/MultilineAssignmentLayout:
61
- Enabled: true
62
-
63
- # Ajoute une limite maximum à la longueur d'une ligne
64
- Layout/LineLength:
65
- Enabled: true
66
- Max: 120
67
- # Cette option fait en sorte que Rubocop essaye d'ajouter
68
- # des retours à la ligne là où il faut.
69
- AutoCorrect: true
70
- Exclude:
71
- - Gemfile
72
- - Guardfile
73
-
74
- Gemspec/DevelopmentDependencies:
75
- EnforcedStyle: gemspec
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in almapi.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
data/Gemfile.lock DELETED
@@ -1,80 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- almapi (0.1.4)
5
- faraday
6
- faraday-follow_redirects
7
- zeitwerk (~> 2)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- ast (2.4.2)
13
- diff-lcs (1.5.1)
14
- faraday (2.9.0)
15
- faraday-net_http (>= 2.0, < 3.2)
16
- faraday-follow_redirects (0.3.0)
17
- faraday (>= 1, < 3)
18
- faraday-net_http (3.1.0)
19
- net-http
20
- json (2.7.1)
21
- language_server-protocol (3.17.0.3)
22
- net-http (0.4.1)
23
- uri
24
- parallel (1.24.0)
25
- parser (3.3.0.5)
26
- ast (~> 2.4.1)
27
- racc
28
- racc (1.7.3)
29
- rainbow (3.1.1)
30
- rake (13.1.0)
31
- regexp_parser (2.9.0)
32
- rexml (3.2.6)
33
- rspec (3.13.0)
34
- rspec-core (~> 3.13.0)
35
- rspec-expectations (~> 3.13.0)
36
- rspec-mocks (~> 3.13.0)
37
- rspec-core (3.13.0)
38
- rspec-support (~> 3.13.0)
39
- rspec-expectations (3.13.0)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.13.0)
42
- rspec-mocks (3.13.0)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.13.0)
45
- rspec-support (3.13.1)
46
- rubocop (1.62.1)
47
- json (~> 2.3)
48
- language_server-protocol (>= 3.17.0)
49
- parallel (~> 1.10)
50
- parser (>= 3.3.0.2)
51
- rainbow (>= 2.2.2, < 4.0)
52
- regexp_parser (>= 1.8, < 3.0)
53
- rexml (>= 3.2.5, < 4.0)
54
- rubocop-ast (>= 1.31.1, < 2.0)
55
- ruby-progressbar (~> 1.7)
56
- unicode-display_width (>= 2.4.0, < 3.0)
57
- rubocop-ast (1.31.2)
58
- parser (>= 3.3.0.4)
59
- rubocop-performance (1.20.2)
60
- rubocop (>= 1.48.1, < 2.0)
61
- rubocop-ast (>= 1.30.0, < 2.0)
62
- ruby-progressbar (1.13.0)
63
- unicode-display_width (2.5.0)
64
- uri (0.13.0)
65
- yard (0.9.36)
66
- zeitwerk (2.6.13)
67
-
68
- PLATFORMS
69
- x86_64-linux
70
-
71
- DEPENDENCIES
72
- almapi!
73
- rake (~> 13.0)
74
- rspec
75
- rubocop
76
- rubocop-performance
77
- yard
78
-
79
- BUNDLED WITH
80
- 2.4.10
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2024 jszenb
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
data/sig/almapi.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Almapi
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end