easyllama-client 0.1.0 → 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 +11 -12
- data/lib/easyllama/learners.rb +75 -0
- data/lib/easyllama/locations.rb +29 -0
- data/lib/easyllama/trainings.rb +19 -0
- metadata +4 -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
@@ -3,6 +3,10 @@
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
+
require_relative 'locations'
|
7
|
+
require_relative 'learners'
|
8
|
+
require_relative 'trainings'
|
9
|
+
|
6
10
|
module EasyLlama
|
7
11
|
# This class provides methods for interacting with the Easy Llama API.
|
8
12
|
class Client
|
@@ -23,27 +27,22 @@ module EasyLlama
|
|
23
27
|
|
24
28
|
# Parses the response body and returns the value corresponding to the provided key.
|
25
29
|
# If the response is successful, returns the value for the key.
|
26
|
-
# If the response is unsuccessful, returns an error message.
|
30
|
+
# If the response is unsuccessful, returns an error code and message.
|
27
31
|
#
|
28
32
|
# @param response [Net::HTTPResponse] The HTTP response.
|
29
33
|
# @param key [String] The key to retrieve from the response body.
|
30
|
-
# @return [Object] The value corresponding to the key or
|
31
|
-
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)
|
32
36
|
if response.is_a?(Net::HTTPSuccess)
|
37
|
+
return {} if response.body.nil?
|
38
|
+
return JSON.parse(response.body) if key.nil?
|
39
|
+
|
33
40
|
JSON.parse(response.body)[key]
|
34
41
|
else
|
35
|
-
{ 'error' => response.message }
|
42
|
+
{ 'code' => response.code, 'error' => response.message }
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
39
|
-
# Sends a GET request to retrieve locations.
|
40
|
-
#
|
41
|
-
# @return [Object] The locations or an error message.
|
42
|
-
def locations
|
43
|
-
response = send_request(path: '/locations')
|
44
|
-
response_body(response, 'locations')
|
45
|
-
end
|
46
|
-
|
47
46
|
private
|
48
47
|
|
49
48
|
def build_uri(path)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EasyLlama
|
4
|
+
class Client
|
5
|
+
# This class provides methods for interacting with the Easy Llama API for learners.
|
6
|
+
class Learners
|
7
|
+
class << self
|
8
|
+
# Sends a GET request to retrieve all learners.
|
9
|
+
#
|
10
|
+
# @return [Object] The learners or an error message.
|
11
|
+
def all
|
12
|
+
response = EasyLlama::Client.send_request(path: '/learners')
|
13
|
+
|
14
|
+
EasyLlama::Client.parse_response(response, 'learners')
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sends a GET request to retrieve a learner by ID.
|
18
|
+
#
|
19
|
+
# @param id [Integer] The ID of the learner.
|
20
|
+
# @return [Object] The learner or an error message.
|
21
|
+
def find(id)
|
22
|
+
response = EasyLlama::Client.send_request(path: "/learners/#{id}")
|
23
|
+
|
24
|
+
EasyLlama::Client.parse_response(response, 'learner')
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sends a POST request to create a learner.
|
28
|
+
#
|
29
|
+
# @param learner_attributes [Hash] The attributes of the learner.
|
30
|
+
# @return [Object] The created learner or an error message.
|
31
|
+
def create(learner_attributes = {})
|
32
|
+
response = EasyLlama::Client.send_request(path: '/learners', method: :post, body: learner_attributes)
|
33
|
+
|
34
|
+
EasyLlama::Client.parse_response(response, 'learner')
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sends a PATCH request to update a learner by ID.
|
38
|
+
#
|
39
|
+
# @param id [Integer] The ID of the learner.
|
40
|
+
# @param learner_attributes [Hash] The attributes to update.
|
41
|
+
# @return [Object] The updated learner or an error message.
|
42
|
+
def update(id, learner_attributes = {})
|
43
|
+
response = EasyLlama::Client.send_request(path: "/learners/#{id}", method: :patch, body: learner_attributes)
|
44
|
+
|
45
|
+
EasyLlama::Client.parse_response(response, 'learner')
|
46
|
+
end
|
47
|
+
|
48
|
+
# Sends a POST request to assign a training to a learner.
|
49
|
+
#
|
50
|
+
# @param training_id [Integer] The ID of the training.
|
51
|
+
# @param learner_id [Integer] The ID of the learner.
|
52
|
+
# @return [Object] The training assignment details or an error message.
|
53
|
+
def assign_training_to_learner(training_id:, learner_id:)
|
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)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EasyLlama
|
4
|
+
class Client
|
5
|
+
# This class provides methods for interacting with the Easy Llama API for locations.
|
6
|
+
class Locations
|
7
|
+
class << self
|
8
|
+
# Sends a GET request to retrieve all locations.
|
9
|
+
#
|
10
|
+
# @return [Object] The locations or an error message.
|
11
|
+
def all
|
12
|
+
response = EasyLlama::Client.send_request(path: '/locations')
|
13
|
+
|
14
|
+
EasyLlama::Client.parse_response(response, 'locations')
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sends a POST request to create a location.
|
18
|
+
#
|
19
|
+
# @param location_attributes [Hash] The attributes of the location.
|
20
|
+
# @return [Object] The created location or an error message.
|
21
|
+
def create(location_attributes = {})
|
22
|
+
response = EasyLlama::Client.send_request(path: '/locations', method: :post, body: location_attributes)
|
23
|
+
|
24
|
+
EasyLlama::Client.parse_response(response, 'location')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EasyLlama
|
4
|
+
class Client
|
5
|
+
# This class provides methods for interacting with the Easy Llama API for trainings.
|
6
|
+
class Trainings
|
7
|
+
class << self
|
8
|
+
# Sends a GET request to retrieve all trainings.
|
9
|
+
#
|
10
|
+
# @return [Object] The trainings or an error message.
|
11
|
+
def all
|
12
|
+
response = EasyLlama::Client.send_request(path: '/trainings')
|
13
|
+
|
14
|
+
EasyLlama::Client.parse_response(response, 'trainings')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitalii Kashoid
|
@@ -47,6 +47,9 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- lib/easyllama/client.rb
|
49
49
|
- lib/easyllama/client/version.rb
|
50
|
+
- lib/easyllama/learners.rb
|
51
|
+
- lib/easyllama/locations.rb
|
52
|
+
- lib/easyllama/trainings.rb
|
50
53
|
homepage: https://rubygems.org/gems/easyllama-client
|
51
54
|
licenses:
|
52
55
|
- MIT
|