oracle_hcm 0.1.1

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: 30217904bdaf7fe51c434bad5e420ff155c706d17dc24ff900bd3e99c7b52f3c
4
+ data.tar.gz: aa624f11420a5dd1bbc2c3ed476f340df630eeb5fa052a09c50a66a2166ae974
5
+ SHA512:
6
+ metadata.gz: b66c7269e95b9e228ceac55ea66a01ea0deb72a7cb4260d3573542224f947f960fd74a39518fcb17383b795e66b1468ebc14d6138cc1db1906826fdd1a5e1c50
7
+ data.tar.gz: 7411fd20bbfc8b52386578b91709efbef07c7470ec94e29ab9c2cfab1d29d335a03991611571267e743205f6268558091ee722430c2b33b5ee08474398a2fc40
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /spec/reports/
7
+ /tmp/
8
+
9
+ # rspec failure tracking
10
+ .rspec_status
11
+
12
+ Gemfile.lock
13
+
14
+ /bin/test
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # oracle_hcm changelog
2
+
3
+ All notable changes to oracle_hcm will be documented in this file.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oracle_hcm.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Paul Holden
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,31 @@
1
+ # Oracle HCM SDK
2
+
3
+ This gem is a library for interacting with the Oracle HCM REST API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'oracle_hcm'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install oracle_hcm
20
+
21
+ ## Usage
22
+
23
+ Check back later.
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/paulholden2/oracle_hcm.
28
+
29
+ ## License
30
+
31
+ 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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oracle_hcm"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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,29 @@
1
+ require "oracle_hcm/resource"
2
+
3
+ module OracleHcm
4
+ # An Attachment is a child resource of a Document Record (or Document of
5
+ # Record), and stores upload file data and metadata.
6
+ class Attachment < Resource
7
+ property :attachment_document_id, key: "AttachmentDocumentId"
8
+ property :content_type, key: "UploadFileContentType"
9
+ property :content_size, key: "UploadFileContentLength"
10
+ property :title, key: "Title"
11
+
12
+ # Download the file via a readable IO object.
13
+ def download
14
+ io = StringIO.new
15
+ res = client.connection.get do |req|
16
+ req.url uri(rel: "enclosure")
17
+ req.options.on_data = Proc.new do |chunk, total_bytes|
18
+ io << chunk
19
+ end
20
+ end
21
+ if res.success?
22
+ io.rewind
23
+ io
24
+ else
25
+ nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,65 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "oracle_hcm/resource_list"
4
+ require "oracle_hcm/worker"
5
+ require "oracle_hcm/document_record"
6
+
7
+ module OracleHcm
8
+ class Client
9
+ attr_reader :endpoint, :username, :password
10
+
11
+ def initialize(endpoint, username, password)
12
+ @endpoint = endpoint
13
+ @username = username
14
+ @password = password
15
+ end
16
+
17
+ # Sugar syntax for defining top-level resources
18
+ def self.resource(method, resource:, url: resource.resource_name)
19
+ define_method(method) do |offset: 0, limit: 20, q: []|
20
+ if !q.is_a?(Array)
21
+ q = [q]
22
+ end
23
+ res = connection.get do |req|
24
+ req.url url
25
+ req.params["offset"] = offset
26
+ req.params["limit"] = limit
27
+ if q.any?
28
+ req.params["q"] = q.join(";")
29
+ end
30
+ end
31
+ if res.success?
32
+ ResourceList.new(JSON.parse(res.body), offset, limit, method, resource, self)
33
+ else
34
+ nil
35
+ end
36
+ end
37
+ end
38
+
39
+ # Retrieve worker resources.
40
+ resource :workers, resource: Worker
41
+ # Retrieve document record resources.
42
+ resource :document_records, resource: DocumentRecord
43
+
44
+ # Retrieve a single worker resource by PersonId
45
+ def worker(id:)
46
+ workers(q: "PersonId=#{id}").items.first
47
+ end
48
+
49
+ # Retrieve a single document record resource by DocumentsOfRecordId
50
+ def document_record(id:)
51
+ document_records(q: "DocumentsOfRecordId=#{id}").items.first
52
+ end
53
+
54
+ def base_url
55
+ "#{endpoint}/hcmRestApi/resources/11.13.18.05"
56
+ end
57
+
58
+ # Get an authenticated Faraday connection using given credentials.
59
+ def connection
60
+ Faraday.new(url: base_url) do |conn|
61
+ conn.basic_auth(username, password)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ require "oracle_hcm/resource"
2
+ require "oracle_hcm/attachment"
3
+
4
+ module OracleHcm
5
+ # A DocumentRecord is a resource that represents a record of document(s)
6
+ # of a given category for a Worker.
7
+ class DocumentRecord < Resource
8
+ property :document_record_id, key: "DocumentsOfRecordId"
9
+ property :category_code, key: "CategoryCode"
10
+ property :subcategory_code, key: "SubCategoryCode"
11
+ property :document_type, key: "DocumentType"
12
+ property :system_document_type, key: "SystemDocumentType"
13
+ child_resource :attachments, resource: Attachment
14
+
15
+ def canonical_id
16
+ document_record_id
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require "oracle_hcm/resource"
2
+
3
+ module OracleHcm
4
+ # A Name is a child resource of a Worker that stores various data about a
5
+ # Worker's name(s).
6
+ class Name < Resource
7
+ property :first_name, key: "FirstName"
8
+ property :last_name, key: "LastName"
9
+ property :previous_last_name, key: "PreviousLastName"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "oracle_hcm/resource"
2
+
3
+ module OracleHcm
4
+ # A NationalIdentifier is a child resource of a Worker that stores various
5
+ # uniquely identifying information about a Worker, such as their SSN.
6
+ class NationalIdentifier < Resource
7
+ property :national_identifier_type, key: "NationalIdentifierType"
8
+ property :national_identifier_number, key: "NationalIdentifierNumber"
9
+ property :primary_flag, key: "PrimaryFlag"
10
+ end
11
+ end
@@ -0,0 +1,97 @@
1
+ module OracleHcm
2
+ # Base class for all resources in Oracle HCM. Provides some sugar syntax
3
+ # and shared methods.
4
+ class Resource
5
+ attr_reader :data, :client, :parent
6
+
7
+ def initialize(data, client, parent = nil)
8
+ @data = data
9
+ @client = client
10
+ @parent = parent
11
+ @cache = {}
12
+ end
13
+
14
+ # Sugar syntax for defining methods that return data at given keys in
15
+ # the resource JSON. Properties are not a 1:1 match with data in the
16
+ # object JSON. They can be wrappers for sending requests to related
17
+ # resources such as names or addresses, although those are better defined
18
+ # as cached properties.
19
+ def self.property(name, key: nil, &block)
20
+ define_method(name) {
21
+ if block_given?
22
+ yield
23
+ else
24
+ data.fetch(key)
25
+ end
26
+ }
27
+ end
28
+
29
+ # Sugar syntax for defining properties that are cached to avoid making
30
+ # multiple requests for data that is not expected to change during
31
+ # execution, such as employee names or SSNs. Also defines a bang method
32
+ # that will skip and overwrite the cache.
33
+ def self.cached_property(name, &block)
34
+ bang = :"#{name.to_s}!"
35
+ define_method(bang) {
36
+ instance_variable_get(:@cache)[name] = instance_eval(&block)
37
+ }
38
+ define_method(name) {
39
+ @cache[name] || self.send(bang)
40
+ }
41
+ end
42
+
43
+ # Sugar syntax for defining child resource retrieval methods
44
+ def self.child_resource(method, resource:)
45
+ define_method(method) do |offset: 0, limit: 20, q: []|
46
+ # Generate the URL for the request
47
+ url = "#{resource_name}/#{canonical_id}/child/#{resource.resource_name}"
48
+ if !q.is_a?(Array)
49
+ q = [q]
50
+ end
51
+ res = client.connection.get do |req|
52
+ req.url url
53
+ req.params["offset"] = offset
54
+ req.params["limit"] = limit
55
+ if q.any?
56
+ req.params["q"] = q.join(";")
57
+ end
58
+ end
59
+ if res.success?
60
+ ResourceList.new(JSON.parse(res.body), offset, limit, method, resource, client, self)
61
+ else
62
+ nil
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.resource_name
68
+ name = self.to_s.split("::").last
69
+ "#{name[0].downcase}#{name[1..-1]}s"
70
+ end
71
+
72
+ def resource_name
73
+ self.class.resource_name
74
+ end
75
+
76
+ # Retrieve a link by its relationship. By default, returns the self link.
77
+ def link(rel: "self")
78
+ data.fetch("links").select { |link|
79
+ link.fetch("rel") == rel
80
+ }.first
81
+ end
82
+
83
+ # Although resources have unique identifiers, the API does not use these
84
+ # in the URL to retrieve some resources. Instead, a longer identifier
85
+ # string is used. This identifier is only displayed as part of the self
86
+ # link for the resource.
87
+ def canonical_id
88
+ # Extract resource identifier from self link
89
+ m = link.fetch("href").match(/\/([0-9A-F]+)\z/)
90
+ m[1]
91
+ end
92
+
93
+ def uri(rel: "self")
94
+ link(rel: rel).fetch("href").gsub(client.base_url, "")
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,27 @@
1
+ require "oracle_hcm/resource"
2
+
3
+ module OracleHcm
4
+ # A ResourceList is a helper object that makes it easy to poll through
5
+ # paginated resources.
6
+ class ResourceList < Resource
7
+ attr_reader :limit, :offset, :method, :resource, :client, :parent
8
+
9
+ def initialize(data, offset, limit, method, resource, client, parent = nil)
10
+ super(data, client)
11
+ @limit = limit
12
+ @offset = offset
13
+ @method = method
14
+ @resource = resource
15
+ end
16
+
17
+ def next
18
+ client.send(method, limit: limit, offset: offset + limit)
19
+ end
20
+
21
+ def items
22
+ @data.fetch("items").map { |item|
23
+ resource.new(item, client, parent)
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module OracleHcm
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "oracle_hcm/resource"
2
+ require "oracle_hcm/name"
3
+ require "oracle_hcm/national_identifier"
4
+ require "oracle_hcm/document_record"
5
+
6
+ module OracleHcm
7
+ # A Worker is a resources that represents an employee within the system.
8
+ class Worker < Resource
9
+ child_resource :names, resource: Name
10
+ child_resource :national_identifiers, resource: NationalIdentifier
11
+ property :person_id, key: "PersonId"
12
+ property :person_number, key: "PersonNumber"
13
+ cached_property :first_name do names.items.first.first_name; end
14
+ cached_property :last_name do names.items.first.last_name; end
15
+
16
+ def ssns
17
+ national_identifiers q: "NationalIdentifierType=SSN"
18
+ end
19
+ end
20
+ end
data/lib/oracle_hcm.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "oracle_hcm/version"
2
+ require "oracle_hcm/client"
3
+
4
+ module OracleHcm
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "oracle_hcm/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "oracle_hcm"
7
+ spec.version = OracleHcm::VERSION
8
+ spec.authors = ["Paul Holden"]
9
+ spec.email = ["paul@holdensoftware.com"]
10
+
11
+ spec.summary = %q{A library for interacting with the Oracle HCM REST API.}
12
+ spec.homepage = "https://github.com/paulholden2/oracle_hcm"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/paulholden2/oracle_hcm"
19
+ spec.metadata["changelog_uri"] = "https://github.com/paulholden2/oracle_hcm/blog/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "faraday", "~> 1.0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
data/pkg/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oracle_hcm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Holden
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - paul@holdensoftware.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/oracle_hcm.rb
87
+ - lib/oracle_hcm/attachment.rb
88
+ - lib/oracle_hcm/client.rb
89
+ - lib/oracle_hcm/document_record.rb
90
+ - lib/oracle_hcm/name.rb
91
+ - lib/oracle_hcm/national_identifier.rb
92
+ - lib/oracle_hcm/resource.rb
93
+ - lib/oracle_hcm/resource_list.rb
94
+ - lib/oracle_hcm/version.rb
95
+ - lib/oracle_hcm/worker.rb
96
+ - oracle_hcm.gemspec
97
+ - pkg/.gitignore
98
+ homepage: https://github.com/paulholden2/oracle_hcm
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ allowed_push_host: https://rubygems.org
103
+ homepage_uri: https://github.com/paulholden2/oracle_hcm
104
+ source_code_uri: https://github.com/paulholden2/oracle_hcm
105
+ changelog_uri: https://github.com/paulholden2/oracle_hcm/blog/master/CHANGELOG.md
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.0.8
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A library for interacting with the Oracle HCM REST API.
125
+ test_files: []