milady-cima-api 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cba4eea16f1a7f12d7085606bdadee4927918c7f960d2bd95ee4b9f10909f0f
4
- data.tar.gz: e0519d5dfa0eacecf95237a65669ec5b232d23eb334bf50b9349b501887f1bbb
3
+ metadata.gz: e7a0502a36b75c80c03711804558c9396a5e0b8bc28aa904ee4fbca86a7c28ba
4
+ data.tar.gz: 8a32eabd2e1a6d6157bdae2c1cb64428e6572aba4cb11a6ba4b4cf904b8d6e1f
5
5
  SHA512:
6
- metadata.gz: e872f0ae20e5bb564e219625426e4f853cc65ff48ac20a36c73879b7e7dcc4351c22ff6ce5fdb0aee612e11f76fce8cf38588005f54777897c2257c162c630f6
7
- data.tar.gz: 4aedb0de4d77fa84fc8d430fb4dfc3df3ca61e6279785a7dd4750490493ee1cfec2003e8b5583d5d5f7afef19a1a5007ed8b12a0a83fb786bfcb4cf2499f9201
6
+ metadata.gz: 74f6e46875750a10b53cf5051d2b1ba543fb9dcc7ab4f3ef2e5eb1c7bb7e85c3884aa3b51d5878bd850c0cdeb51fca57ea3be4277becac23ddec1d5c9facf33a
7
+ data.tar.gz: 9348229a5ff3940265d8afa641cb64fa1ba6b0c3fdd036cb17f3b9b02988c12c4a3e6fb45223b4f66494fc9105b21eaeac62fb023f6031f0b26cc0e2c32cfd61
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2025-12-04
4
+
5
+ ### Added
6
+ - Added `CourseLearners` resource under `Users` to support `GET /users/{id}/course_learners`.
7
+ - Added `Users#find` method to retrieve a single user.
8
+
9
+ ### Changed
10
+ - Updated `Users#list` to use explicit keyword arguments for better documentation and usability.
11
+ - Removed custom `Users#list_by_organization` and `Users#list_learners_by_organization` methods in favor of standardized `list` with filters.
12
+
13
+ ## [0.3.0] - 2025-12-04
14
+
15
+ ### Added
16
+ - Added `Learners` resource under `Courses` to support `GET /courses/{id}/learners` and `GET /courses/{id}/learners/{user_id}`.
17
+
18
+ ### Changed
19
+ - Refactored `Courses`, `Assessments`, and `Learners` resources to inherit from a common `Base` class to share initialization and filter normalization logic.
20
+
3
21
  ## [0.2.1] - 2025-12-04
4
22
 
5
23
  ### Added
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module MiLadyCimaApi
6
+ module Resources
7
+ class Base
8
+ # @param client [MiLadyCimaApi::Client]
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ protected
14
+
15
+ def normalize_filter(filter)
16
+ return filter if filter.is_a?(String)
17
+ return JSON.generate(filter) if filter.is_a?(Hash)
18
+
19
+ raise ArgumentError, 'filter must be a String (JSON) or a Hash'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../base'
4
+
3
5
  module MiLadyCimaApi
4
6
  module Resources
5
7
  class Courses
6
8
  # Assessments resource exposes endpoints under /courses/{id}/assessments
7
- class Assessments
8
- # @param client [MiLadyCimaApi::Client]
9
- def initialize(client)
10
- @client = client
11
- end
9
+ class Assessments < Resources::Base
12
10
 
13
11
  # List assessments for a course
14
12
  #
@@ -50,14 +48,6 @@ module MiLadyCimaApi
50
48
  @client.get("/courses/#{course_id}/assessments/#{assessment_id}")
51
49
  end
52
50
 
53
- private
54
-
55
- def normalize_filter(filter)
56
- return filter if filter.is_a?(String)
57
- return JSON.generate(filter) if filter.is_a?(Hash)
58
-
59
- raise ArgumentError, 'filter must be a String (JSON) or a Hash'
60
- end
61
51
  end
62
52
  end
63
53
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base'
4
+
5
+ module MiLadyCimaApi
6
+ module Resources
7
+ class Courses
8
+ # Learners resource exposes endpoints under /courses/{id}/learners
9
+ class Learners < Resources::Base
10
+
11
+ # List learners for a course
12
+ #
13
+ # GET /courses/{id}/learners
14
+ # @param course_id [Integer, String] ID of the course
15
+ # @param filter [Hash, String] Filter using JSON structure
16
+ # @param limit [Integer] Limit the number of returned objects (default 10, max 100)
17
+ # @param offset [Integer] Used for paging through a small dataset
18
+ # @param after [Integer] Used for fast paging
19
+ # @param count [Boolean] If true, just return the number of list items
20
+ # @param include [String] Comma separated list of relationships to include
21
+ # @return [Array, Hash] Parsed JSON response from the API
22
+ def list(course_id:, filter: nil, limit: nil, offset: nil, after: nil, count: nil, include: nil)
23
+ raise ArgumentError, 'course_id is required' if course_id.nil?
24
+
25
+ if limit && limit > 100
26
+ raise ArgumentError, 'limit cannot be greater than 100'
27
+ end
28
+
29
+ params = {}
30
+ params['$filter'] = normalize_filter(filter) if filter
31
+ params['$limit'] = limit if limit
32
+ params['$offset'] = offset if offset
33
+ params['$after'] = after if after
34
+ params['$count'] = count if count
35
+ params['$include'] = include if include
36
+
37
+ @client.get("/courses/#{course_id}/learners", params: params)
38
+ end
39
+
40
+ # Get a single learner
41
+ #
42
+ # GET /courses/{id}/learners/{user_id}
43
+ # @param course_id [Integer, String] ID of the course
44
+ # @param user_id [Integer, String] ID of the user
45
+ # @param include [String] Comma separated list of relationships to include
46
+ # @return [Hash] Parsed JSON response from the API
47
+ def find(course_id:, user_id:, include: nil)
48
+ raise ArgumentError, 'course_id is required' if course_id.nil?
49
+ raise ArgumentError, 'user_id is required' if user_id.nil?
50
+
51
+ params = {}
52
+ params['$include'] = include if include
53
+
54
+ @client.get("/courses/#{course_id}/learners/#{user_id}", params: params)
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,23 +1,22 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'json'
4
- require_relative 'courses/assessments'
2
+ require_relative 'base'
5
3
 
6
4
  module MiLadyCimaApi
7
5
  module Resources
8
6
  # Courses resource exposes endpoints under /courses
9
7
  # Provides convenience helpers for building $filter queries.
10
- class Courses
11
- # @param client [MiLadyCimaApi::Client]
12
- def initialize(client)
13
- @client = client
14
- end
8
+ class Courses < Base
15
9
 
16
10
  # @return [MiLadyCimaApi::Resources::Courses::Assessments]
17
11
  def assessments
18
12
  @assessments ||= Assessments.new(@client)
19
13
  end
20
14
 
15
+ # @return [MiLadyCimaApi::Resources::Courses::Learners]
16
+ def learners
17
+ @learners ||= Learners.new(@client)
18
+ end
19
+
21
20
  # List courses
22
21
  #
23
22
  # GET /courses
@@ -91,14 +90,9 @@ module MiLadyCimaApi
91
90
  list(filter: filter, **extra_params)
92
91
  end
93
92
 
94
- private
95
-
96
- def normalize_filter(filter)
97
- return filter if filter.is_a?(String)
98
- return JSON.generate(filter) if filter.is_a?(Hash)
99
-
100
- raise ArgumentError, 'filter must be a String (JSON) or a Hash'
101
- end
102
93
  end
103
94
  end
104
95
  end
96
+
97
+ require_relative 'courses/assessments'
98
+ require_relative 'courses/learners'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base'
4
+
5
+ module MiLadyCimaApi
6
+ module Resources
7
+ class Users
8
+ # CourseLearners resource exposes endpoints under /users/{id}/course_learners
9
+ class CourseLearners < Resources::Base
10
+
11
+ # List user course learners
12
+ #
13
+ # GET /users/{id}/course_learners
14
+ # @param user_id [Integer, String] ID of the user
15
+ # @param after [Integer] Used for fast paging
16
+ # @param count [Boolean] If true, just return the number of list items
17
+ # @param filter [Hash, String] Filter using JSON structure
18
+ # @param include [String] Comma separated list of relationships to include
19
+ # @param limit [Integer] Limit the number of returned objects (default 10, max 100)
20
+ # @param offset [Integer] Used for paging through a small dataset
21
+ # @return [Array, Hash] Parsed JSON response from the API
22
+ def list(user_id:, after: nil, count: nil, filter: nil, include: nil, limit: nil, offset: nil)
23
+ raise ArgumentError, 'user_id is required' if user_id.nil?
24
+
25
+ if limit && limit > 100
26
+ raise ArgumentError, 'limit cannot be greater than 100'
27
+ end
28
+
29
+ params = {}
30
+ params['$after'] = after if after
31
+ params['$count'] = count if count
32
+ params['$filter'] = normalize_filter(filter) if filter
33
+ params['$include'] = include if include
34
+ params['$limit'] = limit if limit
35
+ params['$offset'] = offset if offset
36
+
37
+ @client.get("/users/#{user_id}/course_learners", params: params)
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,60 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'base'
4
+
3
5
  module MiLadyCimaApi
4
6
  module Resources
5
7
  # Users resource exposes endpoints under /users
6
- class Users
7
- # @param client [MiLadyCimaApi::Client]
8
- def initialize(client)
9
- @client = client
8
+ class Users < Base
9
+
10
+ # @return [MiLadyCimaApi::Resources::Users::CourseLearners]
11
+ def course_learners
12
+ @course_learners ||= CourseLearners.new(@client)
10
13
  end
11
14
 
12
- # List users.
15
+ # List users
13
16
  #
14
17
  # GET /users
15
- # @param params [Hash] Optional query params (e.g., pagination)
18
+ # @param after [Integer] Used for fast paging
19
+ # @param count [Boolean] If true, just return the number of list items
20
+ # @param filter [Hash, String] Filter using JSON structure
21
+ # @param include [String] Comma separated list of relationships to include
22
+ # @param limit [Integer] Limit the number of returned objects (default 10, max 100)
23
+ # @param offset [Integer] Used for paging through a small dataset
24
+ # @param order [String] Comma separated attribute names to sort by
16
25
  # @return [Array, Hash] Parsed JSON response from the API
17
- # @raise [MiLadyCimaApi::UnauthorizedError, MiLadyCimaApi::NotFoundError, MiLadyCimaApi::ClientError, MiLadyCimaApi::ServerError]
18
- def list(params = {})
19
- @client.get('/users', params: params)
20
- end
26
+ def list(after: nil, count: nil, filter: nil, include: nil, limit: nil, offset: nil, order: nil)
27
+ if limit && limit > 100
28
+ raise ArgumentError, 'limit cannot be greater than 100'
29
+ end
21
30
 
22
- # List users by organization.
23
- #
24
- # GET /users with organization filter
25
- # @param organization_id [String, Integer] Organization ID to filter by
26
- # @param role [String, nil] Optional role to filter by (e.g., 'Learner')
27
- # @param params [Hash] Optional additional query params (e.g., pagination)
28
- # @return [Array, Hash] Parsed JSON response from the API
29
- # @raise [MiLadyCimaApi::UnauthorizedError, MiLadyCimaApi::NotFoundError, MiLadyCimaApi::ClientError, MiLadyCimaApi::ServerError]
30
- def list_by_organization(organization_id, role: nil, **params)
31
- filter = build_organization_filter(organization_id, role: role)
32
- @client.get('/users', params: params.merge('$filter': filter))
33
- end
31
+ params = {}
32
+ params['$after'] = after if after
33
+ params['$count'] = count if count
34
+ params['$filter'] = normalize_filter(filter) if filter
35
+ params['$include'] = include if include
36
+ params['$limit'] = limit if limit
37
+ params['$offset'] = offset if offset
38
+ params['$order'] = order if order
34
39
 
35
- # List learners by organization.
36
- #
37
- # GET /users with organization and Learner role filter
38
- # @param organization_id [String, Integer] Organization ID to filter by
39
- # @param params [Hash] Optional additional query params (e.g., pagination)
40
- # @return [Array, Hash] Parsed JSON response from the API
41
- # @raise [MiLadyCimaApi::UnauthorizedError, MiLadyCimaApi::NotFoundError, MiLadyCimaApi::ClientError, MiLadyCimaApi::ServerError]
42
- def list_learners_by_organization(organization_id, **params)
43
- list_by_organization(organization_id, role: 'Learner', **params)
40
+ @client.get('/users', params: params)
44
41
  end
45
42
 
46
- private
43
+ # Get user
44
+ #
45
+ # GET /users/{id}
46
+ # @param id [Integer, String] ID of the user
47
+ # @param include [String] Comma separated list of relationships to include
48
+ # @return [Hash] Parsed JSON response from the API
49
+ def find(id:, include: nil)
50
+ raise ArgumentError, 'id is required' if id.nil?
47
51
 
48
- # Build filter object for organization and optional role
49
- # @param organization_id [String, Integer]
50
- # @param role [String, nil]
51
- # @return [Hash] Filter hash
52
- def build_organization_filter(organization_id, role: nil)
53
- conditions = [{ eq: { organization_id: organization_id } }]
54
- conditions << { contains: { roles: role } } if role
52
+ params = {}
53
+ params['$include'] = include if include
55
54
 
56
- { and: conditions }
55
+ @client.get("/users/#{id}", params: params)
57
56
  end
57
+
58
58
  end
59
59
  end
60
- end
60
+ end
61
+
62
+ require_relative 'users/course_learners'
@@ -2,5 +2,5 @@
2
2
 
3
3
  module MiLadyCimaApi
4
4
  # Gem version
5
- VERSION = "0.2.1"
5
+ VERSION = "0.4.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milady-cima-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - marcus.salinas
@@ -27,10 +27,13 @@ files:
27
27
  - lib/milady_cima_api.rb
28
28
  - lib/milady_cima_api/client.rb
29
29
  - lib/milady_cima_api/errors.rb
30
+ - lib/milady_cima_api/resources/base.rb
30
31
  - lib/milady_cima_api/resources/courses.rb
31
32
  - lib/milady_cima_api/resources/courses/assessments.rb
33
+ - lib/milady_cima_api/resources/courses/learners.rb
32
34
  - lib/milady_cima_api/resources/organizations.rb
33
35
  - lib/milady_cima_api/resources/users.rb
36
+ - lib/milady_cima_api/resources/users/course_learners.rb
34
37
  - lib/milady_cima_api/version.rb
35
38
  homepage: https://github.com/jippylong12/milady-cima-api
36
39
  licenses: