ucb-hcm 1.0 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c7039282f5894d83da4f79d4d61d0048bb9cefc4
4
- data.tar.gz: 7d508d08984f8953525c8cb70b1a24dc6a7f9485
2
+ SHA256:
3
+ metadata.gz: 62c9ba3f962308201cf3d2668c222e3b74615d7a5ae111335d09ab6c7334d181
4
+ data.tar.gz: a2cde1633debc69794e4d5ad4acc4755f258bb26da31ccf701623fbed0a09774
5
5
  SHA512:
6
- metadata.gz: ef2b5b292b61354435946187c5e37997eef61ed6bea7f30d4a97205c948e9d572287a833cda07d8ef2b941108e5f037f67e2cdfb0b8e9a9460a786293cf5b713
7
- data.tar.gz: a25d39b46efb3d77cddb13f081dc385152e7cd84f948e5c02e873a4a4db4488e78d273384195e9203686133f5165bcdbd1dba34c08348789f50e5451897cb482
6
+ metadata.gz: 9bef13a7e84c972a74b126b32544cf15eeb77ba79d32fcba3e4c543a1f1e8d159e42bb17f9daa1ac44aadcd84ee7a0e2017aa4efceedbf8e3043815f98f09c91
7
+ data.tar.gz: 3a9feb88955fae6f323ca4cb10a6095a19b9e8ffe38da05686f15bc17eb8f82e670e8bce70bde31b8c7042c51fa7078da399addf24d02f0ee9c9190d6ded9b90
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ .env
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ branches:
2
+ except:
3
+ - /^.*\/.*+$/
4
+ language: ruby
5
+ rvm:
6
+ - 2.5.1
7
+ install: true
8
+ script:
9
+ - bin/setup
10
+ before_deploy:
11
+ - git tag $TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER
12
+ cache:
13
+ directories:
14
+ - vendor/bundle
15
+ notifications:
16
+ slack: infinitered:4s2uT0dj614H6BUJteVhFGqo
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Ucb::Hcm
2
2
 
3
- Ucb::Hcm is a lightweight ruby wrapper around UC Berkeley's Human Capital Management API.
4
- https://developer.berkeley.edu/apidocs/employee
3
+ Ucb::Hcm is a lightweight ruby wrapper around [UC Berkeley's Human Capital Management API](https://api-central.berkeley.edu/api/14/interactive-docs).
5
4
 
6
5
  Version 1.0 of this gem supports the v2 API, documented in the link above. UCB now has v3 of the API - we'll skip version 2.0 of the gem and make version 3.0 support the v3 API.
7
6
 
@@ -9,33 +8,104 @@ Version 1.0 of this gem supports the v2 API, documented in the link above. UCB n
9
8
 
10
9
  Add this line to your application's Gemfile:
11
10
 
12
- gem 'ucb-hcm'
11
+ gem 'ucb-hcm', "~> 3"
13
12
 
14
13
  And then execute:
15
14
 
16
15
  $ bundle
17
16
 
18
- Or install it yourself as:
17
+ Or install it by yourself:
19
18
 
20
19
  $ gem install ucb-hcm
21
20
 
22
- ## Usage
21
+ ## Configuration
22
+
23
+ Configure your app with your API credentials from [UCB's API Central](https://api-central.berkeley.edu/api/14/credentials).
23
24
 
24
25
  Ucb::Hcm.configure do |hcm|
25
26
  hcm.app_id = "APP_ID"
26
27
  hcm.app_key = "APP_KEY"
27
- hcm.endpoint = "https://endpoint/"
28
+ hcm.endpoint = "https://apis.berkeley.edu/dev/hr/v3"
28
29
  end
29
30
 
31
+ ## Usage
32
+
33
+ :rotating_light: Note: Version 3.x of this gem only supports v3 of the API. :rotating_light:
30
34
 
35
+ ### Fetch Employees
36
+
37
+ ```ruby
31
38
  client = Ucb::Hcm::Client.new
32
- client.get("/employees/12345")
33
- client.employees.find(12345) # Coming soon!
39
+ response = client.get("/employees", { limit: 20, previous: 0, next: 20 })
40
+
41
+ >> response.data
42
+ => [
43
+ {
44
+ "identifiers"=> [
45
+ {"type"=>"hr-employee-id", "id"=>"10141478"}
46
+ ]
47
+ },
48
+ {
49
+ "identifiers"=>[
50
+ {"type"=>"hr-employee-id", "id"=>"10272831"},
51
+ {"type"=>"legacy-hr-employee-id", "id"=>"12521372"}
52
+ ]
53
+ }
54
+ ...
55
+ ]
56
+ ```
57
+
58
+ ### Fetch specific Employee
59
+
60
+ ```ruby
61
+ client = Ucb::Hcm::Client.new
62
+ response = client.get("/employees/10272831", {"id-type" => "hr-employee-id"})
63
+
64
+ >> response.data
65
+ => {
66
+ "identifiers" => [
67
+ {"type" => "campus-uid", "id" => "20108691"}, {"type" => "campus-solutions-id"}, {"type" => "student-id"}, {"type" => "hr-employee-id", "id" => "10272831"}, {"type" => "legacy-hr-employee-id"}, {"type" => "calnet-id"}
68
+ ],
69
+ "names" => [{
70
+ "type "= >{"code" => "PRI", "description" => "Primary"},
71
+ "familyName" => "Kumar",
72
+ "givenName" => "Siri",
73
+ "lastChangedBy" => {"id" => "10000499"},
74
+ "fromDate" => "2018-10-01"
75
+ }],
76
+ ...
77
+ }
78
+
79
+ ```
80
+
81
+ ### Fetch an Employee's jobs
82
+
83
+ ```ruby
84
+ client = Ucb::Hcm::Client.new
85
+ response = client.get("/employees/10272831/jobs", {"id-type" => "hr-employee-id"})
86
+
87
+ # The jobs api sometimes returns an array with the first element
88
+ # containing the real job data and the second an empty hash :(.
89
+ # For example: [{<real_data>}, {}]
90
+ >> response.data.first["jobs"]
91
+ => [
92
+ {
93
+ "number" => 0,
94
+ "sequence" => 0,
95
+ "type" => {
96
+ "code" => "2",
97
+ "description" => "Staff: Career"
98
+ },
99
+ ...
100
+ }
101
+ ]
102
+ ```
34
103
 
35
104
  ## Contributing
36
105
 
37
106
  1. Fork it ( https://github.com/[my-github-username]/ucb-hcm/fork )
38
- 2. Create your feature branch (`git checkout -b my-new-feature`)
39
- 3. Commit your changes (`git commit -am 'Add some feature'`)
40
- 4. Push to the branch (`git push origin my-new-feature`)
41
- 5. Create a new Pull Request
107
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
108
+ 1. Ask for `.env` file from previous developer and run `source .env`
109
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 1. Push to the branch (`git push origin my-new-feature`)
111
+ 1. Create a new Pull Request
data/bin/setup ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ def banner(msg, suppress_newline=false)
13
+ puts "#{suppress_newline ? "" : "\n"}== #{msg} =="
14
+ end
15
+
16
+ def ci?
17
+ ENV["TRAVIS"] == "true"
18
+ end
19
+
20
+ chdir APP_ROOT do
21
+ banner "Checking Ruby version"
22
+ required_version = `cat .ruby-version`.gsub(/[a-zA-Z]|-/, "").strip
23
+ if RUBY_VERSION != required_version
24
+ puts "Wrong Ruby version - please use #{required_version} (found: #{RUBY_VERSION})"
25
+ exit -1
26
+ end
27
+
28
+ banner "Installing dependencies"
29
+ system! 'gem install bundler --conservative'
30
+ system('bundle check') || system!('bundle install')
31
+
32
+ banner "Running test suite to confirm setup"
33
+ system! "bundle exec rspec"
34
+
35
+ unless ci?
36
+ puts " =========== SETUP COMPLETE ==============="
37
+ end
38
+ end
data/lib/ucb/hcm/api.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'ucb/hcm/configuration'
2
2
  require "ucb/hcm/request"
3
3
  require "ucb/hcm/response"
4
- require "ucb/hcm/resource"
5
4
 
6
5
  module Ucb
7
6
  module Hcm
@@ -1,7 +1,4 @@
1
1
  require "ucb/hcm/api"
2
- require "ucb/hcm/api/employee"
3
- require "ucb/hcm/api/job"
4
- require "ucb/hcm/api/department"
5
2
 
6
3
  module Ucb
7
4
  module Hcm
@@ -5,7 +5,7 @@ module Ucb
5
5
  VALID_OPTIONS_KEYS = [:app_id, :app_key, :format].freeze
6
6
  VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
7
7
 
8
- DEFAULT_ENDPOINT = 'https://apis.berkeley.edu/uat/hcm/v2'
8
+ DEFAULT_ENDPOINT = 'https://apis.berkeley.edu/test/hr/v3'
9
9
  DEFAULT_METHOD = :get
10
10
  DEFAULT_USER_AGENT = "Ucb::Hcm API Ruby Gem #{Ucb::Hcm::VERSION}".freeze
11
11
 
@@ -21,8 +21,8 @@ module Ucb
21
21
  respond client.post(resource, params)
22
22
  end
23
23
 
24
- def respond( response )
25
- Response.new response
24
+ def respond(response)
25
+ Response.new(response)
26
26
  end
27
27
 
28
28
  private
@@ -50,7 +50,6 @@ module Ucb
50
50
  def base_endpoint
51
51
  endpoint
52
52
  end
53
-
54
53
  end
55
54
  end
56
55
  end
@@ -20,7 +20,11 @@ module Ucb
20
20
  end
21
21
 
22
22
  def data
23
- defined?(@data_fetcher) ? instance_eval(&@data_fetcher) : response
23
+ if raw_response["response"]&.count == 1
24
+ raw_response["response"]&.first
25
+ else
26
+ raw_response["response"]
27
+ end
24
28
  end
25
29
 
26
30
  def data_fetcher=(block)
@@ -1,5 +1,5 @@
1
1
  module Ucb
2
2
  module Hcm
3
- VERSION = "1.0"
3
+ VERSION = "3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ # spec/spec_helper.rb
2
+ require 'ucb/hcm'
3
+ require 'support/test_credentials'
@@ -0,0 +1,4 @@
1
+ module TestCredentials
2
+ TEST_APP_ID = ENV['UCB_HCM_TEST_APP_ID']
3
+ TEST_APP_KEY = ENV['UCB_HCM_TEST_APP_KEY']
4
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ RSpec.describe 'api' do
5
+ before do
6
+ @client = Ucb::Hcm::Client.new(app_id: TestCredentials::TEST_APP_ID, app_key: TestCredentials::TEST_APP_KEY)
7
+ end
8
+
9
+ describe "#get" do
10
+ describe "GET /employees/:id" do
11
+ it "returns employee data w/ valid id & legacy-hr-employee-type" do
12
+ response = @client.get("/employees/10135532", {"id-type" => "hr-employee-id"})
13
+
14
+ expect(response.success?).to eq true
15
+ expect(response.data["identifiers"].first.has_key?("type")).to eq true
16
+
17
+ names = response.data["names"]
18
+ expect(names.empty? || names.first.has_key?("familyName")).to eq true
19
+
20
+ addresses = response.data["addresses"]
21
+ expect(addresses.empty? || addresses.first.has_key?("address1")).to eq true
22
+
23
+ emails = response.data["emails"]
24
+ expect(emails.empty? || emails.first.has_key?("emailAddress")).to eq true
25
+
26
+ phones = response.data["phones"]
27
+ expect(phones.empty? || phones.first.has_key?("number")).to eq true
28
+ end
29
+
30
+ # this used to return 404 - now it just seems to default to hr-employee-id
31
+ it "succeeds with invalid id-type" do
32
+ response = @client.get("/employees/10135532", {"id-type" => "invalid-type"})
33
+
34
+ expect(response.success?).to be true
35
+ end
36
+
37
+ # this used to return 500 - now it returns 200 with an empty response
38
+ it "returns empty response if id is invalid" do
39
+ response = @client.get("/employees/invalidId", {"id-type" => "legacy-hr-employee-id"})
40
+
41
+ expect(response.success?).to be true
42
+ expect(response.data).to be_nil
43
+ end
44
+ end
45
+
46
+ describe "fetch employee jobs" do
47
+ it "returns all an employees jobs" do
48
+ response = @client.get("/employees/010789601/jobs", {"id-type" => "legacy-hr-employee-id"})
49
+
50
+ expect(response.success?).to eq true
51
+
52
+ job = response.data["jobs"].first
53
+ expect(job.has_key?("compensation")).to eq true
54
+ end
55
+ end
56
+
57
+ describe "GET /employees" do
58
+ it "supports pagination" do
59
+ params = {
60
+ limit: 5,
61
+ previous: 0,
62
+ next: 5
63
+ }
64
+
65
+ response = @client.get("/employees", params)
66
+
67
+ expect(response.data.count).to eq 5
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ RSpec.describe 'configuration' do
5
+ after do
6
+ Ucb::Hcm.reset
7
+ end
8
+
9
+ describe '.configure' do
10
+ Ucb::Hcm::Configuration::VALID_CONFIG_KEYS.each do |key|
11
+ it "should set the #{key}" do
12
+ Ucb::Hcm.configure do |config|
13
+ config.send("#{key}=", key)
14
+ expect(Ucb::Hcm.send(key)).to eq key
15
+ end
16
+ end
17
+ end
18
+
19
+ Ucb::Hcm::Configuration::VALID_CONFIG_KEYS.each do |key|
20
+ describe ".#{key}" do
21
+ it 'should return the default value' do
22
+ if [:app_id, :app_key].include?(key)
23
+ expect(Ucb::Hcm.send(key)).to be_nil
24
+ else
25
+ expect(Ucb::Hcm.send(key)).to eq Ucb::Hcm::Configuration.const_get("DEFAULT_#{key.upcase}")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe Ucb::Hcm do
5
+ it 'should have a version' do
6
+ expect(Ucb::Hcm::VERSION).to be_present
7
+ end
8
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
  require 'pry'
3
3
 
4
4
  describe 'request' do
@@ -9,27 +9,27 @@ describe 'request' do
9
9
 
10
10
  describe 'client' do
11
11
  it 'has a HTTParty client interface' do
12
- @client.client.must_be_same_as HTTParty
12
+ expect(@client.client).to eq HTTParty
13
13
  end
14
14
  end
15
15
 
16
16
  describe 'base endpoint' do
17
17
  it 'has a base endpoint the same as the configuration endpoint' do
18
- @client.send(:base_endpoint).must_be_same_as Ucb::Hcm::Configuration::DEFAULT_ENDPOINT
18
+ expect(@client.send(:base_endpoint)).to eq Ucb::Hcm::Configuration::DEFAULT_ENDPOINT
19
19
  end
20
20
 
21
21
  it 'can change the base end point' do
22
22
  new_endpoint = "hello"
23
23
  client = Ucb::Hcm::Client.new(app_id: TestCredentials::TEST_APP_ID, app_key: TestCredentials::TEST_APP_KEY, endpoint: new_endpoint)
24
- client.send(:base_endpoint).must_be_same_as new_endpoint
24
+ expect(client.send(:base_endpoint)).to eq new_endpoint
25
25
  end
26
26
  end
27
27
 
28
28
  describe 'get' do
29
29
  it 'performs a get request' do
30
- response = @client.get("/employees/010789601")
31
- response.must_be_instance_of Ucb::Hcm::Response
32
- response.success?.must_equal true
30
+ response = @client.get("/employees/010789601", {"id-type" => "legacy-hr-employee-id"})
31
+ expect(response).to be_an_instance_of Ucb::Hcm::Response
32
+ expect(response.success?).to eq true
33
33
  end
34
34
  end
35
35
  end
data/ucb-hcm.gemspec CHANGED
@@ -6,11 +6,11 @@ require 'ucb/hcm/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ucb-hcm"
8
8
  spec.version = Ucb::Hcm::VERSION
9
- spec.authors = ["Peter Philips"]
10
- spec.email = ["peter@planet.io"]
9
+ spec.authors = ["Peter Philips", "Darin Wilson", "Zachary Berkompas"]
10
+ spec.email = ["hello@infinite.red"]
11
11
  spec.summary = %q{Ucb HCM - Human Capital Management API gem}
12
12
  spec.description = %q{Lightweight wrapper for the UCB HCM Api - https://developer.berkeley.edu/apidocs/employee}
13
- spec.homepage = "http://planet.io"
13
+ spec.homepage = "https://infinite.red"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency 'pry'
26
26
  spec.add_development_dependency 'byebug'
27
+ spec.add_development_dependency 'rspec-core'
28
+ spec.add_development_dependency 'rspec-expectations'
27
29
  end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucb-hcm
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '3.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Philips
8
+ - Darin Wilson
9
+ - Zachary Berkompas
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2018-07-24 00:00:00.000000000 Z
13
+ date: 2019-02-07 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: activesupport
@@ -94,39 +96,64 @@ dependencies:
94
96
  - - ">="
95
97
  - !ruby/object:Gem::Version
96
98
  version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rspec-core
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec-expectations
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
97
127
  description: Lightweight wrapper for the UCB HCM Api - https://developer.berkeley.edu/apidocs/employee
98
128
  email:
99
- - peter@planet.io
100
- executables: []
129
+ - hello@infinite.red
130
+ executables:
131
+ - setup
101
132
  extensions: []
102
133
  extra_rdoc_files: []
103
134
  files:
104
135
  - ".gitignore"
136
+ - ".ruby-version"
137
+ - ".travis.yml"
105
138
  - Gemfile
106
139
  - LICENSE.txt
107
140
  - README.md
108
- - Rakefile
141
+ - bin/setup
109
142
  - lib/ucb/hcm.rb
110
143
  - lib/ucb/hcm/api.rb
111
- - lib/ucb/hcm/api/department.rb
112
- - lib/ucb/hcm/api/employee.rb
113
- - lib/ucb/hcm/api/job.rb
114
144
  - lib/ucb/hcm/client.rb
115
145
  - lib/ucb/hcm/configuration.rb
116
146
  - lib/ucb/hcm/request.rb
117
- - lib/ucb/hcm/resource.rb
118
147
  - lib/ucb/hcm/response.rb
119
148
  - lib/ucb/hcm/version.rb
120
- - test/helper.rb
121
- - test/support/shared_examples.rb
122
- - test/support/test_credentials.rb
123
- - test/ucb/hcm/api_test.rb
124
- - test/ucb/hcm/client_test.rb
125
- - test/ucb/hcm/configuration_test.rb
126
- - test/ucb/hcm/hcm_test.rb
127
- - test/ucb/hcm/request_test.rb
149
+ - spec/spec_helper.rb
150
+ - spec/support/test_credentials.rb
151
+ - spec/ucb/hcm/api_spec.rb
152
+ - spec/ucb/hcm/configuration_spec.rb
153
+ - spec/ucb/hcm/hcm_spec.rb
154
+ - spec/ucb/hcm/request_spec.rb
128
155
  - ucb-hcm.gemspec
129
- homepage: http://planet.io
156
+ homepage: https://infinite.red
130
157
  licenses:
131
158
  - MIT
132
159
  metadata: {}
@@ -146,16 +173,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
173
  version: '0'
147
174
  requirements: []
148
175
  rubyforge_project:
149
- rubygems_version: 2.6.13
176
+ rubygems_version: 2.7.7
150
177
  signing_key:
151
178
  specification_version: 4
152
179
  summary: Ucb HCM - Human Capital Management API gem
153
180
  test_files:
154
- - test/helper.rb
155
- - test/support/shared_examples.rb
156
- - test/support/test_credentials.rb
157
- - test/ucb/hcm/api_test.rb
158
- - test/ucb/hcm/client_test.rb
159
- - test/ucb/hcm/configuration_test.rb
160
- - test/ucb/hcm/hcm_test.rb
161
- - test/ucb/hcm/request_test.rb
181
+ - spec/spec_helper.rb
182
+ - spec/support/test_credentials.rb
183
+ - spec/ucb/hcm/api_spec.rb
184
+ - spec/ucb/hcm/configuration_spec.rb
185
+ - spec/ucb/hcm/hcm_spec.rb
186
+ - spec/ucb/hcm/request_spec.rb
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- require 'rake/testtask'
4
- Rake::TestTask.new do |test|
5
- test.libs << 'lib' << 'test'
6
- test.ruby_opts << "-rubygems"
7
- test.pattern = 'test/**/*_test.rb'
8
- test.verbose = true
9
- end
@@ -1,12 +0,0 @@
1
- module Ucb
2
- module Hcm
3
- class Department < Resource
4
- scope :departments
5
-
6
- data do
7
- response["DepartmentResponse"]["DepartmentList"]["Department"]
8
- end
9
-
10
- end
11
- end
12
- end
@@ -1,14 +0,0 @@
1
- module Ucb
2
- module Hcm
3
- class Employee < Resource
4
- scope :employees
5
-
6
- api :names, :addresses, :jobs, :emails, :phones, :departments, :identifiers
7
-
8
- data do
9
- response["PersonResponse"]["PersonList"]["Person"]
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Ucb
2
- module Hcm
3
- class Job < Resource
4
- scope :jobs
5
-
6
- api steps: :number
7
-
8
- data do
9
- response["JobResponse"]["JobList"]["Job"]
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,93 +0,0 @@
1
- module Ucb
2
- module Hcm
3
- class Resource
4
- attr_reader :client, :id
5
-
6
- def initialize(client, id)
7
- @client = client
8
- @id = id
9
- end
10
-
11
- def get(request_path, params={})
12
- respond client.get(resource_path(request_path), params)
13
- end
14
-
15
- def post(request_path, params={})
16
- respond client.post(resource_path(request_path), params)
17
- end
18
-
19
- def find
20
- get("/")
21
- end
22
-
23
- # this can be overridden by subclasses
24
- # to key in on exactly what they want minus the fluff
25
- def respond(response)
26
- response.data_fetcher = self.class.data
27
- response
28
- end
29
-
30
- class << self
31
- attr_reader :api_methods
32
-
33
- def scope(name=nil)
34
- name.blank? ? @scope : set_scope(name)
35
- end
36
-
37
- # called in the context of a Response object
38
- def data(&block)
39
- block_given? ? set_data(block) : @data
40
- end
41
-
42
- def api(*attributes)
43
- @api_methods = attributes
44
- generate_api("/", @api_methods)
45
- end
46
-
47
- private
48
- def set_scope(name)
49
- @scope = name.to_s
50
-
51
- Ucb::Hcm::Api.class_eval do
52
- define_method name do |id|
53
- "Ucb::Hcm::#{name.to_s.classify}".constantize.new(self, id)
54
- end
55
- end
56
- end
57
-
58
- def set_data(block)
59
- @data = block
60
- end
61
-
62
- def generate_api(scope, methods)
63
- Array(methods).each do |method|
64
- if method.kind_of?(Hash)
65
- method.each do |parent_method, child_method|
66
- generate_api(scope, parent_method)
67
- generate_api("#{scope}/#{parent_method}/:id", child_method)
68
- end
69
- elsif method.kind_of?(Symbol)
70
- define_method(method) do |*args|
71
- get("#{scope}/#{method}")
72
- end
73
- else
74
- raise "Unsupported type for api method: #{method.class}. Must be Symbol or Hash"
75
- end
76
- end
77
- end
78
- end
79
-
80
- private
81
- def resource_path(request_path)
82
- resource_scope = "/#{self.class.scope}/#{id}"
83
- if request_path == "/"
84
- resource_scope
85
- else
86
- resource_scope + request_path
87
- end
88
- end
89
-
90
- end
91
- end
92
- end
93
-
data/test/helper.rb DELETED
@@ -1,5 +0,0 @@
1
- # test/helper.rb
2
- require 'ucb/hcm'
3
- require 'minitest/autorun'
4
- require 'support/shared_examples'
5
- require 'support/test_credentials'
@@ -1,17 +0,0 @@
1
- MiniTest::Spec.class_eval do
2
- def self.shared_examples
3
- @shared_examples ||= {}
4
- end
5
- end
6
-
7
- module MiniTest::Spec::SharedExamples
8
- def shared_examples_for(desc, &block)
9
- MiniTest::Spec.shared_examples[desc] = block
10
- end
11
-
12
- def it_behaves_like(desc)
13
- self.instance_eval(&MiniTest::Spec.shared_examples[desc])
14
- end
15
- end
16
-
17
- Object.class_eval { include(MiniTest::Spec::SharedExamples) }
@@ -1,4 +0,0 @@
1
- module TestCredentials
2
- TEST_APP_ID = "788834e7"
3
- TEST_APP_KEY = "fa72e534a8284d57b2007947aea80a21"
4
- end
@@ -1,144 +0,0 @@
1
- require 'helper'
2
- require 'pry'
3
-
4
- describe 'api' do
5
-
6
- before do
7
- @client = Ucb::Hcm::Client.new(app_id: TestCredentials::TEST_APP_ID, app_key: TestCredentials::TEST_APP_KEY)
8
- end
9
-
10
- shared_examples_for "successful response" do
11
- it "responds successfully" do
12
- response.must_be_instance_of Ucb::Hcm::Response
13
- response.success?.must_equal true
14
- end
15
- end
16
-
17
- describe 'employee' do
18
- describe "#find" do
19
- let(:response) { @client.employees("010789601").find }
20
-
21
- it_behaves_like "successful response"
22
-
23
- it 'has home dept' do
24
- response.data.first.has_key?("HomeDept").must_equal true
25
- end
26
- end
27
-
28
- describe "#names" do
29
- let(:response) { @client.employees("010789601").names }
30
-
31
- it_behaves_like "successful response"
32
-
33
- it 'has last name' do
34
- data = response.data.first
35
- data.has_key?("Names").must_equal true
36
- data["Names"].has_key?("Name").must_equal true
37
- data["Names"]["Name"].first.has_key?("familyName").must_equal true
38
- end
39
- end
40
-
41
- describe "#addresses" do
42
- let(:response) { @client.employees("010789601").addresses }
43
-
44
- it_behaves_like "successful response"
45
-
46
- it 'has address' do
47
- data = response.data.first
48
- data.has_key?("Addresses").must_equal true
49
- data["Addresses"].has_key?("Address").must_equal true
50
- end
51
- end
52
-
53
- describe "#jobs" do
54
- let(:response) { @client.employees("010789601").jobs }
55
-
56
- it_behaves_like "successful response"
57
-
58
- it 'has jobs' do
59
- data = response.data.first
60
- data.has_key?("Job").must_equal true
61
- data["Job"].has_key?("Compensation").must_equal true
62
- data["Job"]["Compensation"].has_key?("Pay").must_equal true
63
- data["Job"]["Compensation"]["Pay"].has_key?("EmplRecord").must_equal true
64
- end
65
- end
66
-
67
- describe "#emails" do
68
- let(:response) { @client.employees("010789601").emails }
69
-
70
- it_behaves_like "successful response"
71
-
72
- it 'has emails' do
73
- data = response.data.first
74
- data.has_key?("Emails").must_equal true
75
- data["Emails"].has_key?("Email").must_equal true
76
- data["Emails"]["Email"].first.has_key?("emailAddress").must_equal true
77
- end
78
- end
79
-
80
- describe "#phones" do
81
- let(:response) { @client.employees("010789601").phones }
82
-
83
- it_behaves_like "successful response"
84
-
85
- it 'has phones' do
86
- data = response.data.first
87
- data.has_key?("Phones").must_equal true
88
- data["Phones"].has_key?("Phone").must_equal true
89
- data["Phones"]["Phone"].first.has_key?("number").must_equal true
90
- end
91
- end
92
-
93
- describe "#departments" do
94
- let(:response) { @client.employees("010789601").departments }
95
-
96
- it_behaves_like "successful response"
97
-
98
- it 'has department' do
99
- data = response.data.first
100
- data.has_key?("Departments").must_equal true
101
- data["Departments"].has_key?("Department").must_equal true
102
- data["Departments"]["Department"].has_key?("DeptID").must_equal true
103
- end
104
- end
105
-
106
- describe "#identifiers" do
107
- let(:response) { @client.employees("010789601").identifiers }
108
-
109
- it_behaves_like "successful response"
110
-
111
- it 'has identifiers' do
112
- data = response.data.first
113
- data.has_key?("Identifiers").must_equal true
114
- data["Identifiers"].has_key?("Identifier").must_equal true
115
- data["Identifiers"]["Identifier"].first.has_key?("type").must_equal true
116
- end
117
- end
118
-
119
- end
120
-
121
- describe 'job' do
122
- describe "#find" do
123
- let(:response) { @client.jobs("9634C").find }
124
-
125
- it_behaves_like "successful response"
126
-
127
- it 'finds employee name by id' do
128
- response.data["JobCodeDescr"].must_equal "Museum Preparator"
129
- end
130
-
131
- end
132
-
133
- describe "#steps" do
134
- let(:response) { @client.jobs("9634C").steps }
135
-
136
- it_behaves_like "successful response"
137
-
138
- it 'has steps' do
139
- response.data.has_key?("Grade").must_equal true
140
- response.data["Grade"].has_key?("Step").must_equal true
141
- end
142
- end
143
- end
144
- end
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- describe 'configuration' do
4
-
5
- after do
6
- Ucb::Hcm.reset
7
- end
8
-
9
- describe '.configure' do
10
- Ucb::Hcm::Configuration::VALID_CONFIG_KEYS.each do |key|
11
- it "should set the #{key}" do
12
- Ucb::Hcm.configure do |config|
13
- config.send("#{key}=", key)
14
- Ucb::Hcm.send(key).must_equal key
15
- end
16
- end
17
- end
18
- end
19
-
20
- Ucb::Hcm::Configuration::VALID_CONFIG_KEYS.each do |key|
21
- describe ".#{key}" do
22
- it 'should return the default value' do
23
- if [:app_id, :app_key].include?(key)
24
- # MiniTest 6 will require must_be_nil when comparing nil values
25
- Ucb::Hcm.send(key).must_be_nil
26
- else
27
- Ucb::Hcm.send(key).must_equal Ucb::Hcm::Configuration.const_get("DEFAULT_#{key.upcase}")
28
- end
29
- end
30
- end
31
- end
32
-
33
- end
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- describe 'configuration' do
4
-
5
- after do
6
- Ucb::Hcm.reset
7
- end
8
-
9
- Ucb::Hcm::Configuration::VALID_CONFIG_KEYS.each do |key|
10
- describe ".#{key}" do
11
- it 'should return the default value' do
12
- if [:app_id, :app_key].include?(key)
13
- # MiniTest 6 will require must_be_nil when comparing nil values
14
- Ucb::Hcm.send(key).must_be_nil
15
- else
16
- Ucb::Hcm.send(key).must_equal Ucb::Hcm::Configuration.const_get("DEFAULT_#{key.upcase}")
17
- end
18
- end
19
- end
20
- end
21
-
22
- describe '.configure' do
23
- Ucb::Hcm::Configuration::VALID_CONFIG_KEYS.each do |key|
24
- it "should set the #{key}" do
25
- Ucb::Hcm.configure do |config|
26
- config.send("#{key}=", key)
27
- Ucb::Hcm.send(key).must_equal key
28
- end
29
- end
30
- end
31
- end
32
-
33
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- describe Ucb::Hcm do
4
- it 'should have a version' do
5
- Ucb::Hcm::VERSION.wont_be_nil
6
- end
7
- end