ibm_tools-people 1.0.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: 2debfa9c940c4182b2962f1b9485c78ea6b9efec873c8bceae18c5d5e27fb723
4
+ data.tar.gz: b59431afe705a591f2ff3d4176780f424cbe881a2aa4b910f82f6de92c68d8f0
5
+ SHA512:
6
+ metadata.gz: d42baeba070d06277968661e2bd3f2fecba81f2c029655302ba9aea6b693962764cb5a9f06f7d0d68a06fd10dfbaf2fd75e24903071565ead1a971f687bcf476
7
+ data.tar.gz: e135ee2e3bb8b84a7e39f7a8ccc69a0c4cd9c96e44305d604d73e39f36cd134ae8186a038d9c967f9e5d0b13e7181a27ff9602cdf9faf8214ae1366488ad13ae
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.byebug_history
10
+ ibm_tools-people*.gem
11
+ .DS_Store
12
+ Gemfile.lock
@@ -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 thiagogs@br.ibm.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/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ibm_tools-people.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Thiago
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Thiago Silva
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,269 @@
1
+ # IMPORTANT
2
+ Due to the `case-2022-05-05-1450` opened by the __CSIRT team__ we had to migrate from the Public Github to the Github Enterprise, this change forced us to change the name of the gem.
3
+
4
+ Since the ruby does require the name of the gem to be used as the name of the class. Check below what changed:
5
+
6
+ ## Action 1 - Gemfile
7
+ Change the name of the gem to the new one in your Gemfile file and hit `bundle install` on your terminal.
8
+ ```ruby
9
+ # From
10
+ gem 'rails_ibm-uprofile', '~> 0.3.2', require: 'rails_ibm/uprofile'
11
+
12
+ # To
13
+ gem 'ibm_tools-people', '~> 0.0.2', require: 'ibm_tools/people'
14
+ ```
15
+
16
+ ## Action 2 - Usage
17
+ Change everywhere you have within your application from the old class name to the new one.
18
+ ```ruby
19
+ # From
20
+ RailsIbm::Uprofile.info
21
+
22
+ # To
23
+ IbmTools::People.info
24
+ ```
25
+
26
+ From now on it should be transparent and require no other action.
27
+ _________
28
+ <br><br>
29
+
30
+ # IBM Tools
31
+
32
+ Welcome to your Rais IBM Tools module! This gem intend to provide you some fetures used on IBM Web applications __*__.
33
+
34
+ > __*__ IBM VPN is required
35
+
36
+ ### IBM Tools\People
37
+
38
+ Fetch data from the user based on search params.
39
+
40
+ ### IBM Tools\SSO
41
+
42
+ Feature to come.
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the IbmTools::People project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.ibm.com/thiagogs/ibm_tools-people/blob/master/CODE_OF_CONDUCT.md).
47
+
48
+ ## Table of Contents
49
+
50
+ - [Installation](#installation)
51
+ - [Usage](#usage)
52
+ - [Method: info](#method-info)
53
+ - [Method: skills](#method-skills)
54
+ - [Method: teams](#method-teams)
55
+ - [Method: all](#method-all)
56
+ - [Contributing](#contributing)
57
+ - [License](#license)
58
+
59
+ ## Installation
60
+
61
+ Add this line to your application's Gemfile:
62
+
63
+ ```ruby
64
+ gem 'ibm_tools-people'
65
+ ```
66
+
67
+ And then execute:
68
+
69
+ $ bundle install
70
+
71
+ Or install it yourself as:
72
+
73
+ $ gem install ibm_tools-people
74
+
75
+
76
+ # IbmTools::People
77
+
78
+ This module allow you to fetch information from Profile directory (using the [Unified-profile](https://w3.ibm.com/w3publisher/bluepages-ui-support)).
79
+
80
+ ## Usage
81
+
82
+ This module have different methods to search the users and provide different data:
83
+
84
+ ### <a id="method-info"></a>#Info(args*: value[, options])
85
+
86
+ This module allos you to search one or more entries at time, it will return the information about the employee(s)
87
+
88
+ ```ruby
89
+ require 'ibm_tools/people'
90
+
91
+ IbmTools::People.info(uid: '000000000')
92
+ ```
93
+
94
+ #### Args*
95
+
96
+ Since there are different kind of ways to search the user and to ensure readability we split it in several alternatives. It is important to know that at least one of these args are __required__.
97
+
98
+ | name | value | Usage
99
+ | --- | --- | ---
100
+ | uid | String | `IbmTools::People.info(uid: '000000000')`
101
+ | uids | Array | `IbmTools::People.info(uids: ['000000000', '111111111'])`
102
+ | email | String | `IbmTools::People.info(email: 'johndoe@ibm.com')`
103
+ | emails | Array | `IbmTools::People.info(emails: ['johndoe@ibm.com', 'janedoe@ibm.com'])`
104
+ | query | String | `IbmTools::People.info(query: 'John Doe')`
105
+
106
+ #### Options (`optional`)
107
+
108
+ | Attribure | Type | Default | Purpose
109
+ | --- | --- | --- | ---
110
+ | parsed | Boolean | true | Returns a [Parsed Object](#parsed-object)<br><sup>if __false__ Return a [PeopleUnifiedProfileAPI](https://unified-profile-api.us-south-k8s.intranet.ibm.com/v3/api/) Object</sup>
111
+ | remap | Boolean | false | Returns a [Remapped Object](#remapped-object).<br><sup>This option is ignored if `parsed` is __true__</sup>
112
+ | serial | String | '000000' | Will increase the performance of the search by fetching first entries that are peers from the serial informed.<br><sup>Only available for __query__ arg.</sup>
113
+ | limit | Number | 10 | Will limit the result of the API in the number specified.<br><sup>Only available for __query__ arg.</sup>
114
+ | start | Number | 0 | Will start from this position of the list (common used for pagination).<br><sup>Only available for __query__ arg.</sup>
115
+ | array | Boolean | true | The result will be an array instead of an object.<br><sup>Only available for __query__ arg.</sup><br><sup>This option is ignored if `detailed` is __false__.</sup>
116
+
117
+ #### Schemas
118
+
119
+ These are the following models available in this API.
120
+
121
+ ##### Parsed Object
122
+
123
+ ###### UID
124
+ ```ruby
125
+ {
126
+ :"uid_#{query}": PeopleUnifiedProfileAPI.content
127
+ }
128
+
129
+ # Ex.:
130
+ # $ IbmTools::People.info(uid: '000000000')
131
+ # $ => { uid_000000000: PeopleUnifiedProfileAPI.content }
132
+ ```
133
+ >
134
+
135
+ ###### Email
136
+ ```ruby
137
+ {
138
+ :"#{query}": PeopleUnifiedProfileAPI.content
139
+ }
140
+
141
+ # Ex.:
142
+ # $ IbmTools::People.info(email: 'johndoe@ibm.com')
143
+ # $ => { johndoe@ibm.com: PeopleUnifiedProfileAPI.content }
144
+ ```
145
+
146
+ ##### Remapped Object
147
+
148
+ It will rewrite the object to a DefaultTemplate used by this module (preferred for authentications)
149
+
150
+ ###### DefaultTemplate
151
+
152
+ ```ruby
153
+ {
154
+ uid: PeopleUnifiedProfileAPI.content.uid,
155
+ name: PeopleUnifiedProfileAPI.content.nameFull,
156
+ email: PeopleUnifiedProfileAPI.content.preferredIdentity,
157
+ shortname: PeopleUnifiedProfileAPI.content.nameDisplay || PeopleUnifiedProfileAPI.content.nameFull
158
+ }
159
+ ```
160
+
161
+ ###### UID
162
+ ```ruby
163
+ {
164
+ :"uid_#{query}": DefaultTemplate
165
+ }
166
+
167
+ # Ex.:
168
+ # $ IbmTools::People.info(uid: '000000000')
169
+ # $ => { uid_000000000: ShortDataUserObject }
170
+ ```
171
+ >
172
+
173
+ ###### Email
174
+ ```ruby
175
+ {
176
+ :"#{query}": DefaultTemplate
177
+ }
178
+
179
+ # Ex.:
180
+ # $ IbmTools::People.info(email: 'johndoe@ibm.com')
181
+ # $ => { johndoe@ibm.com: ShortDataUserObject }
182
+ ```
183
+
184
+ ### <a id="method-skills"></a>#Skills(args*: value)
185
+
186
+ This method only allows one search at time and it will return the skill set information of the employee.
187
+
188
+ ```ruby
189
+ require 'ibm_tools/people'
190
+
191
+ IbmTools::People.skills(uid: '000000000')
192
+ ```
193
+
194
+ This module have 2 variations, you can check the details below:
195
+
196
+ #### Args*
197
+
198
+ Since there are different kind of ways to search the user and to ensure readability we split it in several alternatives. It is important to know that at least one of these args are __required__.
199
+
200
+ | name | value | Usage
201
+ | --- | --- | ---
202
+ | uid | String | `IbmTools::People.info(uid: '000000000')`
203
+ | email | String | `IbmTools::People.info(email: 'johndoe@ibm.com')`
204
+
205
+ #### Schemas
206
+
207
+ There are no special remapping or parsing for this results, the schema can be checked on [PeopleUnifiedProfileAPI](https://unified-profile-api.us-south-k8s.intranet.ibm.com/v3/api/) docs
208
+
209
+ ### <a id="method-teams"></a>#Teams(args*: value)
210
+
211
+ This method only allows one search at time and it will return the peers and hierarchical tree of the employee (Inside and Outside the country)
212
+
213
+ ```ruby
214
+ require 'ibm_tools/people'
215
+
216
+ IbmTools::People.skills(uid: '000000000')
217
+ ```
218
+
219
+ This module have 2 variations, you can check the details below:
220
+
221
+ #### Args*
222
+
223
+ Since there are different kind of ways to search the user and to ensure readability we split it in several alternatives. It is important to know that at least one of these args are __required__.
224
+
225
+ | name | value | Usage
226
+ | --- | --- | ---
227
+ | uid | String | `IbmTools::People.info(uid: '000000000')`
228
+ | email | String | `IbmTools::People.info(email: 'johndoe@ibm.com')`
229
+
230
+ #### Schemas
231
+
232
+ There are no special remapping or parsing for this results, the schema can be checked on [PeopleUnifiedProfileAPI](https://unified-profile-api.us-south-k8s.intranet.ibm.com/v3/api/) docs
233
+
234
+ ### <a id="method-all"></a>#all(args*: value)
235
+
236
+ This method only allows one search at time and it will return the peers and hierarchical tree of the employee (Inside and Outside the country)
237
+
238
+ ```ruby
239
+ require 'ibm_tools/people'
240
+
241
+ IbmTools::People.skills(uid: '000000000')
242
+ ```
243
+
244
+ This module have 2 variations, you can check the details below:
245
+
246
+ #### Args*
247
+
248
+ Since there are different kind of ways to search the user and to ensure readability we split it in several alternatives. It is important to know that at least one of these args are __required__.
249
+
250
+ | name | value | Usage
251
+ | --- | --- | ---
252
+ | uid | String | `IbmTools::People.info(uid: '000000000')`
253
+ | email | String | `IbmTools::People.info(email: 'johndoe@ibm.com')`
254
+
255
+ #### Schemas
256
+
257
+ There are no special remapping or parsing for this results, the schema can be checked on [PeopleUnifiedProfileAPI](https://unified-profile-api.us-south-k8s.intranet.ibm.com/v3/api/) docs
258
+
259
+ ## Tests
260
+
261
+ I'm in shame to do this, but since I was in a hurry, we got some testers to verify this project, and I know I should implement some automated tests. But this module were created for a project and because of this I had to do this way.
262
+
263
+ ## Contributing
264
+
265
+ Bug reports and pull requests are welcome on GitHub at https://github.ibm.com/thiagogs/ibm_tools-people. 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.ibm.com/thiagogs/ibm_tools-people/blob/master/CODE_OF_CONDUCT.md).
266
+
267
+ ## License
268
+
269
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rails_ibm/uprofile"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ibm_tools/people/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ibm_tools-people"
7
+ spec.version = IbmTools::People::VERSION
8
+ spec.authors = ["Thiago Silva"]
9
+ spec.email = ["thiagogs@br.ibm.com"]
10
+
11
+ spec.summary = "IBM Module - Profile"
12
+ spec.description = "This module Allow the user to retrieve information from the IBM unified profile program."
13
+ spec.homepage = "https://github.ibm.com/thiagogs/ibm_tools-people"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ # spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "https://github.ibm.com/thiagogs/ibm_tools-people"
21
+ # spec.metadata["changelog_uri"] = "https://github.ibm.com/thiagogs/ibm_tools-people/releases"
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(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib", "lib/ibm_tools/people/profile"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ spec.add_dependency 'httparty', '~> 0.18.1'
35
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,64 @@
1
+ require 'httparty'
2
+
3
+ module IbmTools
4
+ module People
5
+ class Arguments
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def filter(allowed, options = nil)
11
+ (options || @options).select {|k,v| allowed.include?(k) }
12
+ end
13
+
14
+ def validate
15
+ raise SyntaxError.new description: "Invalid Argument. #{DOC_LINK}" if invalid_options
16
+ raise SyntaxError.new description: "More than one required Argument. #{DOC_LINK}" if multiple
17
+ raise SyntaxError.new description: "Missing required Argument. #{DOC_LINK}" if missing
18
+ raise TypeError.new description: "Invalid Argument type. #{DOC_LINK}" if invalid_type || unmatch_type
19
+
20
+ true
21
+ end
22
+
23
+ private
24
+
25
+ def value
26
+ @options[:uids] || @options[:emails] || @options[:uid] || @options[:email] || @options[:query]
27
+ end
28
+
29
+ def missing
30
+ value == nil
31
+ end
32
+
33
+ def multiple
34
+ allowed = %i[uid uids email emails query]
35
+ @options.keys.select { |k| allowed.include?(k) }.size > 1
36
+ end
37
+
38
+ def invalid_type
39
+ config = { type: Array, value: value }
40
+ config[:type] = String if @options.include?(:uid) || @options.include?(:email) || @options.include?(:query)
41
+
42
+ !config[:value].is_a?(config[:type])
43
+ end
44
+
45
+ def unmatch_type
46
+ entry = value
47
+ entry = value.first if value.is_a? Array
48
+
49
+ return is_valid_email?(entry) if @options.include?(:uid) || @options.include?(:uids)
50
+ return !is_valid_email?(entry) if @options.include?(:email) || @options.include?(:emails)
51
+ false
52
+ end
53
+
54
+ def invalid_options
55
+ !@options.is_a? Hash
56
+ end
57
+
58
+ def is_valid_email?(email)
59
+ (email =~ IbmTools::People::EMAIL_REGEX) != nil
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ require 'httparty'
2
+
3
+ module IbmTools
4
+ module People
5
+ module Async
6
+ def self.Requests(uris, headers)
7
+ threads = []
8
+ responses = []
9
+
10
+ [uris].flatten.each do |uri|
11
+ threads << Thread.new do
12
+ responses << HTTParty.get(uri, headers: headers)
13
+ end
14
+ end
15
+
16
+ # wait for threads to finish before ending program.
17
+ threads.each { |t| t.join }
18
+ OpenStruct.new(body: "[#{responses.map(&:body).join(",")}]", code: 200)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'search'
2
+ require_relative "../version"
3
+
4
+ module IbmTools
5
+ module People
6
+ module Profile
7
+ class All < Search
8
+ def initialize(query)
9
+ @response = HTTParty.get(uri(query: query), header: headers)
10
+ end
11
+
12
+ def results
13
+ search_results
14
+ end
15
+
16
+ private
17
+
18
+ def uri(query:)
19
+ "#{IbmTools::People::BLUEPAGES_V3_URI}/#{query}/profile_combined"
20
+ end
21
+
22
+ def headers
23
+ {
24
+ 'Content-Type': 'application/json',
25
+ accept: 'application/json'
26
+ }
27
+ end
28
+
29
+ def search_type
30
+ 'all'
31
+ end
32
+
33
+ def search_results
34
+ JSON.parse @response.body, symbolize_names: true
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'search'
2
+
3
+ module IbmTools
4
+ module People
5
+ module Profile
6
+ class Email < Search
7
+ def search_type
8
+ 'email'
9
+ end
10
+
11
+ def search_results(parsed:, remap:)
12
+ return JSON.parse @response.body, symbolize_names: true unless parsed
13
+ results = {}
14
+
15
+ @query.compact.each do |query_term|
16
+ results.merge!(query_term.to_sym => result_for(query_term, remap))
17
+ end
18
+
19
+ results
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'httparty'
2
+ require_relative 'mapper'
3
+ require_relative '../async'
4
+
5
+ module IbmTools
6
+ module People
7
+ module Profile
8
+ class Fetch
9
+ def initialize(uri:)
10
+ @uri = uri
11
+ end
12
+
13
+ def execute(query:)
14
+ @query = query
15
+
16
+ return HTTParty.get("#{@uri}/#{uri_params(query)}", headers: headers) unless multiple_search
17
+ IbmTools::People::Async.Requests chunks(query).map { |c| "#{@uri}/#{uri_params(c)}" }, headers
18
+ end
19
+
20
+ private
21
+
22
+ def multiple_search
23
+ @query.is_a?(Array) && @query.size >= 2
24
+ end
25
+
26
+ def uri_params(users)
27
+ return users.join(',') if multiple_search
28
+ "#{users.first}/profile"
29
+ end
30
+
31
+ def encode_uri(users)
32
+ "#{@uri}/#{ERB::Util.url_encode(uri_params(users))}"
33
+ end
34
+
35
+ def chunks(users)
36
+ partial = [[]]
37
+ users.each do |u|
38
+ partial.last.push(u)
39
+ partial.push([]) if encode_uri(partial.last).length > 5000
40
+ end
41
+
42
+ partial
43
+ end
44
+
45
+ def headers
46
+ {
47
+ 'Content-Type': 'application/json',
48
+ accept: 'application/json'
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ module IbmTools
2
+ module People
3
+ module Profile
4
+ class Mapper
5
+ private
6
+
7
+ def parse_user(response, dig_params, remap: true)
8
+ return nil if response.nil?
9
+
10
+ user_info = response.dig(*dig_params)
11
+ return nil if user_info.nil?
12
+
13
+ if user_info.is_a?(Array)
14
+ user_info.map { |user| remap_obj(data: user, remap: remap) }
15
+ else
16
+ remap_obj(data: user_info, remap: remap)
17
+ end
18
+ end
19
+
20
+ def remap_obj(data:, remap: true)
21
+ return data unless remap
22
+
23
+ user = {
24
+ uid: data[:uid],
25
+ name: data[:nameFull],
26
+ email: data[:preferredIdentity],
27
+ shortname: data[:nameDisplay] || data[:nameFull]
28
+ }
29
+
30
+ user[:is_manager] = data[:employeeType][:isManager] if data[:employeeType] != nil && data[:employeeType][:isManager] != nil
31
+ user
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,65 @@
1
+ require 'httparty'
2
+ require_relative 'mapper'
3
+ require_relative 'fetch'
4
+ require_relative "../version"
5
+
6
+ # Class responsible for making calls to retrieve user information from the Unified Profile API
7
+ module IbmTools
8
+ module People
9
+ module Profile
10
+ class Search < Mapper
11
+ class IbmTools::People::Profile::SearchError < StandardError; end
12
+
13
+ def initialize(query)
14
+ @query = [query].flatten
15
+
16
+ fetch = IbmTools::People::Profile::Fetch.new(uri: IbmTools::People::BLUEPAGES_V3_URI)
17
+ @response = fetch.execute(query: @query)
18
+ end
19
+
20
+ def search_type
21
+ raise StandardError.new description: "#search_type should be overriden by #{self.class}"
22
+ end
23
+
24
+ def results(parsed: true, remap: false)
25
+ search_results(parsed: parsed, remap: remap)
26
+ end
27
+
28
+ private
29
+
30
+ def search_results(parsed:, remap:)
31
+ raise StandardError.new description: "#search_results should be overriden by #{self.class}"
32
+ end
33
+
34
+ def result_for(query_term, remap)
35
+ parsed_users(remap).select { |parsed_user| parsed_user&.values&.include? query_term }.first
36
+ rescue Exception => e
37
+ raise IbmTools::People::Profile::SearchError, e.message
38
+ end
39
+
40
+ def response_valid?
41
+ @response.code >= 200 && @response.code <= 399
42
+ end
43
+
44
+ def parsed_users(remap)
45
+ return [] unless response_valid?
46
+
47
+ parsed_results = JSON.parse @response.body, symbolize_names: true
48
+ parsed_results = parse_multiple_profiles([parsed_results]) if multiple_search
49
+
50
+ [parsed_results].flatten.map { |result| parse_user result, %i[content], remap: remap }
51
+ rescue JSON::ParserError
52
+ []
53
+ end
54
+
55
+ def multiple_search
56
+ @query.is_a?(Array) && @query.size >= 2
57
+ end
58
+
59
+ def parse_multiple_profiles(data)
60
+ data.flatten.map { |p| p[:profiles] }.flatten
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'search'
2
+ require_relative "../version"
3
+
4
+ module IbmTools
5
+ module People
6
+ module Profile
7
+ class Skills < Search
8
+ def initialize(query)
9
+ @response = HTTParty.get(uri(query: query), header: headers)
10
+ end
11
+
12
+ def results
13
+ search_results
14
+ end
15
+
16
+ private
17
+
18
+ def uri(query:)
19
+ "#{IbmTools::People::BLUEPAGES_V3_URI}/#{query}/profile_extended"
20
+ end
21
+
22
+ def headers
23
+ {
24
+ 'Content-Type': 'application/json',
25
+ accept: 'application/json'
26
+ }
27
+ end
28
+
29
+ def search_type
30
+ 'typeahead'
31
+ end
32
+
33
+ def search_results
34
+ JSON.parse @response.body, symbolize_names: true
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'search'
2
+ require_relative "../version"
3
+
4
+ module IbmTools
5
+ module People
6
+ module Profile
7
+ class Teams < Search
8
+ def initialize(query)
9
+ @response = HTTParty.get(uri(query: query), header: headers)
10
+ end
11
+
12
+ def results
13
+ search_results
14
+ end
15
+
16
+ private
17
+
18
+ def uri(query:)
19
+ "#{IbmTools::People::BLUEPAGES_V3_URI}/#{query}/teamResolved"
20
+ end
21
+
22
+ def headers
23
+ {
24
+ 'Content-Type': 'application/json',
25
+ accept: 'application/json'
26
+ }
27
+ end
28
+
29
+ def search_type
30
+ 'team'
31
+ end
32
+
33
+ def search_results
34
+ JSON.parse @response.body, symbolize_names: true
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'search'
2
+ require_relative 'email'
3
+ require_relative "../version"
4
+
5
+ module IbmTools
6
+ module People
7
+ module Profile
8
+ class Typeahead < Search
9
+ def initialize(query, serial: '000000', limit: 10, start: 0)
10
+ uri = "#{IbmTools::People::BLUEPAGES_V1_URI}?userId=#{serial}&rows=#{limit}&start=#{start}&query=#{query}&searchConfig=typeahead_search"
11
+ @response = HTTParty.get(uri, header: headers, format: :plain)
12
+ end
13
+
14
+ def results(options)
15
+ search_results(options)
16
+ end
17
+
18
+ private
19
+
20
+ def headers
21
+ {
22
+ 'Content-Type': 'application/json',
23
+ accept: 'application/json'
24
+ }
25
+ end
26
+
27
+ def search_type
28
+ 'typeahead'
29
+ end
30
+
31
+ def search_results(options)
32
+ results = JSON.parse @response, symbolize_names: true
33
+ return [] if results == nil
34
+
35
+ return results unless default_values(options)[:parsed]
36
+ parse_user results, %i[results], remap: default_values(options)[:remap]
37
+ end
38
+
39
+ def default_values(options)
40
+ default_params = { parsed: true, detailed: false, remap: false, array: true }
41
+ default_params.merge(options)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'search'
2
+
3
+ module IbmTools
4
+ module People
5
+ module Profile
6
+ class Uid < Search
7
+ def search_type
8
+ 'uid'
9
+ end
10
+
11
+ def search_results(parsed:, remap:)
12
+ return JSON.parse @response.body, symbolize_names: true unless parsed
13
+ results = {}
14
+
15
+ @query.compact.each do |query_term|
16
+ results.merge!("uid_#{query_term}".to_sym => result_for(query_term, remap))
17
+ end
18
+
19
+ results
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IbmTools
4
+ module People
5
+ VERSION = "1.0.0"
6
+ BLUEPAGES_V3_URI = "https://unified-profile-api.us-south-k8s.intranet.ibm.com/v3/profiles"
7
+ BLUEPAGES_V1_URI = "https://unified-profile-search-service.us-south-k8s.intranet.ibm.com/search"
8
+ EMAIL_REGEX = %r{\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z}i
9
+ end
10
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'people/version'
4
+ require_relative 'people/profile/email'
5
+ require_relative 'people/profile/uid'
6
+ require_relative 'people/profile/typeahead'
7
+ require_relative 'people/profile/skills'
8
+ require_relative 'people/profile/teams'
9
+ require_relative 'people/profile/all'
10
+ require_relative 'people/arguments'
11
+
12
+ module IbmTools
13
+ module People
14
+ class Error < StandardError; end
15
+ DOC_LINK = "Please refer to 'https://github.com/niightly/rails_ibm-uprofile/blob/master/README.md#usage' for more details.'".freeze
16
+
17
+ def self.info(options = {})
18
+ args = verify(options)
19
+
20
+ if options.include?(:emails) || options.include?(:email)
21
+ IbmTools::People::Profile::Email.new([options[:emails] || options[:email]].flatten).results(**args.filter(%i[parsed remap]))
22
+ elsif options.include?(:uids) || options.include?(:uid)
23
+ IbmTools::People::Profile::Uid.new([options[:uids] || options[:uid]].flatten).results(**args.filter(%i[parsed remap]))
24
+ elsif options.include?(:query)
25
+ IbmTools::People::Profile::Typeahead.new(options[:query], **default_params(options)).results(**args.filter(%i[parsed remap detailed array]))
26
+ end
27
+ end
28
+
29
+ def self.skills(options = {})
30
+ args = verify(options, single: true)
31
+ IbmTools::People::Profile::Skills.new(options[:uid] || options[:email]).results
32
+ end
33
+
34
+ def self.teams(options = {})
35
+ args = verify(options, single: true)
36
+ IbmTools::People::Profile::Teams.new(options[:uid] || options[:email]).results
37
+ end
38
+
39
+ def self.all(options = {})
40
+ args = verify(options, single: true)
41
+ IbmTools::People::Profile::All.new(options[:uid] || options[:email]).results
42
+ end
43
+
44
+ private
45
+
46
+ def self.verify(options, single: false)
47
+ args = IbmTools::People::Arguments.new(params(options, single))
48
+ args.validate
49
+
50
+ args
51
+ end
52
+
53
+ def self.default_params(options)
54
+ { serial: options[:serial] || '000000', limit: options[:limit] || 10, start: options[:start] || 0 }
55
+ end
56
+
57
+ def self.params(options, single)
58
+ return options unless single
59
+ options.tap { |hs| %i[uids emails].each { |k| hs.delete(k) } }
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ibm_tools-people
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thiago Silva
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 11.1.3
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '11.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 11.1.3
47
+ description: This module Allow the user to retrieve information from the IBM unified
48
+ profile program.
49
+ email:
50
+ - thiagogs@br.ibm.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".gitignore"
56
+ - CODE_OF_CONDUCT.md
57
+ - Gemfile
58
+ - LICENSE
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - bin/console
63
+ - bin/setup
64
+ - ibm_tools-people.gemspec
65
+ - lib/ibm_tools/people.rb
66
+ - lib/ibm_tools/people/arguments.rb
67
+ - lib/ibm_tools/people/async.rb
68
+ - lib/ibm_tools/people/profile/all.rb
69
+ - lib/ibm_tools/people/profile/email.rb
70
+ - lib/ibm_tools/people/profile/fetch.rb
71
+ - lib/ibm_tools/people/profile/mapper.rb
72
+ - lib/ibm_tools/people/profile/search.rb
73
+ - lib/ibm_tools/people/profile/skills.rb
74
+ - lib/ibm_tools/people/profile/teams.rb
75
+ - lib/ibm_tools/people/profile/typeahead.rb
76
+ - lib/ibm_tools/people/profile/uid.rb
77
+ - lib/ibm_tools/people/version.rb
78
+ homepage: https://github.ibm.com/thiagogs/ibm_tools-people
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ - lib/ibm_tools/people/profile
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.4.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.3.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: IBM Module - Profile
102
+ test_files: []