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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b275fa080c57dc300bb5d804413e54a90b69b04d58732db4e72286a03bc009f4
4
- data.tar.gz: 23255762cc3409dfd092ef45ec3e089b455ed6f43097ad0faa5b24749c8bee91
3
+ metadata.gz: 89c72f06cf5a96eb1435d7578385620ebd1867d16ff897203b59c9b38151026b
4
+ data.tar.gz: 2130a6de5397b3fe31b9e1966ae6c4f060cef422549e51a6ec311c9b1acd4788
5
5
  SHA512:
6
- metadata.gz: b59d2271d6987a6676cd7603dff54391d5dfbdd2793d7bf0133d2bec6950ba07ab19584f8289ca93fb6a491b6c7c5cb813b055d2f8d1750eaf827ad6da08af91
7
- data.tar.gz: 946e1fa2c7ddfbb15a588841e8114eb714fb94a3a89d433c7201cd4972a4be1d889be3f0b0548cb9aee23835474bbf01ab5a956596522cbe3cf22169ccf46799
6
+ metadata.gz: 26bb01a590bb52623b2652b3ad401c2b8030eeed0bb8d61b03749ca9eff32d20902f9b207dda6b8995e860cba05004f100e99deadbf5a290af5c0494b662bb62
7
+ data.tar.gz: 3c05919297b58408454ac74ec1d572859ab1adb7429e40e79f7b628fabdccf088be1b95aca38071a9f908ec73656ce95369c6b5b3740cbe1d1da7178f8a49541
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Easyllama
4
4
  module Client
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
@@ -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 an error message.
35
- def response_body(response, key)
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
 
@@ -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
- EasyLlama::Client.response_body(response, 'learners')
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
- EasyLlama::Client.response_body(response, 'learner')
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
- EasyLlama::Client.response_body(response, 'learner')
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
- EasyLlama::Client.response_body(response, 'learner')
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(path: "/learners/#{learner_id}/learner_trainings", method: :post, body: { learner_id:, training_id: })
50
- EasyLlama::Client.response_body(response, 'assignment')
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
@@ -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
- EasyLlama::Client.response_body(response, 'locations')
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
- EasyLlama::Client.response_body(response, 'location')
23
+
24
+ EasyLlama::Client.parse_response(response, 'location')
22
25
  end
23
26
  end
24
27
  end
@@ -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
- EasyLlama::Client.response_body(response, 'trainings')
13
+
14
+ EasyLlama::Client.parse_response(response, 'trainings')
13
15
  end
14
16
  end
15
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyllama-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitalii Kashoid