milady-cima-api 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5539419d40c122e538f50af35e0be9230c3b9e29343ae9afaf47ecc18164cc25
4
+ data.tar.gz: 175f19d66fd55269468793c5d7ae9eb2eb5b1adf6c874e35f28ca0a7cbf431e7
5
+ SHA512:
6
+ metadata.gz: 6b14b31072de9c2678cae2938c5de0dc6ba0feb1d9c2571a51db638c6bd740c04eb93d7f6972a40edd31cd07575446d74ad4fdaab401eb8d0bf28bfb70e08ccd
7
+ data.tar.gz: 63c8e1ec423e9abf96e7a9b3be440e38d3a0a642eb4a76102d3440e5a5da08b3cc3ad577a721f0de455071ec5e4ab6eea71d870cb90d0a53e1a0e279eb03b666
data/.env.test.example ADDED
@@ -0,0 +1,3 @@
1
+ # Copy this file to .env.test and adjust values for local testing
2
+ # This API key is used by the test suite when running locally.
3
+ MILADY_CIMA_API_KEY=secret
@@ -0,0 +1,45 @@
1
+ Junie Agent Guidelines for the MiLady CIMA Project
2
+ ==================================================
3
+
4
+ Welcome, Junie. You are an AI coding agent tasked with assisting with the **MiLady CIMA** project, which is being developed as a Ruby gem. Your primary function is to help build and maintain an API wrapper. To ensure your work is aligned with our standards and goals, please follow the guidelines below.
5
+
6
+ * * * * *
7
+
8
+ 1\. Project Description: MiLady CIMA
9
+ ------------------------------------
10
+
11
+ The **MiLady CIMA** project is an **API wrapper** built as a Ruby gem. Its purpose is to provide a clean, user-friendly interface for interacting with an external API. The core principle is to abstract away the complexities of direct API calls, such as handling authentication, request headers, data serialization, and error responses. Our goal is to make the external API accessible to other developers in a simple, intuitive, and consistent manner, following established Ruby gem paradigms.
12
+
13
+ * * * * *
14
+
15
+ 2\. Core Principles for the Ruby Gem
16
+ ------------------------------------
17
+
18
+ When working on this project, your code should always reflect these core design principles:
19
+
20
+ - **Resource-Oriented Design:** The gem's structure must mirror the external API's resources. We will use a **class-based approach** where a main client class contains instances of other classes that represent specific API resources (e.g., `client.users`, `client.posts`). This prevents a monolithic "God object" and creates a clear, logical hierarchy.
21
+
22
+ - **Separation of Concerns:** Each class or module should have a single responsibility. A `Users` class, for example, should only contain logic related to the `/users` endpoint and its sub-resources.
23
+
24
+ - **Clear Error Handling:** The gem should catch API errors and raise descriptive, custom Ruby exceptions. A user should not have to parse raw JSON error messages to understand what went wrong. For example, a 404 response should raise a `MiLadyCima::NotFoundError`.
25
+
26
+ - **Adherence to Ruby Best Practices:** Write clean, well-commented code that follows the standard Ruby style guide (e.g., using `snake_case` for methods and variables). Use meaningful variable names and clear function signatures.
27
+
28
+ * * * * *
29
+
30
+ 3\. Your Role as Junie
31
+ ----------------------
32
+
33
+ As the AI agent, your role is to write code that aligns with the principles above. When a task involves creating a new endpoint or modifying an existing one, you should:
34
+
35
+ - **Determine the correct resource class** for the new endpoint (e.g., `Users`, `Posts`, `Comments`). If the class does not exist, you must create it.
36
+
37
+ - **Add a new method** to the appropriate resource class that encapsulates the API call.
38
+
39
+ - **Implement proper error handling** for potential API responses (e.g., 404 Not Found, 401 Unauthorized, 500 Server Error) by rescuing them and raising custom exceptions.
40
+
41
+ - **Add clear YARD-style documentation** (`@param`, `@return`, etc.) to the method explaining its purpose, parameters, and return values.
42
+
43
+ - **Write corresponding tests** using a framework like RSpec to ensure the new functionality works as expected and doesn't introduce regressions.
44
+
45
+ By following these guidelines, you'll help us create a robust, well-documented, and professionally designed Ruby gem for the **MiLady CIMA** project.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-10-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at 12.marcus.salinas@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 marcus.salinas
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/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Milady::Cima::Api
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/milady/cima/api`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/milady-cima-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/milady-cima-api/blob/master/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Milady::Cima::Api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/milady-cima-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ module MiLadyCimaApi
8
+ class Client
9
+ DEFAULT_BASE_URL = 'https://www.miladycima.com/api/v3'
10
+ API_PAGE_LIMIT = 100
11
+
12
+ attr_reader :api_key, :base_url
13
+ attr_reader :users, :organizations, :courses
14
+
15
+ def initialize(api_key:, base_url: DEFAULT_BASE_URL)
16
+ raise ArgumentError, 'api_key is required' if api_key.nil? || api_key.strip.empty?
17
+
18
+ @api_key = api_key
19
+ @base_url = base_url.chomp('/')
20
+ @users = MiLadyCimaApi::Resources::Users.new(self)
21
+ @organizations = MiLadyCimaApi::Resources::Organizations.new(self)
22
+ @courses = MiLadyCimaApi::Resources::Courses.new(self)
23
+ end
24
+
25
+ def get(path, params: {})
26
+ params = params || {}
27
+ requested_limit = extract_numeric(params['$limit'] || params[:'$limit'])
28
+ if requested_limit && requested_limit > API_PAGE_LIMIT
29
+ raise ArgumentError, "$limit cannot be greater than #{API_PAGE_LIMIT}"
30
+ end
31
+
32
+ uri = build_uri(path, params)
33
+ request = Net::HTTP::Get.new(uri)
34
+ attach_headers(request)
35
+ perform_request(uri, request)
36
+ end
37
+
38
+ def post(path, body: {})
39
+ uri = build_uri(path)
40
+ request = Net::HTTP::Post.new(uri)
41
+ attach_headers(request)
42
+ request.body = JSON.generate(body)
43
+ perform_request(uri, request)
44
+ end
45
+
46
+ private
47
+
48
+ def build_uri(path, params = {})
49
+ raise ArgumentError, 'path must start with /' unless path.start_with?('/')
50
+ uri = URI.parse(base_url + path)
51
+
52
+ unless params.nil? || params.empty?
53
+ # 1) stringify keys/values properly
54
+ stringified = deep_stringify_keys(params)
55
+ # 2) JSON-encode complex values and preserve $-prefixed keys (e.g., "$filter")
56
+ json_ready = encode_complex_query_values(stringified)
57
+ query = URI.decode_www_form(String(uri.query)) + json_ready.to_a
58
+ uri.query = URI.encode_www_form(query)
59
+ end
60
+
61
+ uri
62
+ end
63
+
64
+ def deep_stringify_keys(obj)
65
+ case obj
66
+ when Hash
67
+ obj.each_with_object({}) do |(k, v), h|
68
+ h[k].is_a?(Symbol) ? h[k.to_s] = deep_stringify_keys(v) : h[k.to_s] = deep_stringify_keys(v)
69
+ end
70
+ when Array
71
+ obj.map { |v| deep_stringify_keys(v) }
72
+ else
73
+ obj
74
+ end
75
+ end
76
+
77
+ # Ensure nested hashes/arrays are sent as JSON strings in query values.
78
+ # Keys that begin with "$" (e.g., "$filter") are preserved verbatim.
79
+ # Example:
80
+ # { "$filter" => { "and" => [ ... ] } }
81
+ # => "$filter" => "{\"and\":[...]}"
82
+ def encode_complex_query_values(params)
83
+ return params unless params.is_a?(Hash)
84
+
85
+ params.each_with_object({}) do |(k, v), h|
86
+ if v.is_a?(Hash) || v.is_a?(Array)
87
+ h[k] = JSON.generate(v)
88
+ else
89
+ h[k] = v
90
+ end
91
+ end
92
+ end
93
+
94
+ def attach_headers(request)
95
+ request['Accept'] = 'application/json'
96
+ request['Content-Type'] = 'application/json'
97
+ request['x-api-key'] = api_key
98
+ end
99
+
100
+ def perform_request(uri, request)
101
+ http = Net::HTTP.new(uri.host, uri.port)
102
+ http.use_ssl = uri.scheme == 'https'
103
+ response = http.request(request)
104
+ handle_response(response)
105
+ end
106
+
107
+ def handle_response(response)
108
+ code = response.code.to_i
109
+ body = response.body
110
+
111
+ case code
112
+ when 200..299
113
+ parse_json(body)
114
+ when 401
115
+ raise MiLadyCimaApi::UnauthorizedError, error_message(body, code)
116
+ when 404
117
+ raise MiLadyCimaApi::NotFoundError, error_message(body, code)
118
+ when 400..499
119
+ raise MiLadyCimaApi::ClientError, error_message(body, code)
120
+ when 500..599
121
+ raise MiLadyCimaApi::ServerError, error_message(body, code)
122
+ else
123
+ raise MiLadyCimaApi::Error, error_message(body, code)
124
+ end
125
+ end
126
+
127
+ def parse_json(body)
128
+ return nil if body.nil? || body.strip.empty?
129
+ JSON.parse(body)
130
+ rescue JSON::ParserError => e
131
+ raise MiLadyCimaApi::ResponseError, "Invalid JSON response: #{e.message}"
132
+ end
133
+
134
+ def error_message(body, code)
135
+ begin
136
+ parsed = body && !body.strip.empty? ? JSON.parse(body) : nil
137
+ message = parsed.is_a?(Hash) ? (parsed['message'] || parsed['error'] || parsed['errors'] || parsed.to_s) : body.to_s
138
+ rescue JSON::ParserError
139
+ message = body.to_s
140
+ end
141
+ "HTTP #{code}: #{message}"
142
+ end
143
+
144
+ def extract_numeric(value)
145
+ return nil if value.nil?
146
+ return value if value.is_a?(Integer)
147
+ return value.to_i if value.is_a?(String) && value.to_s =~ /\A\d+\z/
148
+ nil
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiLadyCimaApi
4
+ # Base error class for all API-related errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when the API returns 401 Unauthorized
8
+ class UnauthorizedError < Error; end
9
+
10
+ # Raised when the API returns 404 Not Found
11
+ class NotFoundError < Error; end
12
+
13
+ # Raised when the API returns 4xx errors other than 401/404
14
+ class ClientError < Error; end
15
+
16
+ # Raised when the API returns 5xx errors
17
+ class ServerError < Error; end
18
+
19
+ # Raised when the response cannot be parsed or is otherwise invalid
20
+ class ResponseError < Error; end
21
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module MiLadyCimaApi
6
+ module Resources
7
+ # Courses resource exposes endpoints under /courses
8
+ # Provides convenience helpers for building $filter queries.
9
+ class Courses
10
+ # @param client [MiLadyCimaApi::Client]
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ # List courses
16
+ #
17
+ # GET /courses
18
+ # @param params [Hash] Optional query params. Supports the special key
19
+ # "$filter" (String or Hash). If provided as a Hash, it will be JSON-encoded
20
+ # to match the API expectation (e.g., {"organization_id" => 123} or
21
+ # {"and" => [{"gt" => {"metadata.created_at" => "2025-01-01T00:00:00.000Z"}}]}).
22
+ # @option params [String, Hash] :$filter JSON string or Ruby Hash representing the filter
23
+ # @return [Array, Hash] Parsed JSON response from the API
24
+ # @raise [MiLadyCimaApi::UnauthorizedError, MiLadyCimaApi::NotFoundError, MiLadyCimaApi::ClientError, MiLadyCimaApi::ServerError]
25
+ def list(params = {})
26
+ params = params.dup || {}
27
+ normalize_filter_param!(params)
28
+ @client.get('/courses', params: params)
29
+ end
30
+
31
+ # Convenience: List courses by organization
32
+ # @param organization_id [Integer, String]
33
+ # @param extra_params [Hash] Additional query params (e.g., pagination)
34
+ # @return [Array, Hash]
35
+ def by_organization(organization_id:, **extra_params)
36
+ raise ArgumentError, 'organization_id is required' if organization_id.nil?
37
+ filter = { 'organization_id' => organization_id }
38
+ list({ '$filter' => filter }.merge(extra_params))
39
+ end
40
+
41
+ # Convenience: List courses filtered by created_at with comparison operator
42
+ # @param created_at [String, Time] ISO8601 string or Time
43
+ # @param op [String] One of 'gt' or 'lt'
44
+ # @param organization_id [Integer, String, nil] Optional extra filter combined with AND
45
+ # @param extra_params [Hash]
46
+ # @return [Array, Hash]
47
+ def by_created_at(created_at:, op:, organization_id: nil, **extra_params)
48
+ raise ArgumentError, "op must be 'gt' or 'lt'" unless %w[gt lt].include?(op.to_s)
49
+ ts = created_at.is_a?(Time) ? created_at.utc.iso8601(3) : created_at.to_s
50
+ time_filter = { op.to_s => { 'metadata.created_at' => ts } }
51
+
52
+ filter = if organization_id.nil?
53
+ { 'and' => [time_filter] }
54
+ else
55
+ { 'and' => [time_filter, { 'organization_id' => organization_id }] }
56
+ end
57
+
58
+ list({ '$filter' => filter }.merge(extra_params))
59
+ end
60
+
61
+ private
62
+
63
+ # Mutates params hash to ensure $filter is a JSON string when provided as a Hash
64
+ def normalize_filter_param!(params)
65
+ # support both symbol and string keys
66
+ filter_key = params.key?(:$filter) ? :$filter : (params.key?("$filter") ? "$filter" : nil)
67
+ return unless filter_key
68
+
69
+ value = params[filter_key]
70
+ case value
71
+ when Hash
72
+ params[filter_key] = JSON.generate(value)
73
+ when String
74
+ # pass through
75
+ else
76
+ raise ArgumentError, "$filter must be a String (JSON) or a Hash"
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiLadyCimaApi
4
+ module Resources
5
+ # Organizations resource exposes endpoints under /organizations
6
+ class Organizations
7
+ # @param client [MiLadyCimaApi::Client]
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ # List organizations.
13
+ #
14
+ # GET /organizations
15
+ # @param params [Hash] Optional query params (e.g., pagination)
16
+ # @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('/organizations', params: params)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiLadyCimaApi
4
+ module Resources
5
+ # Users resource exposes endpoints under /users
6
+ class Users
7
+ # @param client [MiLadyCimaApi::Client]
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ # List users.
13
+ #
14
+ # GET /users
15
+ # @param params [Hash] Optional query params (e.g., pagination)
16
+ # @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
21
+
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
34
+
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)
44
+ end
45
+
46
+ private
47
+
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
55
+
56
+ { and: conditions }
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiLadyCimaApi
4
+ # Gem version
5
+ VERSION = "0.1.0"
6
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "milady_cima_api/version"
4
+ require_relative "milady_cima_api/errors"
5
+ require_relative "milady_cima_api/client"
6
+ require_relative "milady_cima_api/resources/users"
7
+ require_relative "milady_cima_api/resources/organizations"
8
+ require_relative "milady_cima_api/resources/courses"
9
+
10
+ # MiLadyCimaApi is the top-level namespace for the MiLady CIMA API Ruby client.
11
+ # It provides a simple, resource-oriented interface for interacting with the
12
+ # MiLady CIMA API v3.
13
+ module MiLadyCimaApi
14
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/milady_cima_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "milady-cima-api"
7
+ spec.version = MiLadyCimaApi::VERSION
8
+ spec.authors = ["marcus.salinas"]
9
+ spec.email = ["12.marcus.salinas@gmail.com"]
10
+
11
+ spec.summary = "Ruby wrapper for the MiLady CIMA API."
12
+ spec.description = "milady-cima-api is a lightweight Ruby client that wraps the MiLady CIMA API, providing simple, idiomatic access to its endpoints."
13
+ spec.homepage = "https://github.com/jippylong12/milady-cima-api"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/jippylong12/milady-cima-api"
21
+ spec.metadata["changelog_uri"] = "https://github.com/jippylong12/milady-cima-api/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: milady-cima-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - marcus.salinas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: milady-cima-api is a lightweight Ruby client that wraps the MiLady CIMA
14
+ API, providing simple, idiomatic access to its endpoints.
15
+ email:
16
+ - 12.marcus.salinas@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".env.test.example"
22
+ - ".junie/guidelines.md"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/milady_cima_api.rb
29
+ - lib/milady_cima_api/client.rb
30
+ - lib/milady_cima_api/errors.rb
31
+ - lib/milady_cima_api/resources/courses.rb
32
+ - lib/milady_cima_api/resources/organizations.rb
33
+ - lib/milady_cima_api/resources/users.rb
34
+ - lib/milady_cima_api/version.rb
35
+ - milady-cima-api.gemspec
36
+ homepage: https://github.com/jippylong12/milady-cima-api
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ allowed_push_host: https://rubygems.org
41
+ homepage_uri: https://github.com/jippylong12/milady-cima-api
42
+ source_code_uri: https://github.com/jippylong12/milady-cima-api
43
+ changelog_uri: https://github.com/jippylong12/milady-cima-api/blob/main/CHANGELOG.md
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.6.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.5.22
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Ruby wrapper for the MiLady CIMA API.
63
+ test_files: []