easyllama-client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/easyllama/client/version.rb +1 -1
- data/lib/easyllama/client.rb +7 -4
- data/lib/easyllama/learners.rb +27 -7
- data/lib/easyllama/locations.rb +5 -2
- data/lib/easyllama/trainings.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89c72f06cf5a96eb1435d7578385620ebd1867d16ff897203b59c9b38151026b
|
4
|
+
data.tar.gz: 2130a6de5397b3fe31b9e1966ae6c4f060cef422549e51a6ec311c9b1acd4788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26bb01a590bb52623b2652b3ad401c2b8030eeed0bb8d61b03749ca9eff32d20902f9b207dda6b8995e860cba05004f100e99deadbf5a290af5c0494b662bb62
|
7
|
+
data.tar.gz: 3c05919297b58408454ac74ec1d572859ab1adb7429e40e79f7b628fabdccf088be1b95aca38071a9f908ec73656ce95369c6b5b3740cbe1d1da7178f8a49541
|
data/lib/easyllama/client.rb
CHANGED
@@ -27,16 +27,19 @@ module EasyLlama
|
|
27
27
|
|
28
28
|
# Parses the response body and returns the value corresponding to the provided key.
|
29
29
|
# If the response is successful, returns the value for the key.
|
30
|
-
# If the response is unsuccessful, returns an error message.
|
30
|
+
# If the response is unsuccessful, returns an error code and message.
|
31
31
|
#
|
32
32
|
# @param response [Net::HTTPResponse] The HTTP response.
|
33
33
|
# @param key [String] The key to retrieve from the response body.
|
34
|
-
# @return [Object] The value corresponding to the key or
|
35
|
-
def
|
34
|
+
# @return [Object] The empty hash, parsed response body, value corresponding to the key or error code and message.
|
35
|
+
def parse_response(response, key = nil)
|
36
36
|
if response.is_a?(Net::HTTPSuccess)
|
37
|
+
return {} if response.body.nil?
|
38
|
+
return JSON.parse(response.body) if key.nil?
|
39
|
+
|
37
40
|
JSON.parse(response.body)[key]
|
38
41
|
else
|
39
|
-
{ 'error' => response.message }
|
42
|
+
{ 'code' => response.code, 'error' => response.message }
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
data/lib/easyllama/learners.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EasyLlama
|
4
4
|
class Client
|
5
|
+
# This class provides methods for interacting with the Easy Llama API for learners.
|
5
6
|
class Learners
|
6
7
|
class << self
|
7
8
|
# Sends a GET request to retrieve all learners.
|
@@ -9,7 +10,8 @@ module EasyLlama
|
|
9
10
|
# @return [Object] The learners or an error message.
|
10
11
|
def all
|
11
12
|
response = EasyLlama::Client.send_request(path: '/learners')
|
12
|
-
|
13
|
+
|
14
|
+
EasyLlama::Client.parse_response(response, 'learners')
|
13
15
|
end
|
14
16
|
|
15
17
|
# Sends a GET request to retrieve a learner by ID.
|
@@ -18,7 +20,8 @@ module EasyLlama
|
|
18
20
|
# @return [Object] The learner or an error message.
|
19
21
|
def find(id)
|
20
22
|
response = EasyLlama::Client.send_request(path: "/learners/#{id}")
|
21
|
-
|
23
|
+
|
24
|
+
EasyLlama::Client.parse_response(response, 'learner')
|
22
25
|
end
|
23
26
|
|
24
27
|
# Sends a POST request to create a learner.
|
@@ -27,7 +30,8 @@ module EasyLlama
|
|
27
30
|
# @return [Object] The created learner or an error message.
|
28
31
|
def create(learner_attributes = {})
|
29
32
|
response = EasyLlama::Client.send_request(path: '/learners', method: :post, body: learner_attributes)
|
30
|
-
|
33
|
+
|
34
|
+
EasyLlama::Client.parse_response(response, 'learner')
|
31
35
|
end
|
32
36
|
|
33
37
|
# Sends a PATCH request to update a learner by ID.
|
@@ -37,17 +41,33 @@ module EasyLlama
|
|
37
41
|
# @return [Object] The updated learner or an error message.
|
38
42
|
def update(id, learner_attributes = {})
|
39
43
|
response = EasyLlama::Client.send_request(path: "/learners/#{id}", method: :patch, body: learner_attributes)
|
40
|
-
|
44
|
+
|
45
|
+
EasyLlama::Client.parse_response(response, 'learner')
|
41
46
|
end
|
42
47
|
|
43
48
|
# Sends a POST request to assign a training to a learner.
|
44
49
|
#
|
45
50
|
# @param training_id [Integer] The ID of the training.
|
46
51
|
# @param learner_id [Integer] The ID of the learner.
|
47
|
-
# @return [Object] The assignment details or an error message.
|
52
|
+
# @return [Object] The training assignment details or an error message.
|
48
53
|
def assign_training_to_learner(training_id:, learner_id:)
|
49
|
-
response = EasyLlama::Client.send_request(
|
50
|
-
|
54
|
+
response = EasyLlama::Client.send_request(
|
55
|
+
path: "/learners/#{learner_id}/learner_trainings",
|
56
|
+
method: :post,
|
57
|
+
body: { learner_id:, training_id: }
|
58
|
+
)
|
59
|
+
|
60
|
+
EasyLlama::Client.parse_response(response)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Sends a DELETE request to archive a learner by ID.
|
64
|
+
#
|
65
|
+
# @param id [Integer] The ID of the learner.
|
66
|
+
# @return [Object] The updated learner or an error message.
|
67
|
+
def archive(id)
|
68
|
+
response = EasyLlama::Client.send_request(path: "/learners/#{id}", method: :delete)
|
69
|
+
|
70
|
+
EasyLlama::Client.parse_response(response)
|
51
71
|
end
|
52
72
|
end
|
53
73
|
end
|
data/lib/easyllama/locations.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EasyLlama
|
4
4
|
class Client
|
5
|
+
# This class provides methods for interacting with the Easy Llama API for locations.
|
5
6
|
class Locations
|
6
7
|
class << self
|
7
8
|
# Sends a GET request to retrieve all locations.
|
@@ -9,7 +10,8 @@ module EasyLlama
|
|
9
10
|
# @return [Object] The locations or an error message.
|
10
11
|
def all
|
11
12
|
response = EasyLlama::Client.send_request(path: '/locations')
|
12
|
-
|
13
|
+
|
14
|
+
EasyLlama::Client.parse_response(response, 'locations')
|
13
15
|
end
|
14
16
|
|
15
17
|
# Sends a POST request to create a location.
|
@@ -18,7 +20,8 @@ module EasyLlama
|
|
18
20
|
# @return [Object] The created location or an error message.
|
19
21
|
def create(location_attributes = {})
|
20
22
|
response = EasyLlama::Client.send_request(path: '/locations', method: :post, body: location_attributes)
|
21
|
-
|
23
|
+
|
24
|
+
EasyLlama::Client.parse_response(response, 'location')
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
data/lib/easyllama/trainings.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module EasyLlama
|
4
4
|
class Client
|
5
|
+
# This class provides methods for interacting with the Easy Llama API for trainings.
|
5
6
|
class Trainings
|
6
7
|
class << self
|
7
8
|
# Sends a GET request to retrieve all trainings.
|
@@ -9,7 +10,8 @@ module EasyLlama
|
|
9
10
|
# @return [Object] The trainings or an error message.
|
10
11
|
def all
|
11
12
|
response = EasyLlama::Client.send_request(path: '/trainings')
|
12
|
-
|
13
|
+
|
14
|
+
EasyLlama::Client.parse_response(response, 'trainings')
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|