peoplehr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d043bf00a8109b47e0b671655cc900e9aad877c
4
+ data.tar.gz: 67300a4f44692dfaf471b694097ad7af62695459
5
+ SHA512:
6
+ metadata.gz: 009ff7796532e3f85df70fc7cfefa938f0c3b6ac61be5c9bd079c504846188e4fb13216162a9192f24831a7bfd5c265173f2922657c1b7220c15a4ddaccd0a7a
7
+ data.tar.gz: 93ade2de5056d07615f7b443881704c105bf4b8c6813534197107647f3dc6b45f63000519dbc3f35f87145b2df8770ec3524d9fccb53a73772e974c1ef30f424
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers 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. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peoplehr.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Rob Miller
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.
@@ -0,0 +1,68 @@
1
+ # peoplehr
2
+
3
+ [PeopleHR](http://www.peoplehr.com/) is an online system for managing
4
+ your organisation’s HR issues.
5
+
6
+ It offers an API for manipulating that information — either to pull
7
+ information out of it, or to modify what’s there. This can be useful for
8
+ things like creating telephone directories, pulling employees’ birthday
9
+ dates into a calendar, and lots of other things besides.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'peoplehr'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install peoplehr
26
+
27
+ ## Usage
28
+
29
+ At the moment, the library can be used only to fetch employee data.
30
+
31
+ The `Employees` class functions as a repository, with finder methods to
32
+ restrict the data returned. Use `Employees.all` to get data for all
33
+ employees:
34
+
35
+ api = API.new(api_key: "abc123abc123")
36
+ employees = Employees.new(api)
37
+
38
+ employees.all
39
+
40
+ This returns an array of `Employee` objects, each of which contains the
41
+ information stored in PeopleHR for that particular employee.
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies.
46
+ Then, run `rake spec` to run the tests. You can also run `bin/console`
47
+ for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake
50
+ install`. To release a new version, update the version number in
51
+ `version.rb`, and then run `bundle exec rake release`, which will create
52
+ a git tag for the version, push git commits and tags, and push the
53
+ `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at
58
+ https://github.com/[USERNAME]/peoplehr. This project is intended to be
59
+ a safe, welcoming space for collaboration, and contributors are expected
60
+ to adhere to the [Contributor Covenant](contributor-covenant.org) code
61
+ of conduct.
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT
67
+ License](http://opensource.org/licenses/MIT).
68
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "peoplehr"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "peoplehr/version"
2
+
3
+ require "addressable/uri"
4
+ require "faraday"
5
+ require "transproc"
6
+ require "virtus"
7
+
8
+ require "peoplehr/api"
9
+ require "peoplehr/employee"
10
+ require "peoplehr/employees"
@@ -0,0 +1,49 @@
1
+ require "json"
2
+
3
+ module PeopleHR
4
+ class API
5
+ API_ROOT = Addressable::URI.parse("https://api.peoplehr.net/")
6
+
7
+ class APIError < StandardError; end
8
+ class BadResponse < APIError; end
9
+
10
+ def initialize(api_key:, connection: nil)
11
+ @api_key = api_key
12
+ @connection = connection ||
13
+ Faraday.new(url: API_ROOT) do |faraday|
14
+ faraday.request :url_encoded
15
+ faraday.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+
19
+ def request(action, params = {})
20
+ request = {
21
+ "APIKey" => api_key,
22
+ "Action" => action,
23
+ }
24
+
25
+ payload = params.merge(request)
26
+ payload = JSON.generate(payload)
27
+
28
+ response = connection.post do |req|
29
+ req.url "/"
30
+ req.headers["Content-Type"] = "application/json"
31
+ req.body = payload
32
+ end
33
+
34
+ response = JSON.parse(response.body)
35
+
36
+ if !response || response["isError"]
37
+ fail APIError
38
+ end
39
+
40
+ response
41
+ rescue JSON::ParserError
42
+ fail BadResponse
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :connection, :api_key
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ module PeopleHR
2
+ class Employee
3
+ include Virtus.value_object
4
+
5
+ values do
6
+ attribute :id, String
7
+ attribute :title, String
8
+ attribute :first_name, String
9
+ attribute :last_name, String
10
+ attribute :email, String
11
+ attribute :start_date, Date
12
+ attribute :date_of_birth, Date
13
+ attribute :job_role, String
14
+ attribute :company, String
15
+ attribute :location, String
16
+ attribute :department, String
17
+ end
18
+
19
+ def full_name
20
+ "#{first_name} #{last_name}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,86 @@
1
+ module PeopleHR
2
+ class Employees
3
+ def initialize(api:)
4
+ @api = api
5
+ end
6
+
7
+ def all
8
+ transformation =
9
+ t(:extract_result) >>
10
+ t(
11
+ :map_array,
12
+ t(
13
+ :map_values,
14
+ t(:extract_display_value)
15
+ )
16
+ ) >>
17
+ t(
18
+ :map_array,
19
+ t(
20
+ :accept_keys,
21
+ [
22
+ "EmployeeId",
23
+ "FirstName",
24
+ "LastName",
25
+ "Title",
26
+ "EmailId",
27
+ "StartDate",
28
+ "DateOfBirth",
29
+ "JobRole",
30
+ "Company",
31
+ "Location",
32
+ "Department",
33
+ ]
34
+ ) >>
35
+ t(
36
+ :map_keys,
37
+ -> k {
38
+ k.gsub(/::/, '/')
39
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
40
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
41
+ .tr("-", "_")
42
+ .downcase
43
+ }
44
+ ) >>
45
+ t(:symbolize_keys) >>
46
+ t(:rename_keys, { employee_id: :id }) >>
47
+ t(:convert_to_employee)
48
+ )
49
+
50
+ transformation.call(api_data)
51
+ end
52
+
53
+ private
54
+
55
+ attr_reader :api
56
+
57
+ def api_data
58
+ api.request("GetAllEmployeeDetail", "IncludeLeavers" => false)
59
+ end
60
+
61
+ def t(*args)
62
+ Transformations[*args]
63
+ end
64
+
65
+ module Transformations
66
+ extend Transproc::Registry
67
+
68
+ import Transproc::HashTransformations
69
+ import Transproc::ArrayTransformations
70
+
71
+ def self.extract_result(hash)
72
+ hash["Result"]
73
+ end
74
+
75
+ def self.extract_display_value(hash)
76
+ if hash.is_a?(Hash)
77
+ hash["DisplayValue"]
78
+ end
79
+ end
80
+
81
+ def self.convert_to_employee(hash)
82
+ Employee.new(hash)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module PeopleHR
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'peoplehr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "peoplehr"
8
+ spec.version = PeopleHR::VERSION
9
+ spec.authors = ["Rob Miller"]
10
+ spec.email = ["rob@bigfish.co.uk"]
11
+
12
+ spec.summary = %q{A library for interacting with the PeopleHR API}
13
+ spec.description = %q{A library for interacting with the PeopleHR API to export and manipulate employee and other information.}
14
+ spec.homepage = "https://github.com/robmiller/peoplehr"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "addressable", "~> 2.3"
23
+ spec.add_runtime_dependency "faraday", "~> 0.9.1"
24
+ spec.add_runtime_dependency "transproc", "~> 0.3.0"
25
+ spec.add_runtime_dependency "virtus", "~> 1.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peoplehr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Miller
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: transproc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A library for interacting with the PeopleHR API to export and manipulate
112
+ employee and other information.
113
+ email:
114
+ - rob@bigfish.co.uk
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/peoplehr.rb
130
+ - lib/peoplehr/api.rb
131
+ - lib/peoplehr/employee.rb
132
+ - lib/peoplehr/employees.rb
133
+ - lib/peoplehr/version.rb
134
+ - peoplehr.gemspec
135
+ homepage: https://github.com/robmiller/peoplehr
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.4.8
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: A library for interacting with the PeopleHR API
159
+ test_files: []