one-mentor-ruby 0.2.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: 9904bfffe82b3303d8c50a6811bed3a6c132094527e141d8b64afae1aa07dfde
4
+ data.tar.gz: 3a20fb4ccebad84af455dd36a796c7f65db49c894ed612d0476242ec8bb438d1
5
+ SHA512:
6
+ metadata.gz: bc2059d775d808a5aaf8e89d157bdc9e94bfff102eb96bf127ff43b0262637ec8ed855975cdfc8e0494c7689f72fc3698a79cb3434a1b1a595409de7ec9bbc75
7
+ data.tar.gz: 4f0ca170a8392af8f6cac0cfe03ab843d1793bbb18c3bf0b2004f5318fc762e3f25d8909abd2eaf5bd4b441684113ed3a784b96afed6be9c55d5902196abc940
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,56 @@
1
+ plugins:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+ SuggestExtensions: false
7
+ TargetRubyVersion: 2.6
8
+
9
+ Layout/LineLength:
10
+ Max: 150
11
+
12
+ Metrics/BlockLength:
13
+ Enabled: true
14
+ Exclude:
15
+ - spec/**/*
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: true
19
+ Max: 100
20
+
21
+ Naming/FileName:
22
+ Enabled: true
23
+ Exclude:
24
+ - lib/one-mentor-ruby.rb
25
+
26
+ RSpec/ExampleLength:
27
+ Enabled: false
28
+ Exclude:
29
+ - lib/one-mentor-ruby/actions/**/*
30
+
31
+ RSpec/InstanceVariable:
32
+ Enabled: false
33
+
34
+ RSpec/MultipleMemoizedHelpers:
35
+ Enabled: false
36
+
37
+ RSpec/SpecFilePathFormat:
38
+ Enabled: false
39
+
40
+ RSpec/SubjectStub:
41
+ Enabled: false
42
+
43
+ RSpec/VerifiedDoubles:
44
+ Enabled: false
45
+
46
+ Style/Documentation:
47
+ Enabled: false
48
+
49
+ Style/StringLiterals:
50
+ Enabled: true
51
+ EnforcedStyle: single_quotes
52
+
53
+ Style/StringLiteralsInInterpolation:
54
+ Enabled: true
55
+ EnforcedStyle: double_quotes
56
+
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.4.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## v0.1.0
2
+
3
+ Initial release of the gem.
4
+
5
+ ## [Unreleased]
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'faraday', '>= 2.0.1'
6
+
7
+ group :development, :test do
8
+ gem 'base64', '~> 0.3.0'
9
+ gem 'benchmark', '~> 0.4.1'
10
+ gem 'ostruct', '~> 0.6.3'
11
+ gem 'rake', '~> 13.0.6'
12
+ gem 'rspec', '~> 3.12.0'
13
+ gem 'rspec_junit_formatter', '~> 0.6.0'
14
+ gem 'rubocop', '~> 1.79.2'
15
+ gem 'rubocop-rspec', '~> 3.6.0'
16
+ gem 'webmock', '~> 3.18.1'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.8.7)
5
+ public_suffix (>= 2.0.2, < 7.0)
6
+ ast (2.4.3)
7
+ base64 (0.3.0)
8
+ benchmark (0.4.1)
9
+ bigdecimal (3.2.2)
10
+ crack (1.0.0)
11
+ bigdecimal
12
+ rexml
13
+ diff-lcs (1.6.2)
14
+ faraday (2.13.4)
15
+ faraday-net_http (>= 2.0, < 3.5)
16
+ json
17
+ logger
18
+ faraday-net_http (3.4.1)
19
+ net-http (>= 0.5.0)
20
+ hashdiff (1.2.0)
21
+ json (2.13.2)
22
+ language_server-protocol (3.17.0.5)
23
+ lint_roller (1.1.0)
24
+ logger (1.7.0)
25
+ net-http (0.6.0)
26
+ uri
27
+ ostruct (0.6.3)
28
+ parallel (1.27.0)
29
+ parser (3.3.9.0)
30
+ ast (~> 2.4.1)
31
+ racc
32
+ prism (1.4.0)
33
+ public_suffix (6.0.2)
34
+ racc (1.8.1)
35
+ rainbow (3.1.1)
36
+ rake (13.0.6)
37
+ regexp_parser (2.11.1)
38
+ rexml (3.4.1)
39
+ rspec (3.12.0)
40
+ rspec-core (~> 3.12.0)
41
+ rspec-expectations (~> 3.12.0)
42
+ rspec-mocks (~> 3.12.0)
43
+ rspec-core (3.12.3)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-expectations (3.12.4)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-mocks (3.12.7)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.12.0)
51
+ rspec-support (3.12.2)
52
+ rspec_junit_formatter (0.6.0)
53
+ rspec-core (>= 2, < 4, != 2.12.0)
54
+ rubocop (1.79.2)
55
+ json (~> 2.3)
56
+ language_server-protocol (~> 3.17.0.2)
57
+ lint_roller (~> 1.1.0)
58
+ parallel (~> 1.10)
59
+ parser (>= 3.3.0.2)
60
+ rainbow (>= 2.2.2, < 4.0)
61
+ regexp_parser (>= 2.9.3, < 3.0)
62
+ rubocop-ast (>= 1.46.0, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 2.4.0, < 4.0)
65
+ rubocop-ast (1.46.0)
66
+ parser (>= 3.3.7.2)
67
+ prism (~> 1.4)
68
+ rubocop-rspec (3.6.0)
69
+ lint_roller (~> 1.1)
70
+ rubocop (~> 1.72, >= 1.72.1)
71
+ ruby-progressbar (1.13.0)
72
+ unicode-display_width (2.6.0)
73
+ uri (1.0.3)
74
+ webmock (3.18.1)
75
+ addressable (>= 2.8.0)
76
+ crack (>= 0.3.2)
77
+ hashdiff (>= 0.4.0, < 2.0.0)
78
+
79
+ PLATFORMS
80
+ arm64-darwin-24
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ base64 (~> 0.3.0)
85
+ benchmark (~> 0.4.1)
86
+ faraday (>= 2.0.1)
87
+ ostruct (~> 0.6.3)
88
+ rake (~> 13.0.6)
89
+ rspec (~> 3.12.0)
90
+ rspec_junit_formatter (~> 0.6.0)
91
+ rubocop (~> 1.79.2)
92
+ rubocop-rspec (~> 3.6.0)
93
+ webmock (~> 3.18.1)
94
+
95
+ BUNDLED WITH
96
+ 2.6.8
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Riipen
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # one-mentor-ruby
2
+
3
+ A GraphQL client for 1Mentor in ruby.
4
+
5
+ ## Installation
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'one-mentor-ruby'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Usage
16
+
17
+ ### API Client
18
+
19
+ The 1Mentor API client uses an API key to authenticate API requests.
20
+
21
+ To obtain an API key talk to your 1Mentor representative.
22
+
23
+ Then you can create a 1MEntor API client.
24
+
25
+ ```ruby
26
+ client = OneMentor::Client.new(
27
+ api_key: 'my_key',
28
+ subdomain: 'my-subdomain' # Your API instance subdomain
29
+ timeout: 30, # Optional setting for timeouts of all requests (default 60)
30
+ )
31
+ ```
32
+
33
+ ### API Endpoints
34
+
35
+ 1Mentor currently does not have any public facing documantion available, so support for endpoints is limited.
36
+
37
+ ### List learner career objectives
38
+
39
+ Example: `client.learner_career_objectives(email@learner.com)`
40
+
41
+ Returns the following array
42
+
43
+ ```json
44
+ [
45
+ {},
46
+ {},
47
+ {},
48
+ ]
49
+ ```
50
+
51
+ ### Check learner
52
+
53
+ Example: `client.learner_exists(email@learner.com)`
54
+
55
+ Returns `true` if the email address is tied to a learner account, `false` otherwise.
56
+
57
+ ### Custom requests
58
+
59
+ Because the 1Mentor API is a wrapper on top of a GraphQL API, adhoc requests can be made
60
+ using the applicable GraphQL syntax.
61
+
62
+ Example:
63
+
64
+ ```
65
+ query = <<~GRAPHQL
66
+ query GetLearnerCareerObjectivesAndSkillGaps($studentEmail: NonEmptyString!)
67
+ {
68
+ getLearnerCareerObjectivesAndSkillGaps(studentEmail: $studentEmail) {
69
+ status
70
+ message
71
+ }
72
+ }
73
+ GRAPHQL
74
+
75
+ client.request({
76
+ operationName: 'GetLearnerCareerObjectivesAndSkillGaps',
77
+ query:,
78
+ variables: {
79
+ studentEmail: email
80
+ },
81
+ })
82
+ ```
83
+
84
+ Custom requests will return the raw data structure from 1Mentor in this form:
85
+
86
+ ```json
87
+ {
88
+ "data": {
89
+ "getLearnerCareerObjectivesAndSkillGaps": {
90
+ "status": true,
91
+ "message": ""
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ ### Pagination
98
+
99
+ 1Mentor does not currently support pagination.
100
+
101
+ ### Errors
102
+
103
+ Any error code returned by the OneMentor API will result in one of the following expections
104
+
105
+ |Code|Exception|
106
+ |----|---------|
107
+ |400| OneMentor::BadRequest|
108
+ |401| OneMentor::Unauthorized|
109
+ |403| OneMentor::Forbidden|
110
+ |404| OneMentor::NotFound|
111
+ |429| OneMentor::TooManyRequests|
112
+ |400...499| OneMentor::ClientError|
113
+ |500| OneMentor::InternalServerError|
114
+ |502| OneMentor::BadGateway|
115
+ |503| OneMentor::ServiceUnavailable|
116
+ |500...599| OneMentor::ServerError|
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneMentor
4
+ module Actions
5
+ module Base
6
+ def request(body)
7
+ connection.post('graphql', body)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneMentor
4
+ module Actions
5
+ module Learners
6
+ def learner_career_objectives(email)
7
+ query = <<~GRAPHQL
8
+ query GetLearnerCareerObjectivesAndSkillGaps($studentEmail: NonEmptyString!)
9
+ {
10
+ getLearnerCareerObjectivesAndSkillGaps(studentEmail: $studentEmail) {
11
+ status
12
+ message
13
+ careerObjectives {
14
+ occupation
15
+ gaps
16
+ }
17
+ }
18
+ }
19
+ GRAPHQL
20
+
21
+ response = connection.post('graphql', {
22
+ operationName: 'GetLearnerCareerObjectivesAndSkillGaps',
23
+ query: query,
24
+ variables: {
25
+ studentEmail: email
26
+ }
27
+ })
28
+
29
+ if response.dig('data', 'getLearnerCareerObjectivesAndSkillGaps', 'status')
30
+ response.dig('data', 'getLearnerCareerObjectivesAndSkillGaps', 'careerObjectives')
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ def learner_exists(email)
37
+ query = <<~GRAPHQL
38
+ query GetLearnerCareerObjectivesAndSkillGaps($studentEmail: NonEmptyString!)
39
+ {
40
+ getLearnerCareerObjectivesAndSkillGaps(studentEmail: $studentEmail) {
41
+ status
42
+ message
43
+ }
44
+ }
45
+ GRAPHQL
46
+
47
+ response = connection.post('graphql', {
48
+ operationName: 'GetLearnerCareerObjectivesAndSkillGaps',
49
+ query: query,
50
+ variables: {
51
+ studentEmail: email
52
+ }
53
+ })
54
+
55
+ response.dig('data', 'getLearnerCareerObjectivesAndSkillGaps', 'status')
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneMentor
4
+ class Client
5
+ include OneMentor::Actions::Base
6
+ include OneMentor::Actions::Learners
7
+
8
+ attr_reader :subdomain, :api_key, :base_url
9
+
10
+ def initialize(subdomain:, api_key:)
11
+ @subdomain = subdomain
12
+ @api_key = api_key
13
+
14
+ @base_url = "https://#{subdomain}.1mentor.io/external"
15
+ end
16
+
17
+ def connection
18
+ Connection.new(@base_url, @api_key)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module OneMentor
6
+ class Connection
7
+ def initialize(url, api_key, options = { timeout: 60 })
8
+ @connection = Faraday.new(url: url) do |builder|
9
+ builder.request :json
10
+ builder.headers[:accept] = 'application/json'
11
+ builder.headers['Content-Type'] = 'application/json'
12
+ builder.headers['x-api-key'] = api_key
13
+ builder.response :json
14
+ builder.options.timeout = options[:timeout]
15
+ end
16
+ end
17
+
18
+ def post(path, params = {})
19
+ request(:post, path, params)
20
+ end
21
+
22
+ def request(method, path, params = {})
23
+ response = @connection.send(method, path, params)
24
+
25
+ error = Error.from_response(response)
26
+
27
+ raise error if error
28
+
29
+ response.body
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneMentor
4
+ class Error < StandardError
5
+ attr_reader :response
6
+
7
+ def self.from_response(response) # rubocop:disable Metrics/CyclomaticComplexity
8
+ klass =
9
+ case response.status
10
+ when 400 then BadRequest
11
+ when 401 then Unauthorized
12
+ when 403 then Forbidden
13
+ when 404 then NotFound
14
+ when 429 then TooManyRequests
15
+ when 400..499 then ClientError
16
+ when 500 then InternalServerError
17
+ when 503 then ServiceUnavailable
18
+ when 500..599 then ServerError
19
+ end
20
+
21
+ klass&.new(response)
22
+ end
23
+
24
+ def initialize(response = nil)
25
+ @response = response
26
+ super(build_error_message)
27
+ end
28
+
29
+ private
30
+
31
+ def build_error_message
32
+ return nil if @response.nil?
33
+
34
+ @response.body
35
+ end
36
+ end
37
+
38
+ class ClientError < Error; end
39
+ class BadRequest < Error; end
40
+ class Unauthorized < Error; end
41
+ class Forbidden < Error; end
42
+ class NotFound < Error; end
43
+ class TooManyRequests < Error; end
44
+ class ServerError < Error; end
45
+ class InternalServerError < Error; end
46
+ class BadGateway < Error; end
47
+ class ServiceUnavailable < Error; end
48
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OneMentor
4
+ VERSION = '0.2.0'
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__)
4
+
5
+ require 'one-mentor-ruby/actions/base'
6
+ require 'one-mentor-ruby/actions/learners'
7
+
8
+ require 'one-mentor-ruby/client'
9
+ require 'one-mentor-ruby/connection'
10
+ require 'one-mentor-ruby/error'
11
+ require 'one-mentor-ruby/version'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: one-mentor-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Ell
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '2.0'
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.0.1
32
+ description: Access the 1Mentor REST API.
33
+ email:
34
+ - jordan.ell@riipen.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ".rspec"
40
+ - ".rubocop.yml"
41
+ - ".tool-versions"
42
+ - CHANGELOG.md
43
+ - Gemfile
44
+ - Gemfile.lock
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - lib/one-mentor-ruby.rb
49
+ - lib/one-mentor-ruby/actions/base.rb
50
+ - lib/one-mentor-ruby/actions/learners.rb
51
+ - lib/one-mentor-ruby/client.rb
52
+ - lib/one-mentor-ruby/connection.rb
53
+ - lib/one-mentor-ruby/error.rb
54
+ - lib/one-mentor-ruby/version.rb
55
+ homepage: https://github.com/riipen/one-mentor-ruby
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ homepage_uri: https://github.com/riipen/one-mentor-ruby
60
+ changelog_uri: https://github.com/riipen/one-mentor-ruby/blob/master/CHANGELOG.md
61
+ rubygems_mfa_required: 'true'
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '2.6'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.6.7
77
+ specification_version: 4
78
+ summary: An API client for 1Mentor in ruby.
79
+ test_files: []